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/
.git/
.gitea/
.gitignore
*.md
README.md
CLAUDE.md
tests/
docs/
.vs/
.vscode/
**/.DS_Store
**/Thumbs.db
**/node_modules/
**/*.log
**/*.tmp
**/temp/
**/*.bak
Properties/launchSettings.json
*.user
*.suo
*.cache
.env
.env.*
!.env.example

View File

@ -1,8 +1,8 @@
name: Deploy ASP.NET MVC to OCI
name: Deploy ASP.NET MVC to OCI
on:
push:
branches: [ main, master ]
branches: [ main, master, 'release/*' ]
pull_request:
branches: [ main, master ]
@ -17,48 +17,62 @@ jobs:
- name: Set up Docker Buildx
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
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
key: ${{ runner.os }}-buildx-${{ steps.vars.outputs.TARGET_ARCH }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ steps.vars.outputs.TARGET_ARCH }}-
${{ 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
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/arm64
platforms: ${{ steps.vars.outputs.PLATFORM }}
push: true
tags: |
registry.redecarneir.us/convertit:latest
registry.redecarneir.us/convertit:${{ github.sha }}
registry.redecarneir.us/convertit:latest${{ steps.vars.outputs.TAG_SUFFIX }}
registry.redecarneir.us/convertit:${{ github.sha }}${{ steps.vars.outputs.TAG_SUFFIX }}
cache-from: |
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: |
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: |
BUILDKIT_INLINE_CACHE=1
TARGETARCH=${{ steps.vars.outputs.TARGET_ARCH }}
- name: Move cache
run: |
rm -rf /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
with:
host: 129.146.116.218
@ -74,7 +88,7 @@ jobs:
# Remove imagem antiga
docker rmi registry.redecarneir.us/convertit:latest || true
# Puxa nova imagem
# Puxa nova imagem ARM64
docker pull registry.redecarneir.us/convertit:latest
# Executa o novo container na porta 80
@ -109,7 +123,58 @@ jobs:
sleep 10
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
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
uses: appleboy/ssh-action@v1.0.3
with:
host: 129.146.116.218
@ -125,3 +190,21 @@ jobs:
echo "=== Teste de conectividade ==="
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
FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/aspnet:8.0 AS base
# Dockerfile otimizado para multi-arquitetura
ARG TARGETARCH=arm64
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
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 TARGETARCH
WORKDIR /src
# Copiar apenas arquivos de projeto primeiro (melhor cache)
COPY ["Convert-It.csproj", "./"]
# Restore com configura<EFBFBD><EFBFBD>es otimizadas para ARM64
# Restore com cache habilitado
RUN dotnet restore "./Convert-It.csproj" \
--runtime linux-arm64 \
--no-cache
--runtime linux-${TARGETARCH}
# Copiar c<EFBFBD>digo fonte
# Copiar código fonte
COPY . .
WORKDIR "/src"
# Build otimizado
# Build otimizado framework-dependent (mais rápido)
RUN dotnet build "./Convert-It.csproj" \
-c $BUILD_CONFIGURATION \
-o /app/build \
--runtime linux-arm64 \
--no-restore
FROM build AS publish
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" \
-c $BUILD_CONFIGURATION \
-o /app/publish \
--runtime linux-arm64 \
--runtime linux-${TARGETARCH} \
--no-restore \
--self-contained true \
/p:PublishTrimmed=true \
/p:PublishSingleFile=false
--self-contained false
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0 AS final
FROM base AS final
WORKDIR /app
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_USE_POLLING_FILE_WATCHER=true
ENV ASPNETCORE_ENVIRONMENT=Production
@ -55,4 +54,4 @@ ENV DOTNET_EnableDiagnostics=0
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
ENTRYPOINT ["./Convert-It"]
ENTRYPOINT ["dotnet", "Convert-It.dll"]