Skip to content

UPD - CICD (#11)

UPD - CICD (#11) #2

Workflow file for this run

name: "PROD - CI/CD"
on:
push:
tags:
- 'v*.*.*' # Se déclenche sur les tags de version (ex: v1.0.0, v2.1.3)
jobs:
# 1️⃣ Build & tests
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 9
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Generate Prisma Client
run: pnpm prisma generate
- name: Skip tests (no test script defined)
run: echo "⚠️ Aucun test défini, étape ignorée."
- name: Build app
run: pnpm build
# 2️⃣ Build & push Docker image
docker-build-push:
runs-on: ubuntu-latest
needs: build-and-test
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=long
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
NEXT_PUBLIC_ENV=production
# 3️⃣ Deploy PROD
deploy-prod:
runs-on: self-hosted
needs: docker-build-push
steps:
- name: Clean workspace
run: rm -rf *
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull new image + restart PROD stack
run: |
echo "🔧 Deploying on PROD..."
cd /home/baptiste/Dev/WPT/prod
docker-compose pull
docker rm -f wpt_website || true
docker-compose up -d --no-deps wpt_website
docker-compose up -d --remove-orphans
echo "🚀 Deployed in PROD!"