- Monorepo backend/ + frontend/ + deploy/ - Backend FastAPI/SQLModel/Alembic/uv qui démarre (health check, config, i18n, base de test PostgreSQL, pytest) - docker-compose de développement (db + backend hot-reload) - Chaîne CI/CD GitHub Actions : lint + tests, build image, push GHCR, déploiement SSH sur le VPS à chaque push main - CLAUDE.md : vocabulaire du domaine, conventions, commandes Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017uUsRg7XzopkCPWimwg9ZM
102 lines
3.0 KiB
YAML
102 lines
3.0 KiB
YAML
name: Déploiement production
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
concurrency:
|
|
group: deploy-production
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
env:
|
|
POSTGRES_USER: benevoles
|
|
POSTGRES_PASSWORD: benevoles
|
|
POSTGRES_DB: benevoles_test
|
|
ports:
|
|
- 5432:5432
|
|
options: >-
|
|
--health-cmd "pg_isready -U benevoles"
|
|
--health-interval 5s --health-timeout 5s --health-retries 10
|
|
env:
|
|
TEST_DATABASE_URL: postgresql+psycopg://benevoles:benevoles@localhost:5432/benevoles_test
|
|
DATABASE_URL: postgresql+psycopg://benevoles:benevoles@localhost:5432/benevoles_test
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: astral-sh/setup-uv@v5
|
|
with:
|
|
version: "0.5.11"
|
|
- name: Installer les dépendances
|
|
working-directory: backend
|
|
run: uv sync
|
|
- name: Lint
|
|
working-directory: backend
|
|
run: uv run ruff check .
|
|
- name: Tests
|
|
working-directory: backend
|
|
run: uv run pytest
|
|
|
|
build:
|
|
needs: test
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: docker/setup-buildx-action@v3
|
|
- uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
- id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: ghcr.io/${{ github.repository }}-backend
|
|
tags: |
|
|
type=raw,value=latest
|
|
type=sha,prefix=sha-
|
|
- uses: docker/build-push-action@v6
|
|
with:
|
|
context: ./backend
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
deploy:
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Copier la configuration de déploiement
|
|
uses: appleboy/scp-action@v0.1.7
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: ${{ secrets.SSH_USER }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
source: deploy/docker-compose.prod.yml
|
|
target: ${{ secrets.DEPLOY_PATH }}
|
|
strip_components: 1
|
|
- name: Redéployer
|
|
uses: appleboy/ssh-action@v1.2.0
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: ${{ secrets.SSH_USER }}
|
|
key: ${{ secrets.SSH_KEY }}
|
|
script: |
|
|
set -e
|
|
cd "${{ secrets.DEPLOY_PATH }}"
|
|
export BACKEND_IMAGE="ghcr.io/${{ github.repository }}-backend:sha-${{ github.sha }}"
|
|
echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
|
|
docker compose -f docker-compose.prod.yml pull
|
|
docker compose -f docker-compose.prod.yml up -d
|
|
docker image prune -f
|