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