fix: ajustes de build
Some checks failed
Deploy ASP.NET MVC to OCI / build-and-deploy (push) Failing after 23m43s

This commit is contained in:
Ricardo Carneiro 2025-09-13 23:47:20 -03:00
parent 0a9f2ba8fe
commit a530a40b4b
3 changed files with 147 additions and 51 deletions

View File

@ -1,13 +1,27 @@
bin/ bin/
obj/ obj/
.git/ .git/
.gitea/
.gitignore .gitignore
*.md *.md
README.md README.md
CLAUDE.md
tests/ tests/
docs/ docs/
.vs/ .vs/
.vscode/ .vscode/
**/.DS_Store **/.DS_Store
**/Thumbs.db **/Thumbs.db
**/node_modules/
**/*.log
**/*.tmp
**/temp/
**/*.bak
Properties/launchSettings.json
*.user
*.suo
*.cache
.env
.env.*
!.env.example

View File

@ -1,64 +1,78 @@
name: Deploy ASP.NET MVC to OCI name: Deploy ASP.NET MVC to OCI
on: on:
push: push:
branches: [ main, master ] branches: [ main, master, 'release/*' ]
pull_request: pull_request:
branches: [ main, master ] branches: [ main, master ]
jobs: jobs:
build-and-deploy: build-and-deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Set build variables
id: vars
run: |
if [[ ${{ github.ref }} == refs/heads/main ]] || [[ ${{ github.ref }} == refs/heads/master ]]; then
echo "PLATFORM=linux/arm64" >> $GITHUB_OUTPUT
echo "TARGET_ARCH=arm64" >> $GITHUB_OUTPUT
echo "TAG_SUFFIX=" >> $GITHUB_OUTPUT
echo "DEPLOY_ENV=production" >> $GITHUB_OUTPUT
elif [[ ${{ github.ref }} == refs/heads/release/* ]]; then
echo "PLATFORM=linux/amd64" >> $GITHUB_OUTPUT
echo "TARGET_ARCH=amd64" >> $GITHUB_OUTPUT
echo "TAG_SUFFIX=-staging" >> $GITHUB_OUTPUT
echo "DEPLOY_ENV=staging" >> $GITHUB_OUTPUT
else
echo "PLATFORM=linux/amd64" >> $GITHUB_OUTPUT
echo "TARGET_ARCH=amd64" >> $GITHUB_OUTPUT
echo "TAG_SUFFIX=-dev" >> $GITHUB_OUTPUT
echo "DEPLOY_ENV=development" >> $GITHUB_OUTPUT
fi
- name: Cache Docker layers - name: Cache Docker layers
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: /tmp/.buildx-cache path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }} key: ${{ runner.os }}-buildx-${{ steps.vars.outputs.TARGET_ARCH }}-${{ github.sha }}
restore-keys: | restore-keys: |
${{ runner.os }}-buildx-${{ steps.vars.outputs.TARGET_ARCH }}-
${{ runner.os }}-buildx- ${{ runner.os }}-buildx-
- name: Debug - List files
run: |
echo "=== Arquivos na raiz ==="
ls -la
echo "=== Procurando Dockerfile ==="
find . -name "Dockerfile" -o -name "dockerfile" -type f
echo "=== Estrutura do projeto ==="
tree -L 3 || find . -type d -name "convertit"
- name: Build and push Docker image - name: Build and push Docker image
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . context: .
file: ./Dockerfile file: ./Dockerfile
platforms: linux/arm64 platforms: ${{ steps.vars.outputs.PLATFORM }}
push: true push: true
tags: | tags: |
registry.redecarneir.us/convertit:latest registry.redecarneir.us/convertit:latest${{ steps.vars.outputs.TAG_SUFFIX }}
registry.redecarneir.us/convertit:${{ github.sha }} registry.redecarneir.us/convertit:${{ github.sha }}${{ steps.vars.outputs.TAG_SUFFIX }}
cache-from: | cache-from: |
type=local,src=/tmp/.buildx-cache type=local,src=/tmp/.buildx-cache
type=registry,ref=registry.redecarneir.us/convertit:cache type=registry,ref=registry.redecarneir.us/convertit:cache-${{ steps.vars.outputs.TARGET_ARCH }}
cache-to: | cache-to: |
type=local,dest=/tmp/.buildx-cache-new,mode=max type=local,dest=/tmp/.buildx-cache-new,mode=max
type=registry,ref=registry.redecarneir.us/convertit:cache,mode=max type=registry,ref=registry.redecarneir.us/convertit:cache-${{ steps.vars.outputs.TARGET_ARCH }},mode=max
build-args: | build-args: |
BUILDKIT_INLINE_CACHE=1 BUILDKIT_INLINE_CACHE=1
TARGETARCH=${{ steps.vars.outputs.TARGET_ARCH }}
- name: Move cache - name: Move cache
run: | run: |
rm -rf /tmp/.buildx-cache rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Deploy to OCI Server - name: Deploy to Production (ARM64)
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
uses: appleboy/ssh-action@v1.0.3 uses: appleboy/ssh-action@v1.0.3
with: with:
host: 129.146.116.218 host: 129.146.116.218
@ -70,13 +84,13 @@ jobs:
# Para o container anterior da aplicação (se existir) # Para o container anterior da aplicação (se existir)
docker stop convertit || true docker stop convertit || true
docker rm convertit || true docker rm convertit || true
# Remove imagem antiga # Remove imagem antiga
docker rmi registry.redecarneir.us/convertit:latest || true docker rmi registry.redecarneir.us/convertit:latest || true
# Puxa nova imagem # Puxa nova imagem ARM64
docker pull registry.redecarneir.us/convertit:latest docker pull registry.redecarneir.us/convertit:latest
# Executa o novo container na porta 80 # Executa o novo container na porta 80
docker run -d \ docker run -d \
--name convertit \ --name convertit \
@ -98,18 +112,69 @@ jobs:
-e DOTNET_EnableDiagnostics=0 \ -e DOTNET_EnableDiagnostics=0 \
-e DOTNET_RUNNING_IN_CONTAINER=true \ -e DOTNET_RUNNING_IN_CONTAINER=true \
registry.redecarneir.us/convertit:latest registry.redecarneir.us/convertit:latest
# Limpa imagens não utilizadas # Limpa imagens não utilizadas
docker image prune -f docker image prune -f
# Verifica se o container está rodando # Verifica se o container está rodando
docker ps | grep convertit docker ps | grep convertit
# Testa se a aplicação está respondendo na porta 80 # Testa se a aplicação está respondendo na porta 80
sleep 10 sleep 10
curl -f http://localhost:80 || echo "Aplicação pode estar inicializando..." curl -f http://localhost:80 || echo "Aplicação pode estar inicializando..."
- name: Deploy to Staging (x86_64)
if: startsWith(github.ref, 'refs/heads/release/')
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.STAGING_SSH_USERNAME }}
key: ${{ secrets.STAGING_SSH_PRIVATE_KEY }}
port: 22
timeout: 60s
script: |
# Para o container anterior da aplicação staging (se existir)
docker stop convertit-staging || true
docker rm convertit-staging || true
# Remove imagem antiga
docker rmi registry.redecarneir.us/convertit:latest-staging || true
# Puxa nova imagem x86_64
docker pull registry.redecarneir.us/convertit:latest-staging
# Executa o novo container staging na porta 8080
docker run -d \
--name convertit-staging \
--restart unless-stopped \
-p 8080:8080 \
--memory=1g \
--cpus=1.0 \
--health-cmd="curl -f http://localhost:8080/health || exit 1" \
--health-interval=30s \
--health-timeout=10s \
--health-retries=3 \
--health-start-period=60s \
-e ASPNETCORE_ENVIRONMENT=Staging \
-e ASPNETCORE_URLS="http://+:8080" \
-e DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
-e DOTNET_USE_POLLING_FILE_WATCHER=true \
-e DOTNET_EnableDiagnostics=0 \
-e DOTNET_RUNNING_IN_CONTAINER=true \
registry.redecarneir.us/convertit:latest-staging
# Limpa imagens não utilizadas
docker image prune -f
# Verifica se o container está rodando
docker ps | grep convertit-staging
# Testa se a aplicação está respondendo na porta 8080
sleep 10
curl -f http://localhost:8080 || echo "Aplicação staging pode estar inicializando..."
- name: Verify deployment - name: Verify deployment
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
uses: appleboy/ssh-action@v1.0.3 uses: appleboy/ssh-action@v1.0.3
with: with:
host: 129.146.116.218 host: 129.146.116.218
@ -119,9 +184,27 @@ jobs:
script: | script: |
echo "=== Status dos containers ===" echo "=== Status dos containers ==="
docker ps -a | grep convertit docker ps -a | grep convertit
echo "=== Logs da aplicação (últimas 20 linhas) ===" echo "=== Logs da aplicação (últimas 20 linhas) ==="
docker logs convertit --tail 20 docker logs convertit --tail 20
echo "=== Teste de conectividade ===" echo "=== Teste de conectividade ==="
curl -I http://localhost:80 || echo "Aplicação ainda não está acessível" curl -I http://localhost:80 || echo "Aplicação ainda não está acessível"
- name: Verify staging deployment
if: startsWith(github.ref, 'refs/heads/release/')
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.STAGING_HOST }}
username: ${{ secrets.STAGING_SSH_USERNAME }}
key: ${{ secrets.STAGING_SSH_PRIVATE_KEY }}
port: 22
script: |
echo "=== Status dos containers staging ==="
docker ps -a | grep convertit-staging
echo "=== Logs da aplicação staging (últimas 20 linhas) ==="
docker logs convertit-staging --tail 20
echo "=== Teste de conectividade staging ==="
curl -I http://localhost:8080 || echo "Aplicação staging ainda não está acessível"

View File

@ -1,51 +1,50 @@
# Dockerfile self-contained para m<>xima performance # Dockerfile otimizado para multi-arquitetura
FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/aspnet:8.0 AS base ARG TARGETARCH=arm64
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app USER app
WORKDIR /app WORKDIR /app
EXPOSE 8080 EXPOSE 8080
EXPOSE 8081 EXPOSE 8081
FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/sdk:8.0 AS build FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release ARG BUILD_CONFIGURATION=Release
ARG TARGETARCH
WORKDIR /src WORKDIR /src
# Copiar apenas arquivos de projeto primeiro (melhor cache) # Copiar apenas arquivos de projeto primeiro (melhor cache)
COPY ["Convert-It.csproj", "./"] COPY ["Convert-It.csproj", "./"]
# Restore com configura<EFBFBD><EFBFBD>es otimizadas para ARM64 # Restore com cache habilitado
RUN dotnet restore "./Convert-It.csproj" \ RUN dotnet restore "./Convert-It.csproj" \
--runtime linux-arm64 \ --runtime linux-${TARGETARCH}
--no-cache
# Copiar c<EFBFBD>digo fonte # Copiar código fonte
COPY . . COPY . .
WORKDIR "/src" WORKDIR "/src"
# Build otimizado # Build otimizado framework-dependent (mais rápido)
RUN dotnet build "./Convert-It.csproj" \ RUN dotnet build "./Convert-It.csproj" \
-c $BUILD_CONFIGURATION \ -c $BUILD_CONFIGURATION \
-o /app/build \ -o /app/build \
--runtime linux-arm64 \
--no-restore --no-restore
FROM build AS publish FROM build AS publish
ARG BUILD_CONFIGURATION=Release ARG BUILD_CONFIGURATION=Release
ARG TARGETARCH
# Publish self-contained para eliminar cold start # Publish framework-dependent (mais rápido que self-contained)
RUN dotnet publish "./Convert-It.csproj" \ RUN dotnet publish "./Convert-It.csproj" \
-c $BUILD_CONFIGURATION \ -c $BUILD_CONFIGURATION \
-o /app/publish \ -o /app/publish \
--runtime linux-arm64 \ --runtime linux-${TARGETARCH} \
--no-restore \ --no-restore \
--self-contained true \ --self-contained false
/p:PublishTrimmed=true \
/p:PublishSingleFile=false
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0 AS final FROM base AS final
WORKDIR /app WORKDIR /app
COPY --from=publish /app/publish . COPY --from=publish /app/publish .
# Vari<EFBFBD>veis de ambiente otimizadas para produ<64><75>o # Variáveis de ambiente otimizadas para produção
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
ENV DOTNET_USE_POLLING_FILE_WATCHER=true ENV DOTNET_USE_POLLING_FILE_WATCHER=true
ENV ASPNETCORE_ENVIRONMENT=Production ENV ASPNETCORE_ENVIRONMENT=Production
@ -55,4 +54,4 @@ ENV DOTNET_EnableDiagnostics=0
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1 CMD curl -f http://localhost:8080/health || exit 1
ENTRYPOINT ["./Convert-It"] ENTRYPOINT ["dotnet", "Convert-It.dll"]