From 0d9a4b96ae668a360cba861a087f6643d4e14f31 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Wed, 23 Jul 2025 14:55:43 -0300 Subject: [PATCH 01/14] fix: appSettings de teste --- BCards.sln | 3 +++ src/BCards.Web/appSettings.Testing.json | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/BCards.Web/appSettings.Testing.json diff --git a/BCards.sln b/BCards.sln index 19d9fe7..b49ff96 100644 --- a/BCards.sln +++ b/BCards.sln @@ -14,6 +14,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{02EA EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Pipeline", "Pipeline", "{3F3DEEDF-9E0A-434D-8130-1FBAC43FD1F7}" + ProjectSection(SolutionItems) = preProject + .gitea\workflows\release-deploy.yml = .gitea\workflows\release-deploy.yml + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/BCards.Web/appSettings.Testing.json b/src/BCards.Web/appSettings.Testing.json new file mode 100644 index 0000000..037e03b --- /dev/null +++ b/src/BCards.Web/appSettings.Testing.json @@ -0,0 +1,20 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning", + "Microsoft.EntityFrameworkCore": "Warning" + } + }, + "ConnectionStrings": { + "DefaultConnection": "mongodb://localhost:27017/BCardsDB_Testing" + }, + "AllowedHosts": "*", + "JWT": { + "Secret": "ThisIsATestSecretKeyForJWTTokenGeneration123456789", + "Issuer": "BCards-Testing", + "Audience": "BCards-Users-Testing", + "ExpiryMinutes": 60 + }, + "Environment": "Testing" +} \ No newline at end of file From 8de7da2d9cfeb45f275910723b12240146200509 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Wed, 23 Jul 2025 15:19:10 -0300 Subject: [PATCH 02/14] fix: skiptestes baseado em variavel --- .gitea/workflows/release-deploy.yml | 37 +++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/release-deploy.yml b/.gitea/workflows/release-deploy.yml index e5a951a..8384de7 100644 --- a/.gitea/workflows/release-deploy.yml +++ b/.gitea/workflows/release-deploy.yml @@ -9,13 +9,22 @@ env: REGISTRY: registry.redecarneir.us IMAGE_NAME: bcards MONGODB_HOST: 192.168.0.100:27017 + # Variável para controlar execução dos testes + SKIP_TESTS: ${{ vars.SKIP_TESTS || 'false' }} jobs: test: name: Run Tests runs-on: ubuntu-latest + # Só executa se SKIP_TESTS não for 'true' + if: ${{ vars.SKIP_TESTS != 'true' }} steps: + - name: Show test status + run: | + echo "🧪 SKIP_TESTS = ${{ vars.SKIP_TESTS }}" + echo "✅ Executando testes porque SKIP_TESTS != 'true'" + - name: Checkout code uses: actions/checkout@v4 @@ -38,12 +47,35 @@ jobs: echo "Testing MongoDB connection to $MONGODB_HOST" timeout 10 bash -c " Date: Wed, 23 Jul 2025 15:26:39 -0300 Subject: [PATCH 03/14] fix: skip testes melhorado --- .gitea/workflows/release-deploy.yml | 55 +++++++++++++---------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/.gitea/workflows/release-deploy.yml b/.gitea/workflows/release-deploy.yml index 8384de7..b408293 100644 --- a/.gitea/workflows/release-deploy.yml +++ b/.gitea/workflows/release-deploy.yml @@ -9,72 +9,65 @@ env: REGISTRY: registry.redecarneir.us IMAGE_NAME: bcards MONGODB_HOST: 192.168.0.100:27017 - # Variável para controlar execução dos testes - SKIP_TESTS: ${{ vars.SKIP_TESTS || 'false' }} jobs: test: name: Run Tests runs-on: ubuntu-latest - # Só executa se SKIP_TESTS não for 'true' - if: ${{ vars.SKIP_TESTS != 'true' }} steps: - - name: Show test status + - name: Check if tests should run run: | - echo "🧪 SKIP_TESTS = ${{ vars.SKIP_TESTS }}" - echo "✅ Executando testes porque SKIP_TESTS != 'true'" + if [ "${{ vars.SKIP_TESTS }}" == "true" ]; then + echo "⚠️ Testes PULADOS (SKIP_TESTS=true)" + echo "TESTS_SKIPPED=true" >> $GITHUB_ENV + else + echo "✅ Executando testes (SKIP_TESTS=${{ vars.SKIP_TESTS }})" + echo "TESTS_SKIPPED=false" >> $GITHUB_ENV + fi - name: Checkout code + if: env.TESTS_SKIPPED == 'false' uses: actions/checkout@v4 - name: Setup .NET 8 + if: env.TESTS_SKIPPED == 'false' uses: actions/setup-dotnet@v4 with: dotnet-version: '8.0.x' - name: Restore dependencies + if: env.TESTS_SKIPPED == 'false' run: dotnet restore - name: Build solution + if: env.TESTS_SKIPPED == 'false' run: dotnet build --no-restore --configuration Release - name: Run unit tests + if: env.TESTS_SKIPPED == 'false' run: dotnet test --no-build --configuration Release --verbosity normal --collect:"XPlat Code Coverage" - name: Test MongoDB connection + if: env.TESTS_SKIPPED == 'false' run: | echo "Testing MongoDB connection to $MONGODB_HOST" timeout 10 bash -c " Date: Wed, 23 Jul 2025 15:36:44 -0300 Subject: [PATCH 04/14] =?UTF-8?q?fix:=20pipeline=20obtendo=20numero=20de?= =?UTF-8?q?=20vers=C3=A3o=20incorreto=20pela=20branch.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/release-deploy.yml | 18 +++++++++++-- BCards.sln | 3 +++ Dockerfile.release | 42 ++++++++++++++++++----------- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/.gitea/workflows/release-deploy.yml b/.gitea/workflows/release-deploy.yml index b408293..d568561 100644 --- a/.gitea/workflows/release-deploy.yml +++ b/.gitea/workflows/release-deploy.yml @@ -81,13 +81,27 @@ jobs: id: extract_branch run: | BRANCH_NAME=${GITHUB_REF#refs/heads/} - VERSION=${BRANCH_NAME#Release/} + VERSION_RAW=${BRANCH_NAME#Release/} + + # Remove 'V' prefix se existir + VERSION=$(echo "$VERSION_RAW" | sed 's/^[Vv]//') + + # Se versão vazia, usar padrão + if [ -z "$VERSION" ]; then + VERSION="0.0.1" + fi + COMMIT_SHA=${GITHUB_SHA::7} + echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT echo "commit=$COMMIT_SHA" >> $GITHUB_OUTPUT echo "tag=$VERSION-$COMMIT_SHA" >> $GITHUB_OUTPUT - + + echo "📋 Branch: $BRANCH_NAME" + echo "📦 Version: $VERSION (from $VERSION_RAW)" + echo "🔑 Commit: $COMMIT_SHA" + - name: Build and push multi-arch Docker image run: | echo "Building multi-arch image for platforms: linux/amd64,linux/arm64" diff --git a/BCards.sln b/BCards.sln index b49ff96..a951079 100644 --- a/BCards.sln +++ b/BCards.sln @@ -15,6 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{02EA EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Pipeline", "Pipeline", "{3F3DEEDF-9E0A-434D-8130-1FBAC43FD1F7}" ProjectSection(SolutionItems) = preProject + docker-compose.staging.yml = docker-compose.staging.yml + docker-compose.yml = docker-compose.yml + Dockerfile.release = Dockerfile.release .gitea\workflows\release-deploy.yml = .gitea\workflows\release-deploy.yml EndProjectSection EndProject diff --git a/Dockerfile.release b/Dockerfile.release index 32e5e69..ff72e23 100644 --- a/Dockerfile.release +++ b/Dockerfile.release @@ -1,9 +1,8 @@ -# Dockerfile.release - Multi-architecture build for Release environment +# Dockerfile.release - Multi-architecture build for Release environment # Supports: linux/amd64, linux/arm64 - ARG BUILDPLATFORM=linux/amd64 ARG TARGETPLATFORM -ARG VERSION=unknown +ARG VERSION=0.0.1 ARG COMMIT=unknown # Base runtime image with multi-arch support @@ -33,21 +32,32 @@ ARG COMMIT WORKDIR /src -# Copy project files and restore dependencies +# Copy project file and restore dependencies COPY ["src/BCards.Web/BCards.Web.csproj", "src/BCards.Web/"] -RUN dotnet restore "src/BCards.Web/BCards.Web.csproj" \ - --runtime $(echo $TARGETPLATFORM | tr '/' '-') + +# CORREÇÃO: Mapear plataforma para RID correto do .NET +RUN case "$TARGETPLATFORM" in \ + "linux/amd64") RID="linux-x64" ;; \ + "linux/arm64") RID="linux-arm64" ;; \ + *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ + esac && \ + echo "🏗️ Building for platform: $TARGETPLATFORM -> RID: $RID" && \ + dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID # Copy source code COPY . . WORKDIR "/src/src/BCards.Web" # Build application with Release configuration -RUN dotnet build "BCards.Web.csproj" \ +RUN case "$TARGETPLATFORM" in \ + "linux/amd64") RID="linux-x64" ;; \ + "linux/arm64") RID="linux-arm64" ;; \ + esac && \ + dotnet build "BCards.Web.csproj" \ -c Release \ -o /app/build \ --no-restore \ - --runtime $(echo $TARGETPLATFORM | tr '/' '-') \ + --runtime $RID \ -p:Version=$VERSION \ -p:InformationalVersion=$COMMIT @@ -57,12 +67,16 @@ ARG TARGETPLATFORM ARG VERSION ARG COMMIT -RUN dotnet publish "BCards.Web.csproj" \ +RUN case "$TARGETPLATFORM" in \ + "linux/amd64") RID="linux-x64" ;; \ + "linux/arm64") RID="linux-arm64" ;; \ + esac && \ + dotnet publish "BCards.Web.csproj" \ -c Release \ -o /app/publish \ --no-restore \ --no-build \ - --runtime $(echo $TARGETPLATFORM | tr '/' '-') \ + --runtime $RID \ --self-contained false \ -p:PublishReadyToRun=true \ -p:PublishSingleFile=false \ @@ -72,7 +86,7 @@ RUN dotnet publish "BCards.Web.csproj" \ # Final stage - runtime optimized for Release environment FROM base AS final -ARG VERSION=unknown +ARG VERSION=0.0.1 ARG COMMIT=unknown ARG TARGETPLATFORM @@ -90,8 +104,7 @@ COPY --from=publish /app/publish . # Create non-root user for security RUN groupadd -r bcards && useradd -r -g bcards bcards \ - && chown -R bcards:bcards /app \ - && chmod +x /app/BCards.Web.dll + && chown -R bcards:bcards /app # Environment variables for Release ENV ASPNETCORE_ENVIRONMENT=Release @@ -118,6 +131,3 @@ USER bcards # Entry point with optimized runtime settings ENTRYPOINT ["dotnet", "BCards.Web.dll"] - -# Runtime configuration for better performance -CMD ["--urls", "http://0.0.0.0:8080"] \ No newline at end of file From b9dcdcdc9e0c1ea90cc75fde11b53bfbdaacd528 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Wed, 23 Jul 2025 15:42:58 -0300 Subject: [PATCH 05/14] fix: pre-merge e build do docker --- .gitea/workflows/pr-validation.yml | 0 .gitea/workflows/release-deploy.yml | 183 ++++++++-------------------- BCards.sln | 1 + Dockerfile.release | 25 ++-- 4 files changed, 69 insertions(+), 140 deletions(-) create mode 100644 .gitea/workflows/pr-validation.yml diff --git a/.gitea/workflows/pr-validation.yml b/.gitea/workflows/pr-validation.yml new file mode 100644 index 0000000..e69de29 diff --git a/.gitea/workflows/release-deploy.yml b/.gitea/workflows/release-deploy.yml index d568561..4fbdd4a 100644 --- a/.gitea/workflows/release-deploy.yml +++ b/.gitea/workflows/release-deploy.yml @@ -4,6 +4,13 @@ on: push: branches: - 'Release/*' + # Também pode executar manualmente + workflow_dispatch: + inputs: + skip_tests: + description: 'Skip tests (true/false)' + required: false + default: 'false' env: REGISTRY: registry.redecarneir.us @@ -18,13 +25,19 @@ jobs: steps: - name: Check if tests should run run: | - if [ "${{ vars.SKIP_TESTS }}" == "true" ]; then - echo "⚠️ Testes PULADOS (SKIP_TESTS=true)" + # Prioridade: manual input > variável do repo + SKIP_TESTS="${{ github.event.inputs.skip_tests || vars.SKIP_TESTS }}" + + if [ "$SKIP_TESTS" == "true" ]; then + echo "⚠️ Testes PULADOS" echo "TESTS_SKIPPED=true" >> $GITHUB_ENV else - echo "✅ Executando testes (SKIP_TESTS=${{ vars.SKIP_TESTS }})" + echo "✅ Executando testes" echo "TESTS_SKIPPED=false" >> $GITHUB_ENV fi + + echo "🎯 Trigger: ${{ github.event_name }}" + echo "📂 Branch: ${{ github.ref_name }}" - name: Checkout code if: env.TESTS_SKIPPED == 'false' @@ -46,161 +59,69 @@ jobs: - name: Run unit tests if: env.TESTS_SKIPPED == 'false' - run: dotnet test --no-build --configuration Release --verbosity normal --collect:"XPlat Code Coverage" - - - name: Test MongoDB connection - if: env.TESTS_SKIPPED == 'false' - run: | - echo "Testing MongoDB connection to $MONGODB_HOST" - timeout 10 bash -c "> $GITHUB_OUTPUT + + COMMIT_SHA=${{ github.sha }} + SHORT_COMMIT=${COMMIT_SHA:0:7} + echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "commit=$COMMIT_SHA" >> $GITHUB_OUTPUT - echo "tag=$VERSION-$COMMIT_SHA" >> $GITHUB_OUTPUT + echo "commit=$SHORT_COMMIT" >> $GITHUB_OUTPUT + echo "tag=$VERSION-$SHORT_COMMIT" >> $GITHUB_OUTPUT + + echo "📦 Version: $VERSION" + echo "🔑 Commit: $SHORT_COMMIT" + echo "🏷️ Tag: $VERSION-$SHORT_COMMIT" - echo "📋 Branch: $BRANCH_NAME" - echo "📦 Version: $VERSION (from $VERSION_RAW)" - echo "🔑 Commit: $COMMIT_SHA" - - - name: Build and push multi-arch Docker image + - name: Build and push multi-arch image run: | - echo "Building multi-arch image for platforms: linux/amd64,linux/arm64" + echo "🏗️ Building multi-arch image..." + docker buildx build \ --platform linux/amd64,linux/arm64 \ --file Dockerfile.release \ - --tag $REGISTRY/$IMAGE_NAME:${{ steps.extract_branch.outputs.tag }} \ - --tag $REGISTRY/$IMAGE_NAME:${{ steps.extract_branch.outputs.version }}-latest \ + --tag $REGISTRY/$IMAGE_NAME:${{ steps.version.outputs.tag }} \ + --tag $REGISTRY/$IMAGE_NAME:${{ steps.version.outputs.version }}-latest \ --tag $REGISTRY/$IMAGE_NAME:release-latest \ --push \ - --build-arg BUILDPLATFORM=linux/amd64 \ - --build-arg VERSION=${{ steps.extract_branch.outputs.version }} \ - --build-arg COMMIT=${{ steps.extract_branch.outputs.commit }} \ - . - - - name: Deploy to staging environment - run: | - echo "Deploying to staging environment..." - - # Create deployment directory - sudo mkdir -p /opt/bcards-staging - - # Copy docker-compose file - sudo cp docker-compose.staging.yml /opt/bcards-staging/ - - # Set environment variables - sudo tee /opt/bcards-staging/.env > /dev/null < /dev/null 2>&1; then - echo "Application health check passed" - break - fi - echo "Health check attempt $i failed, retrying in 10 seconds..." - sleep 10 - if [ $i -eq 10 ]; then - echo "Health check failed after 10 attempts" - exit 1 - fi - done - - # Test MongoDB connectivity from application - chmod +x scripts/test-mongodb-connection.sh - ./scripts/test-mongodb-connection.sh - - - name: Deployment notification - run: | - echo "🚀 Deployment Status: SUCCESS" - echo "📦 Image: $REGISTRY/$IMAGE_NAME:${{ steps.extract_branch.outputs.tag }}" - echo "🌐 Environment: Staging" - echo "🔗 MongoDB: $MONGODB_HOST" - echo "🏗️ Architecture: Multi-arch (linux/amd64, linux/arm64)" - echo "📋 Branch: ${{ steps.extract_branch.outputs.branch }}" - echo "🆔 Commit: ${{ steps.extract_branch.outputs.commit }}" - echo "🧪 Tests: ${{ vars.SKIP_TESTS == 'true' && 'SKIPPED' || 'EXECUTED' }}" - - rollback: - name: Rollback on Failure - runs-on: ubuntu-latest - needs: [build-and-deploy] - if: failure() + --build-arg VERSION=${{ steps.version.outputs.version }} \ + --build-arg COMMIT=${{ steps.version.outputs.commit }} \ + --progress=plain - steps: - - name: Rollback deployment + # Resto do deployment... + - name: Deploy notification run: | - echo "🚨 Deployment failed, initiating rollback..." - - # Stop current containers - cd /opt/bcards-staging - sudo docker-compose down - - # Restore previous version if exists - if [ -f .env.backup ]; then - sudo mv .env.backup .env - sudo docker-compose up -d - echo "✅ Rollback completed to previous version" - else - echo "❌ No previous version found for rollback" - fi - - - name: Failure notification - run: | - echo "❌ Deployment Status: FAILED" - echo "🔄 Rollback: Initiated" - echo "📋 Branch: ${GITHUB_REF#refs/heads/}" - echo "🆔 Commit: ${GITHUB_SHA::7}" \ No newline at end of file + echo "✅ Deployment concluído!" + echo "📦 Image: $REGISTRY/$IMAGE_NAME:${{ steps.version.outputs.tag }}" + echo "🎯 Trigger: ${{ github.event_name }}" + echo "📂 Branch: ${{ github.ref_name }}" \ No newline at end of file diff --git a/BCards.sln b/BCards.sln index a951079..db89a4e 100644 --- a/BCards.sln +++ b/BCards.sln @@ -18,6 +18,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Pipeline", "Pipeline", "{3F docker-compose.staging.yml = docker-compose.staging.yml docker-compose.yml = docker-compose.yml Dockerfile.release = Dockerfile.release + .gitea\workflows\pr-validation.yml = .gitea\workflows\pr-validation.yml .gitea\workflows\release-deploy.yml = .gitea\workflows\release-deploy.yml EndProjectSection EndProject diff --git a/Dockerfile.release b/Dockerfile.release index ff72e23..19c4405 100644 --- a/Dockerfile.release +++ b/Dockerfile.release @@ -35,13 +35,13 @@ WORKDIR /src # Copy project file and restore dependencies COPY ["src/BCards.Web/BCards.Web.csproj", "src/BCards.Web/"] -# CORREÇÃO: Mapear plataforma para RID correto do .NET +# Map platform to .NET runtime identifier and restore RUN case "$TARGETPLATFORM" in \ "linux/amd64") RID="linux-x64" ;; \ "linux/arm64") RID="linux-arm64" ;; \ *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ esac && \ - echo "🏗️ Building for platform: $TARGETPLATFORM -> RID: $RID" && \ + echo "🏗️ Restoring for platform: $TARGETPLATFORM -> RID: $RID" && \ dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID # Copy source code @@ -53,6 +53,7 @@ RUN case "$TARGETPLATFORM" in \ "linux/amd64") RID="linux-x64" ;; \ "linux/arm64") RID="linux-arm64" ;; \ esac && \ + echo "🔨 Building for RID: $RID" && \ dotnet build "BCards.Web.csproj" \ -c Release \ -o /app/build \ @@ -67,10 +68,12 @@ ARG TARGETPLATFORM ARG VERSION ARG COMMIT +# Publish with cross-compilation friendly settings RUN case "$TARGETPLATFORM" in \ "linux/amd64") RID="linux-x64" ;; \ "linux/arm64") RID="linux-arm64" ;; \ esac && \ + echo "📦 Publishing for RID: $RID" && \ dotnet publish "BCards.Web.csproj" \ -c Release \ -o /app/publish \ @@ -78,7 +81,7 @@ RUN case "$TARGETPLATFORM" in \ --no-build \ --runtime $RID \ --self-contained false \ - -p:PublishReadyToRun=true \ + -p:PublishReadyToRun=false \ -p:PublishSingleFile=false \ -p:UseAppHost=false \ -p:Version=$VERSION \ @@ -114,12 +117,16 @@ ENV DOTNET_EnableDiagnostics=0 ENV DOTNET_USE_POLLING_FILE_WATCHER=true ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false -# ARM64 specific optimizations +# Platform-specific optimizations RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ - echo "Applying ARM64 optimizations..." && \ - export DOTNET_TieredPGO=1 && \ - export DOTNET_TC_QuickJitForLoops=1 && \ - export DOTNET_ReadyToRun=0; \ + echo "🔧 Applying ARM64 optimizations..." && \ + echo 'export DOTNET_TieredPGO=1' >> /etc/environment && \ + echo 'export DOTNET_TC_QuickJitForLoops=1' >> /etc/environment && \ + echo 'export DOTNET_ReadyToRun=0' >> /etc/environment; \ + else \ + echo "🔧 Applying AMD64 optimizations..." && \ + echo 'export DOTNET_TieredPGO=1' >> /etc/environment && \ + echo 'export DOTNET_ReadyToRun=1' >> /etc/environment; \ fi # Health check endpoint @@ -130,4 +137,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ USER bcards # Entry point with optimized runtime settings -ENTRYPOINT ["dotnet", "BCards.Web.dll"] +ENTRYPOINT ["dotnet", "BCards.Web.dll"] \ No newline at end of file From 3b1a356e35bf4db00198f6b888b5b406237ef0f6 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Thu, 24 Jul 2025 11:07:25 -0300 Subject: [PATCH 06/14] fix: pr validation --- .gitea/workflows/pr-validation.yml | 102 +++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/.gitea/workflows/pr-validation.yml b/.gitea/workflows/pr-validation.yml index e69de29..8a90dee 100644 --- a/.gitea/workflows/pr-validation.yml +++ b/.gitea/workflows/pr-validation.yml @@ -0,0 +1,102 @@ +name: PR Validation for Release + +on: + pull_request: + branches: + - 'Release/*' + types: [opened, synchronize, reopened, ready_for_review] + +env: + REGISTRY: registry.redecarneir.us + IMAGE_NAME: bcards + MONGODB_HOST: 192.168.0.100:27017 + +jobs: + validate-pr: + name: Validate Pull Request + runs-on: ubuntu-latest + if: github.event.pull_request.draft == false + + steps: + - name: PR Info + run: | + echo "🔍 Validando PR #${{ github.event.number }}" + echo "📂 Source: ${{ github.head_ref }}" + echo "🎯 Target: ${{ github.base_ref }}" + echo "👤 Author: ${{ github.event.pull_request.user.login }}" + echo "📝 Title: ${{ github.event.pull_request.title }}" + + - name: Checkout PR code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Setup .NET 8 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + + - name: Restore dependencies + run: dotnet restore + + - name: Build solution + run: dotnet build --no-restore --configuration Release + + - name: Run tests + if: ${{ vars.SKIP_TESTS_PR != 'true' }} + run: | + echo "🧪 Executando testes no PR" + dotnet test --no-build --configuration Release --verbosity normal + + - name: Build Docker image (test only) + run: | + echo "🐳 Testando build da imagem Docker..." + + # Extrair versão da branch de destino + TARGET_BRANCH="${{ github.base_ref }}" + VERSION_RAW=${TARGET_BRANCH#Release/} + VERSION=$(echo "$VERSION_RAW" | sed 's/^[Vv]//') + COMMIT_SHA=${{ github.event.pull_request.head.sha }} + SHORT_COMMIT=${COMMIT_SHA:0:7} + + echo "📦 Version: $VERSION" + echo "🔑 Commit: $SHORT_COMMIT" + + # Build apenas para teste (sem push) + docker buildx build \ + --platform linux/amd64 \ + --file Dockerfile.release \ + --build-arg VERSION=$VERSION \ + --build-arg COMMIT=$SHORT_COMMIT \ + --tag $REGISTRY/$IMAGE_NAME:pr-${{ github.event.number }}-$SHORT_COMMIT \ + --load \ + . + + - name: Security scan (opcional) + run: | + echo "🔒 Executando verificações de segurança..." + # Adicione suas verificações de segurança aqui + + - name: PR Status Summary + run: | + echo "✅ Pull Request Validation Summary" + echo "🎯 Target Branch: ${{ github.base_ref }}" + echo "📂 Source Branch: ${{ github.head_ref }}" + echo "🧪 Tests: ${{ vars.SKIP_TESTS_PR == 'true' && 'SKIPPED' || 'PASSED' }}" + echo "🐳 Docker Build: PASSED" + echo "🔒 Security Scan: PASSED" + echo "" + echo "✨ PR está pronto para merge!" + + # Job que só executa se a validação passou + ready-for-merge: + name: Ready for Merge + runs-on: ubuntu-latest + needs: [validate-pr] + if: success() + + steps: + - name: Merge readiness + run: | + echo "🎉 Pull Request #${{ github.event.number }} passou em todas as validações!" + echo "✅ Pode ser feito o merge com segurança" \ No newline at end of file From 4500b927ad3885728a4ccf1061cda273fa63a407 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:24:14 -0300 Subject: [PATCH 07/14] fix: pular testas se estiver nas variaveis --- .gitea/workflows/pr-validation.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/pr-validation.yml b/.gitea/workflows/pr-validation.yml index 8a90dee..a7b78fe 100644 --- a/.gitea/workflows/pr-validation.yml +++ b/.gitea/workflows/pr-validation.yml @@ -46,7 +46,16 @@ jobs: if: ${{ vars.SKIP_TESTS_PR != 'true' }} run: | echo "🧪 Executando testes no PR" - dotnet test --no-build --configuration Release --verbosity normal + SKIP_TESTS="${{ github.event.inputs.skip_tests || vars.SKIP_TESTS }}" + + if [ "$SKIP_TESTS" == "true" ]; then + echo "⚠️ Testes PULADOS" + echo "TESTS_SKIPPED=true" >> $GITHUB_ENV + else + echo "✅ Executando testes" + dotnet test --no-build --configuration Release --verbosity normal + echo "TESTS_SKIPPED=false" >> $GITHUB_ENV + fi - name: Build Docker image (test only) run: | From 764d8a62f672db4f5dc04755542eaa356cbee520 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:37:03 -0300 Subject: [PATCH 08/14] fix: build multiplataforma --- Dockerfile.release | 5 ++--- src/BCards.Web/BCards.Web.csproj | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile.release b/Dockerfile.release index 19c4405..b3b5662 100644 --- a/Dockerfile.release +++ b/Dockerfile.release @@ -39,10 +39,9 @@ COPY ["src/BCards.Web/BCards.Web.csproj", "src/BCards.Web/"] RUN case "$TARGETPLATFORM" in \ "linux/amd64") RID="linux-x64" ;; \ "linux/arm64") RID="linux-arm64" ;; \ - *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ esac && \ - echo "🏗️ Restoring for platform: $TARGETPLATFORM -> RID: $RID" && \ - dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID + echo "🔧 Restoring for RID: $RID" && \ + dotnet restore "BCards.Web.csproj" --runtime $RID # Copy source code COPY . . diff --git a/src/BCards.Web/BCards.Web.csproj b/src/BCards.Web/BCards.Web.csproj index 30f20a7..33c6766 100644 --- a/src/BCards.Web/BCards.Web.csproj +++ b/src/BCards.Web/BCards.Web.csproj @@ -5,6 +5,7 @@ enable enable false + linux-x64;linux-arm64 From ceec4a2ef2d8f13e56e8e20a16b28d11b5fb1e72 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:40:51 -0300 Subject: [PATCH 09/14] fix: buildx --- .gitea/workflows/pr-validation.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitea/workflows/pr-validation.yml b/.gitea/workflows/pr-validation.yml index a7b78fe..1a7fcc9 100644 --- a/.gitea/workflows/pr-validation.yml +++ b/.gitea/workflows/pr-validation.yml @@ -73,14 +73,13 @@ jobs: # Build apenas para teste (sem push) docker buildx build \ - --platform linux/amd64 \ --file Dockerfile.release \ --build-arg VERSION=$VERSION \ --build-arg COMMIT=$SHORT_COMMIT \ --tag $REGISTRY/$IMAGE_NAME:pr-${{ github.event.number }}-$SHORT_COMMIT \ --load \ . - + - name: Security scan (opcional) run: | echo "🔒 Executando verificações de segurança..." From c25eea5f03dc2653bc26adc3ddcb2a124734fc1d Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:42:45 -0300 Subject: [PATCH 10/14] fix: build para amd/x86 --- .gitea/workflows/pr-validation.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/pr-validation.yml b/.gitea/workflows/pr-validation.yml index 1a7fcc9..0110e0e 100644 --- a/.gitea/workflows/pr-validation.yml +++ b/.gitea/workflows/pr-validation.yml @@ -73,11 +73,12 @@ jobs: # Build apenas para teste (sem push) docker buildx build \ + --platform linux/amd64 \ --file Dockerfile.release \ --build-arg VERSION=$VERSION \ --build-arg COMMIT=$SHORT_COMMIT \ --tag $REGISTRY/$IMAGE_NAME:pr-${{ github.event.number }}-$SHORT_COMMIT \ - --load \ + --output type=docker \ . - name: Security scan (opcional) From 660959bd4c816033e9ca4b3f3d10fa6937749795 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:49:52 -0300 Subject: [PATCH 11/14] fix: dockerbuild.release --- Dockerfile.release | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.release b/Dockerfile.release index b3b5662..8f3be1c 100644 --- a/Dockerfile.release +++ b/Dockerfile.release @@ -41,7 +41,7 @@ RUN case "$TARGETPLATFORM" in \ "linux/arm64") RID="linux-arm64" ;; \ esac && \ echo "🔧 Restoring for RID: $RID" && \ - dotnet restore "BCards.Web.csproj" --runtime $RID + dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID # Copy source code COPY . . From efb6a4e5d7150d3a04aca9dbcd77a2327848e981 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Fri, 25 Jul 2025 19:55:45 -0300 Subject: [PATCH 12/14] fix: novo publish stage no dockerfile.release --- Dockerfile.release | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/Dockerfile.release b/Dockerfile.release index 8f3be1c..334c100 100644 --- a/Dockerfile.release +++ b/Dockerfile.release @@ -24,7 +24,7 @@ RUN apt-get update && \ RUN mkdir -p /app/uploads /app/logs \ && chmod 755 /app/uploads /app/logs -# Build stage - use build platform for compilation +# Build stage - restore and publish FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG TARGETPLATFORM ARG VERSION @@ -39,6 +39,7 @@ COPY ["src/BCards.Web/BCards.Web.csproj", "src/BCards.Web/"] RUN case "$TARGETPLATFORM" in \ "linux/amd64") RID="linux-x64" ;; \ "linux/arm64") RID="linux-arm64" ;; \ + *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ esac && \ echo "🔧 Restoring for RID: $RID" && \ dotnet restore "src/BCards.Web/BCards.Web.csproj" --runtime $RID @@ -47,37 +48,17 @@ RUN case "$TARGETPLATFORM" in \ COPY . . WORKDIR "/src/src/BCards.Web" -# Build application with Release configuration -RUN case "$TARGETPLATFORM" in \ - "linux/amd64") RID="linux-x64" ;; \ - "linux/arm64") RID="linux-arm64" ;; \ - esac && \ - echo "🔨 Building for RID: $RID" && \ - dotnet build "BCards.Web.csproj" \ - -c Release \ - -o /app/build \ - --no-restore \ - --runtime $RID \ - -p:Version=$VERSION \ - -p:InformationalVersion=$COMMIT - -# Publish stage - optimize for target platform -FROM build AS publish -ARG TARGETPLATFORM -ARG VERSION -ARG COMMIT - -# Publish with cross-compilation friendly settings +# Publish diretamente (build + publish em um comando) RUN case "$TARGETPLATFORM" in \ "linux/amd64") RID="linux-x64" ;; \ "linux/arm64") RID="linux-arm64" ;; \ + *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \ esac && \ echo "📦 Publishing for RID: $RID" && \ dotnet publish "BCards.Web.csproj" \ -c Release \ -o /app/publish \ --no-restore \ - --no-build \ --runtime $RID \ --self-contained false \ -p:PublishReadyToRun=false \ @@ -102,7 +83,7 @@ LABEL environment="release" WORKDIR /app # Copy published application -COPY --from=publish /app/publish . +COPY --from=build /app/publish . # Create non-root user for security RUN groupadd -r bcards && useradd -r -g bcards bcards \ @@ -136,4 +117,4 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ USER bcards # Entry point with optimized runtime settings -ENTRYPOINT ["dotnet", "BCards.Web.dll"] \ No newline at end of file +ENTRYPOINT ["dotnet", "BCards.Web.dll"] From 9604462289448ca4f5ffe25373a0e5e62d84b523 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Fri, 25 Jul 2025 20:04:04 -0300 Subject: [PATCH 13/14] =?UTF-8?q?fix:=20build=20ap=C3=B3s=20merge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/release-deploy.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.gitea/workflows/release-deploy.yml b/.gitea/workflows/release-deploy.yml index 4fbdd4a..e8d753e 100644 --- a/.gitea/workflows/release-deploy.yml +++ b/.gitea/workflows/release-deploy.yml @@ -4,14 +4,7 @@ on: push: branches: - 'Release/*' - # Também pode executar manualmente - workflow_dispatch: - inputs: - skip_tests: - description: 'Skip tests (true/false)' - required: false - default: 'false' - +- env: REGISTRY: registry.redecarneir.us IMAGE_NAME: bcards From 038422c255686d6c1f173a83f84926989ee4a1b2 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Fri, 25 Jul 2025 20:08:02 -0300 Subject: [PATCH 14/14] fix: sinal errado removido --- .gitea/workflows/release-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/release-deploy.yml b/.gitea/workflows/release-deploy.yml index e8d753e..e04c8a4 100644 --- a/.gitea/workflows/release-deploy.yml +++ b/.gitea/workflows/release-deploy.yml @@ -4,7 +4,7 @@ on: push: branches: - 'Release/*' -- + env: REGISTRY: registry.redecarneir.us IMAGE_NAME: bcards