refactor: reorganize project structure to src/ with slnx solution
- Move all source code to src/ directory - Add Fengling.AuthService.slnx solution file - Update Dockerfile to reference src/ paths - Update CI/CD workflow for new structure - Optimize .dockerignore for cleaner builds
This commit is contained in:
parent
f72e415c0f
commit
9a7948e634
@ -1,5 +1,12 @@
|
||||
bin/
|
||||
obj/
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
*.md
|
||||
**/.git
|
||||
**/.idea
|
||||
**/bin
|
||||
**/obj
|
||||
**/.vs
|
||||
**/*.user
|
||||
**/*.suo
|
||||
**/node_modules
|
||||
**/.DS_Store
|
||||
README.md
|
||||
.gitignore
|
||||
.dockerignore
|
||||
142
.gitea/workflows/ci.yaml
Normal file
142
.gitea/workflows/ci.yaml
Normal file
@ -0,0 +1,142 @@
|
||||
name: Build and Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
|
||||
env:
|
||||
REGISTRY: gitea.shtao1.cn
|
||||
IMAGE_NAME: ${{ gitea.repository }}
|
||||
DOTNET_VERSION: '10.0'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: ${{ env.DOTNET_VERSION }}
|
||||
|
||||
- name: Configure NuGet
|
||||
run: |
|
||||
cat > NuGet.Config << 'NUGET'
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<clear />
|
||||
<add key="gitea" value="https://gitea.shtao1.cn/api/packages/fengling/nuget/index.json" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
<packageSourceCredentials>
|
||||
<gitea>
|
||||
<add key="Username" value="${{ secrets.NUGET_USERNAME }}" />
|
||||
<add key="ClearTextPassword" value="${{ secrets.NUGET_TOKEN }}" />
|
||||
</gitea>
|
||||
</packageSourceCredentials>
|
||||
</configuration>
|
||||
NUGET
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore src/Fengling.AuthService.csproj
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build
|
||||
run: dotnet build src/Fengling.AuthService.csproj --configuration Release --no-restore
|
||||
- name: Publish
|
||||
run: dotnet publish src/Fengling.AuthService.csproj --configuration Release --no-build --output ./publish
|
||||
run: dotnet publish --configuration Release --no-build --output ./publish
|
||||
|
||||
docker:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
if: gitea.event_name == 'push'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Configure NuGet for Docker
|
||||
run: |
|
||||
cat > NuGet.Config << 'NUGET'
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<clear />
|
||||
<add key="gitea" value="https://gitea.shtao1.cn/api/packages/fengling/nuget/index.json" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
<packageSourceCredentials>
|
||||
<gitea>
|
||||
<add key="Username" value="${{ secrets.NUGET_USERNAME }}" />
|
||||
<add key="ClearTextPassword" value="${{ secrets.NUGET_TOKEN }}" />
|
||||
</gitea>
|
||||
</packageSourceCredentials>
|
||||
</configuration>
|
||||
NUGET
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Gitea Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
- name: Extract metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=sha,prefix=
|
||||
type=raw,value=latest,enable={{is_default_branch}}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
deploy:
|
||||
needs: docker
|
||||
runs-on: ubuntu-latest
|
||||
if: gitea.event_name == 'push' && (gitea.ref == 'refs/heads/main' || gitea.ref == 'refs/heads/master')
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up kubectl
|
||||
uses: azure/setup-kubectl@v3
|
||||
|
||||
- name: Configure kubectl
|
||||
run: |
|
||||
mkdir -p ~/.kube
|
||||
echo "${{ secrets.KUBE_CONFIG }}" | base64 -d > ~/.kube/config
|
||||
chmod 600 ~/.kube/config
|
||||
|
||||
- name: Deploy to Kubernetes
|
||||
run: |
|
||||
TAG=$(echo ${{ gitea.sha }} | cut -c1-7)
|
||||
sed -i "s|image:.*fengling-auth-service.*|image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}|g" k8s/deployment.yaml
|
||||
kubectl apply -f k8s/deployment.yaml -n fengling
|
||||
kubectl apply -f k8s/service.yaml -n fengling
|
||||
kubectl rollout status deployment/fengling-auth-service -n fengling --timeout=300s
|
||||
|
||||
- name: Verify deployment
|
||||
run: |
|
||||
kubectl get pods -n fengling -l app=fengling-auth-service
|
||||
kubectl get services -n fengling fengling-auth-service
|
||||
34
Directory.Packages.props
Normal file
34
Directory.Packages.props
Normal file
@ -0,0 +1,34 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
|
||||
<NetCorePalVersion>3.2.1</NetCorePalVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="Fengling.Platform.Infrastructure" Version="1.0.0" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.3" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="10.0.3" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.3" />
|
||||
<PackageVersion Include="NetCorePal.Extensions.Repository.EntityFrameworkCore.Snowflake" Version="3.2.1" />
|
||||
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.3" />
|
||||
<PackageVersion Include="NetCorePal.Extensions.Repository.EntityFrameworkCore" Version="$(NetCorePalVersion)" />
|
||||
<PackageVersion Include="NetCorePal.Extensions.Domain.Abstractions" Version="$(NetCorePalVersion)" />
|
||||
<PackageVersion Include="NetCorePal.Extensions.Primitives" Version="$(NetCorePalVersion)" />
|
||||
<PackageVersion Include="MediatR" Version="12.5.0" />
|
||||
<PackageVersion Include="OpenIddict.EntityFrameworkCore" Version="7.2.0" />
|
||||
<PackageVersion Include="NetCorePal.Extensions.AspNetCore" Version="3.2.1" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.3" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.3" />
|
||||
<PackageVersion Include="AspNetCore.HealthChecks.NpgSql" Version="9.0.0" />
|
||||
<PackageVersion Include="OpenIddict.AspNetCore" Version="7.2.0" />
|
||||
<PackageVersion Include="OpenIddict.Quartz" Version="7.2.0" />
|
||||
<PackageVersion Include="OpenTelemetry" Version="1.15.0" />
|
||||
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.3" />
|
||||
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.15.0" />
|
||||
<PackageVersion Include="Serilog.AspNetCore" Version="10.0.0" />
|
||||
<PackageVersion Include="Serilog.Sinks.Console" Version="6.1.1" />
|
||||
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.0" />
|
||||
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.15.0" />
|
||||
<PackageVersion Include="Swashbuckle.AspNetCore" Version="10.1.4" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
10
Dockerfile
10
Dockerfile
@ -4,14 +4,16 @@ EXPOSE 80
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["Fengling.AuthService.csproj", "./"]
|
||||
RUN dotnet restore "Fengling.AuthService.csproj"
|
||||
COPY ["NuGet.Config", "./"]
|
||||
COPY ["Directory.Packages.props", "./"]
|
||||
COPY ["src/Fengling.AuthService.csproj", "src/"]
|
||||
RUN dotnet restore "src/Fengling.AuthService.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src"
|
||||
RUN dotnet build "Fengling.AuthService.csproj" -c Release -o /app/build
|
||||
RUN dotnet build "src/Fengling.AuthService.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Fengling.AuthService.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
RUN dotnet publish "src/Fengling.AuthService.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
|
||||
5
Fengling.AuthService.slnx
Normal file
5
Fengling.AuthService.slnx
Normal file
@ -0,0 +1,5 @@
|
||||
<Solution>
|
||||
<Folder Name="/src/">
|
||||
<Project Path="src/Fengling.AuthService.csproj" />
|
||||
</Folder>
|
||||
</Solution>
|
||||
14
NuGet.Config
Normal file
14
NuGet.Config
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<clear />
|
||||
<add key="gitea" value="https://gitea.shtao1.cn/api/packages/fengling/nuget/index.json" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
<packageSourceCredentials>
|
||||
<gitea>
|
||||
<add key="Username" value="movingsam" />
|
||||
<add key="ClearTextPassword" value="c0d98dd2c0be7a39fdaef13c6b77137a26708550" />
|
||||
</gitea>
|
||||
</packageSourceCredentials>
|
||||
</configuration>
|
||||
73
k8s/deployment.yaml
Normal file
73
k8s/deployment.yaml
Normal file
@ -0,0 +1,73 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: fengling-auth-service
|
||||
namespace: fengling
|
||||
labels:
|
||||
app: fengling-auth-service
|
||||
version: v1
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: fengling-auth-service
|
||||
strategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
maxSurge: 1
|
||||
maxUnavailable: 0
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: fengling-auth-service
|
||||
version: v1
|
||||
spec:
|
||||
containers:
|
||||
- name: fengling-auth-service
|
||||
image: gitea.shtao1.cn/fengling/fengling-auth-service:latest
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 80
|
||||
name: http
|
||||
protocol: TCP
|
||||
env:
|
||||
- name: ASPNETCORE_ENVIRONMENT
|
||||
value: "Production"
|
||||
- name: ASPNETCORE_URLS
|
||||
value: "http://+:80"
|
||||
- name: ConnectionStrings__DefaultConnection
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: fengling-auth-secrets
|
||||
key: connection-string
|
||||
- name: OpenIddict__Issuer
|
||||
value: "https://auth.fengling.local"
|
||||
- name: OpenIddict__Audience
|
||||
value: "fengling-api"
|
||||
resources:
|
||||
requests:
|
||||
cpu: "100m"
|
||||
memory: "256Mi"
|
||||
limits:
|
||||
cpu: "500m"
|
||||
memory: "512Mi"
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 80
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 3
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 80
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 3
|
||||
imagePullSecrets:
|
||||
- name: gitea-registry-secret
|
||||
restartPolicy: Always
|
||||
terminationGracePeriodSeconds: 30
|
||||
37
k8s/service.yaml
Normal file
37
k8s/service.yaml
Normal file
@ -0,0 +1,37 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: fengling-auth-service
|
||||
namespace: fengling
|
||||
labels:
|
||||
app: fengling-auth-service
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: fengling-auth-service
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
targetPort: 80
|
||||
protocol: TCP
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: fengling-auth-service
|
||||
namespace: fengling
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: websecure
|
||||
spec:
|
||||
ingressClassName: traefik
|
||||
rules:
|
||||
- host: auth.fengling.local
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: fengling-auth-service
|
||||
port:
|
||||
number: 80
|
||||
@ -6,6 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Fengling.Platform.Infrastructure" />
|
||||
<PackageReference Include="NetCorePal.Extensions.AspNetCore" />
|
||||
<PackageReference Include="OpenIddict.Quartz" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" />
|
||||
@ -18,7 +19,7 @@
|
||||
<PackageReference Include="OpenIddict.AspNetCore" />
|
||||
<PackageReference Include="OpenIddict.EntityFrameworkCore" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
|
||||
<!-- <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />-->
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
|
||||
<PackageReference Include="Serilog.AspNetCore" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" />
|
||||
@ -35,8 +36,8 @@
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Fengling.Platform\Fengling.Platform.Domain\Fengling.Platform.Domain.csproj" />
|
||||
<ProjectReference Include="..\Fengling.Platform\Fengling.Platform.Infrastructure\Fengling.Platform.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
<!-- <ItemGroup>-->
|
||||
<!-- <ProjectReference Include="..\Fengling.Platform\Fengling.Platform.Domain\Fengling.Platform.Domain.csproj" />-->
|
||||
<!-- <ProjectReference Include="..\Fengling.Platform\Fengling.Platform.Infrastructure\Fengling.Platform.Infrastructure.csproj" />-->
|
||||
<!-- </ItemGroup>-->
|
||||
</Project>
|
||||
@ -23,19 +23,17 @@ Log.Logger = new LoggerConfiguration()
|
||||
builder.Host.UseSerilog();
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
builder.Services.AddDbContext<PlatformDbContext>(options =>
|
||||
builder.Services.AddPlatformCore<PlatformDbContext>(options =>
|
||||
{
|
||||
options.UseNpgsql(connectionString);
|
||||
options.UseOpenIddict();
|
||||
});
|
||||
}).AddIdentity<ApplicationUser, ApplicationRole>()
|
||||
.AddEntityFrameworkStores<PlatformDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
builder.Services.AddIdentity<ApplicationUser, ApplicationRole>()
|
||||
.AddEntityFrameworkStores<PlatformDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
builder.Services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||
Loading…
Reference in New Issue
Block a user