Mate11 commited on
Commit ·
50f5b55
1
Parent(s): c54762e
AGREGA CD
Browse files- .github/workflows/cd.yml +12 -102
.github/workflows/cd.yml
CHANGED
|
@@ -1,112 +1,22 @@
|
|
| 1 |
-
name:
|
| 2 |
|
| 3 |
on:
|
| 4 |
push:
|
| 5 |
branches: [main]
|
| 6 |
-
|
| 7 |
-
env:
|
| 8 |
-
REGISTRY: ghcr.io
|
| 9 |
-
IMAGE_NAME: ${{ github.repository }}
|
| 10 |
|
| 11 |
jobs:
|
| 12 |
-
# ── 1. Tests deben pasar antes de buildear ──────────────────────────────
|
| 13 |
-
test:
|
| 14 |
-
name: Tests (gate)
|
| 15 |
-
runs-on: ubuntu-latest
|
| 16 |
-
env:
|
| 17 |
-
DATABASE_URL: sqlite:///./test.db
|
| 18 |
-
JWT_SECRET: ci-test-secret-key-not-used-in-production-32chars
|
| 19 |
-
ENVIRONMENT: development
|
| 20 |
-
MOCK_EXTERNAL_SERVICES: "true"
|
| 21 |
-
steps:
|
| 22 |
-
- uses: actions/checkout@v4
|
| 23 |
-
- uses: actions/setup-python@v5
|
| 24 |
-
with:
|
| 25 |
-
python-version: "3.12"
|
| 26 |
-
cache: pip
|
| 27 |
-
- run: pip install -r requirements-dev.txt
|
| 28 |
-
- run: pytest tests/ -v
|
| 29 |
-
|
| 30 |
-
# ── 2. Build y push de la imagen Docker a ghcr.io ──────────────────────
|
| 31 |
-
build-and-push:
|
| 32 |
-
name: Build & Push Docker
|
| 33 |
-
needs: test
|
| 34 |
-
runs-on: ubuntu-latest
|
| 35 |
-
permissions:
|
| 36 |
-
contents: read
|
| 37 |
-
packages: write
|
| 38 |
-
outputs:
|
| 39 |
-
image-tag: ${{ steps.meta.outputs.tags }}
|
| 40 |
-
image-digest: ${{ steps.build.outputs.digest }}
|
| 41 |
-
|
| 42 |
-
steps:
|
| 43 |
-
- uses: actions/checkout@v4
|
| 44 |
-
|
| 45 |
-
- name: Log in to GitHub Container Registry
|
| 46 |
-
uses: docker/login-action@v3
|
| 47 |
-
with:
|
| 48 |
-
registry: ${{ env.REGISTRY }}
|
| 49 |
-
username: ${{ github.actor }}
|
| 50 |
-
password: ${{ secrets.GITHUB_TOKEN }}
|
| 51 |
-
|
| 52 |
-
- name: Extract Docker metadata
|
| 53 |
-
id: meta
|
| 54 |
-
uses: docker/metadata-action@v5
|
| 55 |
-
with:
|
| 56 |
-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
| 57 |
-
tags: |
|
| 58 |
-
type=sha,prefix=sha-
|
| 59 |
-
type=raw,value=latest,enable=true
|
| 60 |
-
|
| 61 |
-
- name: Build and push image
|
| 62 |
-
id: build
|
| 63 |
-
uses: docker/build-push-action@v6
|
| 64 |
-
with:
|
| 65 |
-
context: .
|
| 66 |
-
push: true
|
| 67 |
-
tags: ${{ steps.meta.outputs.tags }}
|
| 68 |
-
labels: ${{ steps.meta.outputs.labels }}
|
| 69 |
-
cache-from: type=gha
|
| 70 |
-
cache-to: type=gha,mode=max
|
| 71 |
-
|
| 72 |
-
# ── 3. Deploy al servidor de producción (requiere secrets configurados) ─
|
| 73 |
-
#
|
| 74 |
-
# Para activar este job:
|
| 75 |
-
# 1. Ir a GitHub → Settings → Variables → New repository variable
|
| 76 |
-
# DEPLOY_ENABLED = true
|
| 77 |
-
# 2. Agregar los siguientes Secrets (Settings → Secrets):
|
| 78 |
-
# DEPLOY_HOST — IP o dominio del servidor
|
| 79 |
-
# DEPLOY_USER — usuario SSH (ej: ubuntu, deploy)
|
| 80 |
-
# DEPLOY_KEY — clave privada SSH (contenido del archivo .pem / id_rsa)
|
| 81 |
-
# 3. En el servidor tener docker + docker compose y el archivo .env en
|
| 82 |
-
# /opt/m6-backend/.env con las variables de producción
|
| 83 |
deploy:
|
| 84 |
-
name: Deploy to Production
|
| 85 |
-
needs: build-and-push
|
| 86 |
runs-on: ubuntu-latest
|
| 87 |
-
environment: production
|
| 88 |
-
if: ${{ vars.DEPLOY_ENABLED == 'true' }}
|
| 89 |
-
|
| 90 |
steps:
|
| 91 |
-
- name:
|
| 92 |
-
uses:
|
| 93 |
with:
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io \
|
| 103 |
-
-u ${{ github.actor }} --password-stdin
|
| 104 |
-
|
| 105 |
-
# Bajar imagen nueva y levantar sin downtime
|
| 106 |
-
docker compose pull backend
|
| 107 |
-
docker compose up -d --no-build --remove-orphans
|
| 108 |
-
|
| 109 |
-
# Limpiar imágenes viejas
|
| 110 |
-
docker image prune -f
|
| 111 |
-
|
| 112 |
-
echo "Deploy completado: $(date)"
|
|
|
|
| 1 |
+
name: Deploy to Hugging Face Spaces
|
| 2 |
|
| 3 |
on:
|
| 4 |
push:
|
| 5 |
branches: [main]
|
| 6 |
+
workflow_dispatch: # permite trigger manual desde la UI de GitHub
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
jobs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
deploy:
|
|
|
|
|
|
|
| 10 |
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
|
|
| 11 |
steps:
|
| 12 |
+
- name: Checkout
|
| 13 |
+
uses: actions/checkout@v4
|
| 14 |
with:
|
| 15 |
+
fetch-depth: 0 # importante: trae todo el historial, no shallow
|
| 16 |
+
lfs: true # por si usás Git LFS
|
| 17 |
+
|
| 18 |
+
- name: Push to Hugging Face Space
|
| 19 |
+
env:
|
| 20 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 21 |
+
run: |
|
| 22 |
+
git push https://MateFerreyra:$HF_TOKEN@huggingface.co/spaces/MateFerreyra/Modulo-6 main --force
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|