chore: simplify deploy workflow to pull-only with podman

This commit is contained in:
Tiago Yamamoto 2025-12-29 10:23:32 -03:00
parent 1058b7005f
commit 8ba5e9e8e0

View file

@ -10,44 +10,13 @@ on:
- 'frontend/**'
env:
REGISTRY: rg.fr-par.scw.cloud
NAMESPACE: gohorsejobs
REGISTRY: rg.fr-par.scw.cloud/funcscwinfrastructureascodehdz4uzhb
NAMESPACE: a5034510-9763-40e8-ac7e-1836e7a61460
jobs:
# Job 1: Testes do Backend (Padrão GoHorse)
test-backend:
# Job: Deploy no Servidor (Pull das imagens do Scaleway)
deploy-dev:
runs-on: docker
if: contains(github.event.head_commit.modified, 'backend/') || contains(github.event.head_commit.added, 'backend/')
steps:
- name: Checkout code
uses: https://github.com/actions/checkout@v4
- name: Setup Go
uses: https://github.com/actions/setup-go@v5
with:
go-version: '1.24'
cache-dependency-path: backend/go.sum
- name: Install dependencies
run: |
cd backend
go mod download
- name: Run tests
run: |
cd backend
go test -v ./internal/services/...
go test -v ./internal/core/usecases/...
# Job 2: Build e Push das Imagens para Scaleway Registry
build-and-push:
runs-on: docker
needs: [test-backend]
if: always() && (needs.test-backend.result == 'success' || needs.test-backend.result == 'skipped')
outputs:
backend_updated: ${{ steps.check.outputs.backend }}
frontend_updated: ${{ steps.check.outputs.frontend }}
backoffice_updated: ${{ steps.check.outputs.backoffice }}
steps:
- name: Checkout code
uses: https://github.com/actions/checkout@v4
@ -73,48 +42,6 @@ jobs:
echo "backoffice=false" >> $GITHUB_OUTPUT
fi
- name: Login to Scaleway Registry
run: |
echo "${{ secrets.SCW_SECRET_KEY }}" | docker login ${{ env.REGISTRY }} -u nologin --password-stdin
- name: Build and Push Backend
if: steps.check.outputs.backend == 'true'
run: |
docker build -t ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backend:dev-${{ github.sha }} \
-t ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backend:dev-latest \
./backend
docker push ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backend:dev-${{ github.sha }}
docker push ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backend:dev-latest
- name: Build and Push Frontend
if: steps.check.outputs.frontend == 'true'
run: |
docker build \
--build-arg NODE_OPTIONS="--max-old-space-size=2048" \
--build-arg NEXT_PUBLIC_API_URL="${{ secrets.API_URL }}" \
--build-arg NEXT_PUBLIC_BACKOFFICE_URL="${{ secrets.BACKOFFICE_URL }}" \
-t ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/frontend:dev-${{ github.sha }} \
-t ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/frontend:dev-latest \
./frontend
docker push ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/frontend:dev-${{ github.sha }}
docker push ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/frontend:dev-latest
- name: Build and Push Backoffice
if: steps.check.outputs.backoffice == 'true'
run: |
docker build \
-t ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backoffice:dev-${{ github.sha }} \
-t ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backoffice:dev-latest \
./backoffice
docker push ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backoffice:dev-${{ github.sha }}
docker push ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backoffice:dev-latest
# Job 3: Deploy no Servidor (Pull das imagens do Scaleway)
deploy-dev:
runs-on: docker
needs: [build-and-push]
if: always() && needs.build-and-push.result == 'success'
steps:
- name: Deploy via SSH
uses: https://github.com/appleboy/ssh-action@v1.0.3
with:
@ -127,7 +54,7 @@ jobs:
echo "${{ secrets.SCW_SECRET_KEY }}" | podman login ${{ env.REGISTRY }} -u nologin --password-stdin
# --- DEPLOY DO BACKEND ---
if [ "${{ needs.build-and-push.outputs.backend_updated }}" == "true" ]; then
if [ "${{ steps.check.outputs.backend }}" == "true" ]; then
echo "Pulling e reiniciando Backend..."
podman pull ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backend:dev-latest
podman tag ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backend:dev-latest localhost/gohorsejobs-backend-dev:latest
@ -135,7 +62,7 @@ jobs:
fi
# --- DEPLOY DO FRONTEND ---
if [ "${{ needs.build-and-push.outputs.frontend_updated }}" == "true" ]; then
if [ "${{ steps.check.outputs.frontend }}" == "true" ]; then
echo "Pulling e reiniciando Frontend..."
podman pull ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/frontend:dev-latest
podman tag ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/frontend:dev-latest localhost/gohorsejobs-frontend-dev:latest
@ -143,7 +70,7 @@ jobs:
fi
# --- DEPLOY DO BACKOFFICE ---
if [ "${{ needs.build-and-push.outputs.backoffice_updated }}" == "true" ]; then
if [ "${{ steps.check.outputs.backoffice }}" == "true" ]; then
echo "Pulling e reiniciando Backoffice..."
podman pull ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backoffice:dev-latest
podman tag ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/backoffice:dev-latest localhost/gohorsejobs-backoffice-dev:latest