diff --git a/.dockerignore b/.dockerignore
index 72acb0b..f092705 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,5 +1,12 @@
-bin/
-obj/
-Dockerfile
-.dockerignore
-*.md
+**/.git
+**/.idea
+**/bin
+**/obj
+**/.vs
+**/*.user
+**/*.suo
+**/node_modules
+**/.DS_Store
+README.md
+.gitignore
+.dockerignore
\ No newline at end of file
diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml
new file mode 100644
index 0000000..dd0e660
--- /dev/null
+++ b/.gitea/workflows/ci.yaml
@@ -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'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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'
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
diff --git a/Directory.Packages.props b/Directory.Packages.props
new file mode 100644
index 0000000..780d87f
--- /dev/null
+++ b/Directory.Packages.props
@@ -0,0 +1,34 @@
+
+
+ true
+ 3.2.1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index 736232d..e534d54 100644
--- a/Dockerfile
+++ b/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
diff --git a/Fengling.AuthService.slnx b/Fengling.AuthService.slnx
new file mode 100644
index 0000000..9f2f00c
--- /dev/null
+++ b/Fengling.AuthService.slnx
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/NuGet.Config b/NuGet.Config
new file mode 100644
index 0000000..3dd3d72
--- /dev/null
+++ b/NuGet.Config
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml
new file mode 100644
index 0000000..532295f
--- /dev/null
+++ b/k8s/deployment.yaml
@@ -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
\ No newline at end of file
diff --git a/k8s/service.yaml b/k8s/service.yaml
new file mode 100644
index 0000000..d848117
--- /dev/null
+++ b/k8s/service.yaml
@@ -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
\ No newline at end of file
diff --git a/Configuration/FormValueRequiredAttribute.cs b/src/Configuration/FormValueRequiredAttribute.cs
similarity index 100%
rename from Configuration/FormValueRequiredAttribute.cs
rename to src/Configuration/FormValueRequiredAttribute.cs
diff --git a/Configuration/OpenIddictSetup.cs b/src/Configuration/OpenIddictSetup.cs
similarity index 100%
rename from Configuration/OpenIddictSetup.cs
rename to src/Configuration/OpenIddictSetup.cs
diff --git a/Controllers/AccessLogsController.cs b/src/Controllers/AccessLogsController.cs
similarity index 100%
rename from Controllers/AccessLogsController.cs
rename to src/Controllers/AccessLogsController.cs
diff --git a/Controllers/AccountController.cs b/src/Controllers/AccountController.cs
similarity index 100%
rename from Controllers/AccountController.cs
rename to src/Controllers/AccountController.cs
diff --git a/Controllers/AuditLogsController.cs b/src/Controllers/AuditLogsController.cs
similarity index 100%
rename from Controllers/AuditLogsController.cs
rename to src/Controllers/AuditLogsController.cs
diff --git a/Controllers/AuthorizationController.cs b/src/Controllers/AuthorizationController.cs
similarity index 100%
rename from Controllers/AuthorizationController.cs
rename to src/Controllers/AuthorizationController.cs
diff --git a/Controllers/DashboardController.cs b/src/Controllers/DashboardController.cs
similarity index 100%
rename from Controllers/DashboardController.cs
rename to src/Controllers/DashboardController.cs
diff --git a/Controllers/LogoutController.cs b/src/Controllers/LogoutController.cs
similarity index 100%
rename from Controllers/LogoutController.cs
rename to src/Controllers/LogoutController.cs
diff --git a/Controllers/OAuthClientsController.cs b/src/Controllers/OAuthClientsController.cs
similarity index 100%
rename from Controllers/OAuthClientsController.cs
rename to src/Controllers/OAuthClientsController.cs
diff --git a/Controllers/RolesController.cs b/src/Controllers/RolesController.cs
similarity index 100%
rename from Controllers/RolesController.cs
rename to src/Controllers/RolesController.cs
diff --git a/Controllers/StatsController.cs b/src/Controllers/StatsController.cs
similarity index 100%
rename from Controllers/StatsController.cs
rename to src/Controllers/StatsController.cs
diff --git a/Controllers/TenantsController.cs b/src/Controllers/TenantsController.cs
similarity index 100%
rename from Controllers/TenantsController.cs
rename to src/Controllers/TenantsController.cs
diff --git a/Controllers/TokenController.cs b/src/Controllers/TokenController.cs
similarity index 100%
rename from Controllers/TokenController.cs
rename to src/Controllers/TokenController.cs
diff --git a/Controllers/UsersController.cs b/src/Controllers/UsersController.cs
similarity index 100%
rename from Controllers/UsersController.cs
rename to src/Controllers/UsersController.cs
diff --git a/Fengling.AuthService.csproj b/src/Fengling.AuthService.csproj
similarity index 79%
rename from Fengling.AuthService.csproj
rename to src/Fengling.AuthService.csproj
index 9dd6279..09032b3 100644
--- a/Fengling.AuthService.csproj
+++ b/src/Fengling.AuthService.csproj
@@ -6,6 +6,7 @@
+
@@ -18,7 +19,7 @@
-
+
@@ -35,8 +36,8 @@
-
-
-
-
+
+
+
+
diff --git a/Fengling.AuthService.http b/src/Fengling.AuthService.http
similarity index 100%
rename from Fengling.AuthService.http
rename to src/Fengling.AuthService.http
diff --git a/Program.cs b/src/Program.cs
similarity index 94%
rename from Program.cs
rename to src/Program.cs
index 80696e1..b01ecc8 100644
--- a/Program.cs
+++ b/src/Program.cs
@@ -23,19 +23,17 @@ Log.Logger = new LoggerConfiguration()
builder.Host.UseSerilog();
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
-builder.Services.AddDbContext(options =>
+builder.Services.AddPlatformCore(options =>
{
options.UseNpgsql(connectionString);
options.UseOpenIddict();
-});
+}).AddIdentity()
+.AddEntityFrameworkStores()
+.AddDefaultTokenProviders();
builder.Services.AddRazorPages();
builder.Services.AddControllersWithViews();
-builder.Services.AddIdentity()
- .AddEntityFrameworkStores()
- .AddDefaultTokenProviders();
-
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
diff --git a/Properties/launchSettings.json b/src/Properties/launchSettings.json
similarity index 100%
rename from Properties/launchSettings.json
rename to src/Properties/launchSettings.json
diff --git a/ViewModels/AuthorizeViewModel.cs b/src/ViewModels/AuthorizeViewModel.cs
similarity index 100%
rename from ViewModels/AuthorizeViewModel.cs
rename to src/ViewModels/AuthorizeViewModel.cs
diff --git a/ViewModels/DashboardViewModel.cs b/src/ViewModels/DashboardViewModel.cs
similarity index 100%
rename from ViewModels/DashboardViewModel.cs
rename to src/ViewModels/DashboardViewModel.cs
diff --git a/ViewModels/LoginViewModel.cs b/src/ViewModels/LoginViewModel.cs
similarity index 100%
rename from ViewModels/LoginViewModel.cs
rename to src/ViewModels/LoginViewModel.cs
diff --git a/ViewModels/RegisterViewModel.cs b/src/ViewModels/RegisterViewModel.cs
similarity index 100%
rename from ViewModels/RegisterViewModel.cs
rename to src/ViewModels/RegisterViewModel.cs
diff --git a/Views/Account/Login.cshtml b/src/Views/Account/Login.cshtml
similarity index 100%
rename from Views/Account/Login.cshtml
rename to src/Views/Account/Login.cshtml
diff --git a/Views/Account/Register.cshtml b/src/Views/Account/Register.cshtml
similarity index 100%
rename from Views/Account/Register.cshtml
rename to src/Views/Account/Register.cshtml
diff --git a/Views/Authorization/Authorize.cshtml b/src/Views/Authorization/Authorize.cshtml
similarity index 100%
rename from Views/Authorization/Authorize.cshtml
rename to src/Views/Authorization/Authorize.cshtml
diff --git a/Views/Dashboard/Index.cshtml b/src/Views/Dashboard/Index.cshtml
similarity index 100%
rename from Views/Dashboard/Index.cshtml
rename to src/Views/Dashboard/Index.cshtml
diff --git a/Views/Dashboard/Profile.cshtml b/src/Views/Dashboard/Profile.cshtml
similarity index 100%
rename from Views/Dashboard/Profile.cshtml
rename to src/Views/Dashboard/Profile.cshtml
diff --git a/Views/Dashboard/Settings.cshtml b/src/Views/Dashboard/Settings.cshtml
similarity index 100%
rename from Views/Dashboard/Settings.cshtml
rename to src/Views/Dashboard/Settings.cshtml
diff --git a/Views/Shared/_Layout.cshtml b/src/Views/Shared/_Layout.cshtml
similarity index 100%
rename from Views/Shared/_Layout.cshtml
rename to src/Views/Shared/_Layout.cshtml
diff --git a/Views/_ViewImports.cshtml b/src/Views/_ViewImports.cshtml
similarity index 100%
rename from Views/_ViewImports.cshtml
rename to src/Views/_ViewImports.cshtml
diff --git a/Views/_ViewStart.cshtml b/src/Views/_ViewStart.cshtml
similarity index 100%
rename from Views/_ViewStart.cshtml
rename to src/Views/_ViewStart.cshtml
diff --git a/appsettings.Development.json b/src/appsettings.Development.json
similarity index 100%
rename from appsettings.Development.json
rename to src/appsettings.Development.json
diff --git a/appsettings.Testing.json b/src/appsettings.Testing.json
similarity index 100%
rename from appsettings.Testing.json
rename to src/appsettings.Testing.json
diff --git a/appsettings.json b/src/appsettings.json
similarity index 100%
rename from appsettings.json
rename to src/appsettings.json
diff --git a/wwwroot/css/styles.css b/src/wwwroot/css/styles.css
similarity index 100%
rename from wwwroot/css/styles.css
rename to src/wwwroot/css/styles.css