diff --git a/.build/dev/app.Dockerfile b/.build/dev/app.Dockerfile new file mode 100644 index 0000000..fa9f134 --- /dev/null +++ b/.build/dev/app.Dockerfile @@ -0,0 +1,23 @@ +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base +USER $APP_UID +WORKDIR /app +EXPOSE 9755 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +ARG BUILD_CONFIGURATION=Debug +WORKDIR /src +COPY ["Submission.Api/Submission.Api.csproj", "Submission.Api/"] +RUN dotnet restore "Submission.Api/Submission.Api.csproj" +COPY . . +WORKDIR "/src/Submission.Api" +RUN dotnet build "./Submission.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Debug +RUN dotnet publish "./Submission.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Submission.Api.dll"] diff --git a/.build/prod/app.Dockerfile b/.build/prod/app.Dockerfile new file mode 100644 index 0000000..042a232 --- /dev/null +++ b/.build/prod/app.Dockerfile @@ -0,0 +1,32 @@ +FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base +USER $APP_UID +WORKDIR /app +EXPOSE 9755 +EXPOSE 8081 + +FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build +ARG BUILD_CONFIGURATION=Release +ARG CI_COMMIT_SHORT_SHA +ARG CI_COMMIT_SHA +ARG CI_COMMIT_BRANCH +WORKDIR /src +COPY ["Submission.Api/Submission.Api.csproj", "Submission.Api/"] +RUN dotnet restore "Submission.Api/Submission.Api.csproj" +COPY . . +WORKDIR "/src/Submission.Api" +RUN dotnet build "./Submission.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./Submission.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +FROM base AS final +ARG CI_COMMIT_SHORT_SHA +ARG CI_COMMIT_SHA +ARG CI_COMMIT_BRANCH +ENV CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA +ENV CI_COMMIT_SHA=$CI_COMMIT_SHA +ENV CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Submission.Api.dll"] diff --git a/.build/prod/compose.yml b/.build/prod/compose.yml new file mode 100644 index 0000000..9158ea0 --- /dev/null +++ b/.build/prod/compose.yml @@ -0,0 +1,16 @@ +services: + api: + build: + context: ../../ + dockerfile: .build/prod/app.Dockerfile + hostname: api + image: git.shihaam.dev/mvdevsunion/wpetition/api + + frontend: + build: + context: ../../ + dockerfile: .build/prod/frontend.Dockerfile + hostname: frontend + image: git.shihaam.dev/mvdevsunion/wpetition/frontend + depends_on: + - api diff --git a/.build/prod/frontend.Dockerfile b/.build/prod/frontend.Dockerfile new file mode 100644 index 0000000..6a72e11 --- /dev/null +++ b/.build/prod/frontend.Dockerfile @@ -0,0 +1,12 @@ +FROM nginx:alpine + +# Copy custom nginx configuration +COPY .build/prod/nginx.conf /etc/nginx/nginx.conf + +# Copy static frontend files +COPY Frontend/ /usr/share/nginx/html/ + +# Expose port 80 +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/.build/prod/nginx.conf b/.build/prod/nginx.conf new file mode 100644 index 0000000..bdf322e --- /dev/null +++ b/.build/prod/nginx.conf @@ -0,0 +1,53 @@ +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + sendfile on; + keepalive_timeout 65; + + # Gzip compression + gzip on; + gzip_vary on; + gzip_proxied any; + gzip_comp_level 6; + gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss; + + server { + listen 80; + server_name _; + + # Serve static frontend files + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri $uri/ /index.html; + } + + # Proxy API requests to the backend + location /api/ { + proxy_pass http://api:9755/api/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_cache_bypass $http_upgrade; + } + + # Optional: Proxy Swagger if you want it accessible + location /swagger { + proxy_pass http://api:9755/swagger; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } +} diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml new file mode 100644 index 0000000..8ff3bc5 --- /dev/null +++ b/.gitea/workflows/docker-build.yml @@ -0,0 +1,45 @@ +name: Build and Push Docker Images + +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + +jobs: + docker: + name: Build and Push Docker Images + runs-on: builder + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Login to Docker Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ${{ vars.DOCKER_REGISTRY_URL }} + username: ${{ vars.DOCKER_REGISTRY_USER }} + password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} + + - name: Build and push docker images + working-directory: .build/prod + run: docker compose --progress build --push + + + - name: Deploy production + if: github.event_name != 'pull_request' + run: | + ssh root@10.0.1.39 -t "cd /mnt && \ + docker compose --progress plain pull && \ + docker compose --progress plain down && \ + docker compose --progress plain up -d" + + - name: Clean up dangling images + if: github.event_name != 'pull_request' + run: ssh root@10.0.1.39 -t "docker image prune -f" diff --git a/.github/workflows/mirror-to-sargitea.yml b/.github/workflows/mirror-to-sargitea.yml new file mode 100644 index 0000000..8b7f65c --- /dev/null +++ b/.github/workflows/mirror-to-sargitea.yml @@ -0,0 +1,19 @@ +name: Sync Gitea Mirror on Push + +on: + push: + branches: + - main + +jobs: + sync-mirror: + runs-on: ubuntu-latest + + steps: + - name: Trigger Gitea Mirror Sync + run: | + curl -X POST \ + -H "Authorization: token ${{ secrets.SAR_GITEA_TOKEN }}" \ + -H "Accept: application/json" \ + -H "Content-Type: application/json" \ + https://git.shihaam.dev/api/v1/repos/${{ vars.SAR_GITEA_REPO_OWNER }}/${{ vars.SAR_GITEA_REPO_NAME }}/mirror-sync