Skip to content

feat: add relabeling rules for host and container metrics in Alloy co… #15

feat: add relabeling rules for host and container metrics in Alloy co…

feat: add relabeling rules for host and container metrics in Alloy co… #15

Workflow file for this run

name: Deploy to VPS
on:
push:
branches:
- main
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
jobs:
# ─── Build e push das imagens ─────────────────────────────────────────────────
build:
name: Build & Push Docker images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build & push — web (Next.js)
uses: docker/build-push-action@v5
with:
context: ./apps/web
file: ./apps/web/Dockerfile
push: true
tags: |
${{ env.IMAGE_PREFIX }}/web:latest
${{ env.IMAGE_PREFIX }}/web:${{ github.sha }}
cache-from: type=gha,scope=web
cache-to: type=gha,mode=max,scope=web
- name: Build & push — backend (NestJS)
uses: docker/build-push-action@v5
with:
context: ./apps/backend
file: ./apps/backend/Dockerfile
push: true
tags: |
${{ env.IMAGE_PREFIX }}/backend:latest
${{ env.IMAGE_PREFIX }}/backend:${{ github.sha }}
cache-from: type=gha,scope=backend
cache-to: type=gha,mode=max,scope=backend
# ─── Deploy na VPS ────────────────────────────────────────────────────────────
deploy:
name: Deploy to VPS
runs-on: ubuntu-latest
needs: build
environment: production
steps:
- name: Checkout (para copiar arquivos de infra)
uses: actions/checkout@v4
- name: Copy infra files to VPS
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
source: "docker-compose.yml,docker-compose.prod.yml,infra/"
target: "/opt/condominio"
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
script: |
set -e
cd /opt/condominio
# Login no GHCR para pull das imagens
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
# Exporta variáveis de ambiente necessárias para o Compose
export GITHUB_REPOSITORY="${{ github.repository }}"
export IMAGE_TAG="${{ github.sha }}"
# Pull das novas imagens e reinicia apenas os serviços afetados
docker compose -f docker-compose.yml -f docker-compose.prod.yml pull web backend
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --no-build --remove-orphans
# Remove imagens antigas (economiza espaço em disco)
docker image prune -f