67 lines
2.1 KiB
YAML
67 lines
2.1 KiB
YAML
name: Build and Deploy ASP.NET API
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ] # Apenas quando merge na main
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: localACDC
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup .NET
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: '8.0.x' # ou sua versão
|
|
|
|
- name: Restore dependencies
|
|
run: dotnet restore
|
|
|
|
- name: Build application
|
|
run: dotnet build --configuration Release --no-restore
|
|
|
|
- name: Run tests (opcional)
|
|
run: dotnet test --no-build --verbosity normal
|
|
|
|
- name: Publish application
|
|
run: dotnet publish --configuration Release --output ./publish
|
|
|
|
- name: Build Docker image
|
|
run: |
|
|
docker build -t ytextractor:${{ github.sha }} .
|
|
docker tag ytextractor:${{ github.sha }} registry.redecarneir.us/ytextractor:latest
|
|
docker tag ytextractor:${{ github.sha }} registry.redecarneir.us/ytextractor:${{ github.sha }}
|
|
|
|
- name: Push to registry
|
|
run: |
|
|
docker push registry.redecarneir.us/ytextractor:latest
|
|
docker push registry.redecarneir.us/ytextractor:${{ github.sha }}
|
|
|
|
- name: Deploy to remote VPS
|
|
run: |
|
|
ssh -o StrictHostKeyChecking=no ubuntu@137.131.63.61 << 'EOF'
|
|
# Pull da nova imagem
|
|
docker pull registry.redecarneir.us/ytextractor:latest
|
|
|
|
# Parar container atual se existir
|
|
docker stop ytextractor-api || true
|
|
docker rm ytextractor-api || true
|
|
|
|
# Rodar novo container em produção
|
|
docker run -d \
|
|
--name ytextractor-api \
|
|
--restart unless-stopped \
|
|
-p 5000:8080 \
|
|
-e ASPNETCORE_ENVIRONMENT=Production \
|
|
registry.redecarneir.us/ytextractor:latest
|
|
|
|
# Limpeza de imagens antigas (opcional)
|
|
docker image prune -f
|
|
EOF
|
|
|
|
- name: Verify deployment
|
|
run: |
|
|
ssh ubuntu@137.131.63.61 'docker ps | grep ytextractor-api' |