Some checks failed
Deploy ASP.NET MVC to OCI / build-and-deploy (push) Has been cancelled
127 lines
4.0 KiB
YAML
127 lines
4.0 KiB
YAML
name: Deploy ASP.NET MVC to OCI
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, master ]
|
|
pull_request:
|
|
branches: [ main, master ]
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: localACDC
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Cache Docker layers
|
|
uses: actions/cache@v3
|
|
with:
|
|
path: /tmp/.buildx-cache
|
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
restore-keys: |
|
|
${{ 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
|
|
push: true
|
|
tags: |
|
|
registry.redecarneir.us/convertit:latest
|
|
registry.redecarneir.us/convertit:${{ github.sha }}
|
|
cache-from: |
|
|
type=local,src=/tmp/.buildx-cache
|
|
type=registry,ref=registry.redecarneir.us/convertit:cache
|
|
cache-to: |
|
|
type=local,dest=/tmp/.buildx-cache-new,mode=max
|
|
type=registry,ref=registry.redecarneir.us/convertit:cache,mode=max
|
|
build-args: |
|
|
BUILDKIT_INLINE_CACHE=1
|
|
|
|
- name: Move cache
|
|
run: |
|
|
rm -rf /tmp/.buildx-cache
|
|
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
|
|
|
- name: Deploy to OCI Server
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: 129.146.116.218
|
|
username: ${{ secrets.SSH_USERNAME }}
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
port: 22
|
|
timeout: 60s
|
|
script: |
|
|
# Para o container anterior da aplicação (se existir)
|
|
docker stop convertit || true
|
|
docker rm convertit || true
|
|
|
|
# Remove imagem antiga
|
|
docker rmi registry.redecarneir.us/convertit:latest || true
|
|
|
|
# Puxa nova imagem
|
|
docker pull registry.redecarneir.us/convertit:latest
|
|
|
|
# Executa o novo container na porta 80
|
|
docker run -d \
|
|
--name convertit \
|
|
--restart unless-stopped \
|
|
--add-host="k3ss1:172.17.0.1" \
|
|
--add-host="k3sw2:172.17.0.1" \
|
|
-p 80:8080 \
|
|
--memory=2g \
|
|
--cpus=1.5 \
|
|
--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=Production \
|
|
-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
|
|
|
|
# Limpa imagens não utilizadas
|
|
docker image prune -f
|
|
|
|
# Verifica se o container está rodando
|
|
docker ps | grep convertit
|
|
|
|
# Testa se a aplicação está respondendo na porta 80
|
|
sleep 10
|
|
curl -f http://localhost:80 || echo "Aplicação pode estar inicializando..."
|
|
|
|
- name: Verify deployment
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: 129.146.116.218
|
|
username: ${{ secrets.SSH_USERNAME }}
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
port: 22
|
|
script: |
|
|
echo "=== Status dos containers ==="
|
|
docker ps -a | grep convertit
|
|
|
|
echo "=== Logs da aplicação (últimas 20 linhas) ==="
|
|
docker logs convertit --tail 20
|
|
|
|
echo "=== Teste de conectividade ==="
|
|
curl -I http://localhost:80 || echo "Aplicação ainda não está acessível" |