feat: deploy to production
This commit is contained in:
parent
c2c89af91b
commit
afd1b53354
187
.github/workflows/deploy.yml
vendored
187
.github/workflows/deploy.yml
vendored
@ -1,5 +1,4 @@
|
|||||||
name: Deploy QR Rapido
|
name: Deploy QR Rapido
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main, develop ]
|
branches: [ main, develop ]
|
||||||
@ -7,8 +6,8 @@ on:
|
|||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: ghcr.io
|
REGISTRY: registry.redecarneir.us
|
||||||
IMAGE_NAME: ${{ github.repository }}
|
IMAGE_NAME: qrrapido
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@ -47,43 +46,31 @@ jobs:
|
|||||||
build-and-push:
|
build-and-push:
|
||||||
needs: test
|
needs: test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
packages: write
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Login to Container Registry
|
- name: Set up Docker Buildx
|
||||||
uses: docker/login-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
with:
|
|
||||||
registry: ${{ env.REGISTRY }}
|
- name: Build and push to registry
|
||||||
username: ${{ github.actor }}
|
run: |
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
# Determina a tag baseada na branch
|
||||||
|
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
|
||||||
|
TAG="latest"
|
||||||
|
else
|
||||||
|
TAG="develop"
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Extract metadata
|
# Build da imagem
|
||||||
id: meta
|
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$TAG .
|
||||||
uses: docker/metadata-action@v5
|
|
||||||
with:
|
# Push para o registry (sem autenticação conforme mencionado)
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$TAG
|
||||||
tags: |
|
|
||||||
type=ref,event=branch
|
echo "IMAGE_TAG=$TAG" >> $GITHUB_ENV
|
||||||
type=ref,event=pr
|
|
||||||
type=sha,prefix={{branch}}-
|
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v5
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
push: true
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
cache-from: type=gha
|
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
|
|
||||||
deploy-staging:
|
deploy-staging:
|
||||||
needs: build-and-push
|
needs: build-and-push
|
||||||
@ -91,12 +78,54 @@ jobs:
|
|||||||
if: github.ref == 'refs/heads/develop'
|
if: github.ref == 'refs/heads/develop'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Deploy to Staging
|
- name: Deploy to Staging Servers
|
||||||
uses: azure/webapps-deploy@v2
|
run: |
|
||||||
with:
|
# Configura SSH known_hosts
|
||||||
app-name: 'qrrapido-staging'
|
mkdir -p ~/.ssh
|
||||||
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_STAGING }}
|
ssh-keyscan -H 141.148.162.114 >> ~/.ssh/known_hosts
|
||||||
images: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop'
|
ssh-keyscan -H 129.146.116.218 >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
# Deploy no Servidor 1
|
||||||
|
ssh ubuntu@141.148.162.114 << 'EOF'
|
||||||
|
# Para o container atual se existir
|
||||||
|
docker stop qrrapido-staging || true
|
||||||
|
docker rm qrrapido-staging || true
|
||||||
|
|
||||||
|
# Remove imagem antiga
|
||||||
|
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop || true
|
||||||
|
|
||||||
|
# Puxa nova imagem
|
||||||
|
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop
|
||||||
|
|
||||||
|
# Executa novo container
|
||||||
|
docker run -d \
|
||||||
|
--name qrrapido-staging \
|
||||||
|
--restart unless-stopped \
|
||||||
|
-p 5000:8080 \
|
||||||
|
-e ASPNETCORE_ENVIRONMENT=Staging \
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Deploy no Servidor 2
|
||||||
|
ssh ubuntu@129.146.116.218 << 'EOF'
|
||||||
|
# Para o container atual se existir
|
||||||
|
docker stop qrrapido-staging || true
|
||||||
|
docker rm qrrapido-staging || true
|
||||||
|
|
||||||
|
# Remove imagem antiga
|
||||||
|
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop || true
|
||||||
|
|
||||||
|
# Puxa nova imagem
|
||||||
|
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop
|
||||||
|
|
||||||
|
# Executa novo container
|
||||||
|
docker run -d \
|
||||||
|
--name qrrapido-staging \
|
||||||
|
--restart unless-stopped \
|
||||||
|
-p 5000:8080 \
|
||||||
|
-e ASPNETCORE_ENVIRONMENT=Staging \
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:develop
|
||||||
|
EOF
|
||||||
|
|
||||||
deploy-production:
|
deploy-production:
|
||||||
needs: build-and-push
|
needs: build-and-push
|
||||||
@ -105,17 +134,69 @@ jobs:
|
|||||||
environment: production
|
environment: production
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Deploy to Production
|
- name: Deploy to Production Servers
|
||||||
uses: azure/webapps-deploy@v2
|
run: |
|
||||||
with:
|
# Configura SSH known_hosts
|
||||||
app-name: 'qrrapido-production'
|
mkdir -p ~/.ssh
|
||||||
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE_PROD }}
|
ssh-keyscan -H 141.148.162.114 >> ~/.ssh/known_hosts
|
||||||
images: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest'
|
ssh-keyscan -H 129.146.116.218 >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
- name: Notify Slack
|
# Deploy no Servidor 1 (com NGINX)
|
||||||
uses: 8398a7/action-slack@v3
|
ssh ubuntu@141.148.162.114 << 'EOF'
|
||||||
with:
|
# Para o container atual se existir
|
||||||
status: ${{ job.status }}
|
docker stop qrrapido-prod || true
|
||||||
channel: '#deployments'
|
docker rm qrrapido-prod || true
|
||||||
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
|
|
||||||
text: "QR Rapido deployed to production! 🚀"
|
# Remove imagem antiga
|
||||||
|
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest || true
|
||||||
|
|
||||||
|
# Puxa nova imagem
|
||||||
|
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||||
|
|
||||||
|
# Executa novo container
|
||||||
|
docker run -d \
|
||||||
|
--name qrrapido-prod \
|
||||||
|
--restart unless-stopped \
|
||||||
|
-p 5001:8080 \
|
||||||
|
-e ASPNETCORE_ENVIRONMENT=Production \
|
||||||
|
-e ASPNETCORE_URLS=http://+:8080 \
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||||
|
|
||||||
|
# Recarrega NGINX para garantir que está apontando para o novo container
|
||||||
|
sudo nginx -t && sudo systemctl reload nginx
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Deploy no Servidor 2
|
||||||
|
ssh ubuntu@129.146.116.218 << 'EOF'
|
||||||
|
# Para o container atual se existir
|
||||||
|
docker stop qrrapido-prod || true
|
||||||
|
docker rm qrrapido-prod || true
|
||||||
|
|
||||||
|
# Remove imagem antiga
|
||||||
|
docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest || true
|
||||||
|
|
||||||
|
# Puxa nova imagem
|
||||||
|
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||||
|
|
||||||
|
# Executa novo container
|
||||||
|
docker run -d \
|
||||||
|
--name qrrapido-prod \
|
||||||
|
--restart unless-stopped \
|
||||||
|
-p 5001:8080 \
|
||||||
|
-e ASPNETCORE_ENVIRONMENT=Production \
|
||||||
|
-e ASPNETCORE_URLS=http://+:8080 \
|
||||||
|
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Health Check
|
||||||
|
run: |
|
||||||
|
# Aguarda um pouco para os containers subirem
|
||||||
|
sleep 30
|
||||||
|
|
||||||
|
# Verifica se os serviços estão respondendo
|
||||||
|
echo "Verificando Servidor 1..."
|
||||||
|
ssh ubuntu@141.148.162.114 'curl -f http://localhost:5001/health || echo "Servidor 1 pode não estar respondendo"'
|
||||||
|
|
||||||
|
echo "Verificando Servidor 2..."
|
||||||
|
ssh ubuntu@129.146.116.218 'curl -f http://localhost:5001/health || echo "Servidor 2 pode não estar respondendo"'
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,15 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.13.35818.85 d17.13
|
VisualStudioVersion = 17.13.35818.85
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRRapidoApp", "QRRapidoApp.csproj", "{8AF92774-40E8-830E-08B3-67F0A0B91DDE}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QRRapidoApp", "QRRapidoApp.csproj", "{8AF92774-40E8-830E-08B3-67F0A0B91DDE}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RootFolder", "RootFolder", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
.github\workflows\deploy.yml = .github\workflows\deploy.yml
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user