build: update cicd
This commit is contained in:
32
.env.registry.example
Normal file
32
.env.registry.example
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Configuration du Registre Docker pour docker-compose.prod.yml
|
||||||
|
# Copiez ce fichier en .env et ajustez les valeurs
|
||||||
|
|
||||||
|
# URL du registre Docker (sans https://)
|
||||||
|
# Exemples:
|
||||||
|
# - Docker Hub: docker.io
|
||||||
|
# - GitHub: ghcr.io
|
||||||
|
# - GitLab: registry.gitlab.com
|
||||||
|
# - Gitea: git.example.com
|
||||||
|
# - Harbor: harbor.example.com
|
||||||
|
REGISTRY_URL=registry.example.com
|
||||||
|
|
||||||
|
# Namespace/Organisation dans le registre
|
||||||
|
# Exemples:
|
||||||
|
# - Docker Hub: votre-username
|
||||||
|
# - GitHub: votre-username ou organisation
|
||||||
|
# - GitLab: votre-username/projet
|
||||||
|
# - Gitea: votre-username
|
||||||
|
REGISTRY_NAMESPACE=myorganization
|
||||||
|
|
||||||
|
# Tag de l'image à utiliser
|
||||||
|
# Options:
|
||||||
|
# - latest (dernière version)
|
||||||
|
# - v2.0.0 (version spécifique)
|
||||||
|
# - rewrite (branche spécifique)
|
||||||
|
# - main-abc123 (commit SHA)
|
||||||
|
IMAGE_TAG=latest
|
||||||
|
|
||||||
|
# Note: Pour utiliser ces variables avec docker-compose.prod.yml:
|
||||||
|
# 1. Copiez ce fichier: cp .env.registry.example .env
|
||||||
|
# 2. Éditez .env avec vos valeurs
|
||||||
|
# 3. Lancez: docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
||||||
@@ -10,10 +10,11 @@ on:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: ${{ secrets.REGISTRY_URL }}
|
REGISTRY: ${{ secrets.REGISTRY_URL }}
|
||||||
NAMESPACE: ${{ secrets.REGISTRY_NAMESPACE || 'notytex' }}
|
NAMESPACE: ${{ secrets.REGISTRY_NAMESPACE || 'lafrite' }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-backend:
|
||||||
|
name: Build Backend Image
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
@@ -29,31 +30,108 @@ jobs:
|
|||||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
- name: Extract metadata
|
- name: Extract metadata for backend
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ${{ env.REGISTRY }}/lafrite/notytex
|
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/notytex-backend
|
||||||
tags: |
|
tags: |
|
||||||
type=ref,event=branch,enable={{is_not_default_branch}}
|
type=ref,event=branch
|
||||||
# type=ref,event=pr
|
|
||||||
type=ref,event=tag
|
type=ref,event=tag
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
# type=sha,prefix={{branch}}-,suffix=-{{date 'YYYYMMDD-HHmmss'}},enable={{is_default_branch}}
|
type=sha,prefix={{branch}}-
|
||||||
labels: |
|
labels: |
|
||||||
org.opencontainers.image.source=https://${{ env.REGISTRY }}/lafrite/notytex
|
org.opencontainers.image.title=Notytex Backend
|
||||||
|
org.opencontainers.image.description=FastAPI backend for Notytex school management system
|
||||||
|
org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}
|
||||||
|
org.opencontainers.image.version=${{ gitea.ref_name }}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push backend image
|
||||||
id: build
|
id: build-backend
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: ./backend
|
||||||
dockerfile: Dockerfile
|
file: ./backend/Dockerfile
|
||||||
registry: ${{ env.REGISTRY }}
|
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64,linux/arm64
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
- name: Image digest
|
- name: Backend image digest
|
||||||
run: echo "Image pushed with digest ${{ steps.build.outputs.digest }}"
|
run: |
|
||||||
|
echo "Backend image pushed with digest: ${{ steps.build-backend.outputs.digest }}"
|
||||||
|
echo "Tags: ${{ steps.meta.outputs.tags }}"
|
||||||
|
|
||||||
|
build-frontend:
|
||||||
|
name: Build Frontend Image
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to Docker Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Extract metadata for frontend
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/notytex-frontend
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=tag
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
type=sha,prefix={{branch}}-
|
||||||
|
labels: |
|
||||||
|
org.opencontainers.image.title=Notytex Frontend
|
||||||
|
org.opencontainers.image.description=Vue.js frontend for Notytex school management system
|
||||||
|
org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}
|
||||||
|
org.opencontainers.image.version=${{ gitea.ref_name }}
|
||||||
|
|
||||||
|
- name: Build and push frontend image
|
||||||
|
id: build-frontend
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: ./frontend
|
||||||
|
file: ./frontend/Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
- name: Frontend image digest
|
||||||
|
run: |
|
||||||
|
echo "Frontend image pushed with digest: ${{ steps.build-frontend.outputs.digest }}"
|
||||||
|
echo "Tags: ${{ steps.meta.outputs.tags }}"
|
||||||
|
|
||||||
|
summary:
|
||||||
|
name: Build Summary
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [build-backend, build-frontend]
|
||||||
|
if: always()
|
||||||
|
steps:
|
||||||
|
- name: Build summary
|
||||||
|
run: |
|
||||||
|
echo "## 🐳 Docker Images Built Successfully"
|
||||||
|
echo ""
|
||||||
|
echo "### Backend Image"
|
||||||
|
echo "- Registry: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/notytex-backend"
|
||||||
|
echo "- Tags: latest, ${{ gitea.ref_name }}"
|
||||||
|
echo ""
|
||||||
|
echo "### Frontend Image"
|
||||||
|
echo "- Registry: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/notytex-frontend"
|
||||||
|
echo "- Tags: latest, ${{ gitea.ref_name }}"
|
||||||
|
echo ""
|
||||||
|
echo "### 🚀 Deployment"
|
||||||
|
echo "docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d"
|
||||||
|
|||||||
128
DOCKER.md
128
DOCKER.md
@@ -8,8 +8,11 @@ Guide complet pour déployer Notytex avec Docker et Docker Compose.
|
|||||||
|
|
||||||
### Prérequis
|
### Prérequis
|
||||||
|
|
||||||
- Docker 24.0+ (ou Docker Desktop 4.20+)
|
- **Docker** : 24.0+ (ou Docker Desktop 4.20+)
|
||||||
- Docker Compose 2.20+
|
- **Docker Compose** : 2.20+
|
||||||
|
- **Alternative Podman** : Podman 4.0+ avec podman-compose
|
||||||
|
|
||||||
|
> 💡 **Note Podman** : Les Dockerfiles utilisent des images Docker Hub qualifiées (`docker.io/library/*`) pour compatibilité Podman
|
||||||
|
|
||||||
### Installation en 3 commandes
|
### Installation en 3 commandes
|
||||||
|
|
||||||
@@ -92,6 +95,44 @@ python -c "import secrets; print(secrets.token_hex(32))"
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 🐋 Utilisation avec Podman
|
||||||
|
|
||||||
|
### Pourquoi Podman ?
|
||||||
|
|
||||||
|
- **Sans privilèges root** : Exécution en mode utilisateur (rootless)
|
||||||
|
- **Compatible Docker** : Même syntaxe que docker-compose
|
||||||
|
- **Plus sécurisé** : Pas de daemon en arrière-plan
|
||||||
|
|
||||||
|
### Installation Podman
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Debian/Ubuntu
|
||||||
|
sudo apt install podman podman-compose
|
||||||
|
|
||||||
|
# Fedora/RHEL
|
||||||
|
sudo dnf install podman podman-compose
|
||||||
|
|
||||||
|
# Arch Linux
|
||||||
|
sudo pacman -S podman podman-compose
|
||||||
|
```
|
||||||
|
|
||||||
|
### Commandes Podman
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Remplacer 'docker-compose' par 'podman-compose'
|
||||||
|
podman-compose up -d
|
||||||
|
podman-compose logs -f
|
||||||
|
podman-compose down
|
||||||
|
|
||||||
|
# Ou utiliser l'alias podman (compatible Docker CLI)
|
||||||
|
alias docker=podman
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
> ✅ **Les Dockerfiles sont configurés avec des images qualifiées** (`docker.io/library/*`) pour éviter les erreurs de registre
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 🛠️ Commandes Docker
|
## 🛠️ Commandes Docker
|
||||||
|
|
||||||
### Démarrage
|
### Démarrage
|
||||||
@@ -377,20 +418,93 @@ docker-compose up -d --build
|
|||||||
|
|
||||||
## 📦 Multi-environnements
|
## 📦 Multi-environnements
|
||||||
|
|
||||||
### Développement
|
### Développement (Build Local)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Utiliser docker-compose.dev.yml
|
# Build et exécution locale (par défaut)
|
||||||
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
|
docker-compose up -d --build
|
||||||
|
|
||||||
|
# Avec Podman
|
||||||
|
podman-compose up -d --build
|
||||||
```
|
```
|
||||||
|
|
||||||
### Production
|
### Production (Images du Registre)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Utiliser docker-compose.prod.yml
|
# Configurer les variables d'environnement pour votre registre
|
||||||
|
export REGISTRY_URL=registry.example.com # Votre registre Docker
|
||||||
|
export REGISTRY_NAMESPACE=myorganization # Votre namespace/organisation
|
||||||
|
export IMAGE_TAG=latest # Ou version spécifique (v2.0.0)
|
||||||
|
|
||||||
|
# Démarrer avec les images du registre
|
||||||
|
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
||||||
|
|
||||||
|
# Ou avec Podman
|
||||||
|
podman-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
**Exemples de registres** :
|
||||||
|
- **Gitea** : `registry.example.com/namespace/notytex-backend:latest`
|
||||||
|
- **GitHub** : `ghcr.io/username/notytex-backend:latest`
|
||||||
|
- **Docker Hub** : `docker.io/username/notytex-backend:latest`
|
||||||
|
- **GitLab** : `registry.gitlab.com/username/notytex-backend:latest`
|
||||||
|
|
||||||
|
> 💡 Les images peuvent être construites automatiquement par CI/CD (Gitea Actions, GitHub Actions, GitLab CI)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔄 CI/CD - Images du Registre
|
||||||
|
|
||||||
|
### Configuration CI/CD
|
||||||
|
|
||||||
|
Le fichier `.gitea/workflows/docker-publish.yml` configure la construction automatique des images Docker.
|
||||||
|
|
||||||
|
**Déclencheurs** :
|
||||||
|
- Push sur `main` ou `rewrite`
|
||||||
|
- Tags `v*` (releases)
|
||||||
|
- Déclenchement manuel
|
||||||
|
|
||||||
|
**Variables requises (Secrets Gitea/GitHub)** :
|
||||||
|
- `REGISTRY_URL` - URL de votre registre Docker
|
||||||
|
- `REGISTRY_NAMESPACE` - Namespace/organisation (optionnel, défaut: `lafrite`)
|
||||||
|
- `REGISTRY_USERNAME` - Nom d'utilisateur pour le registre
|
||||||
|
- `REGISTRY_PASSWORD` - Mot de passe ou token pour le registre
|
||||||
|
|
||||||
|
**Artefacts produits** :
|
||||||
|
- `<registry>/<namespace>/notytex-backend:latest`
|
||||||
|
- `<registry>/<namespace>/notytex-backend:<branch>`
|
||||||
|
- `<registry>/<namespace>/notytex-frontend:latest`
|
||||||
|
- `<registry>/<namespace>/notytex-frontend:<branch>`
|
||||||
|
|
||||||
|
### Utiliser les images du registre
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Se connecter au registre (si privé)
|
||||||
|
docker login <REGISTRY_URL>
|
||||||
|
# Ou avec Podman
|
||||||
|
podman login <REGISTRY_URL>
|
||||||
|
|
||||||
|
# 2. Pull des images
|
||||||
|
docker pull <REGISTRY_URL>/<NAMESPACE>/notytex-backend:latest
|
||||||
|
docker pull <REGISTRY_URL>/<NAMESPACE>/notytex-frontend:latest
|
||||||
|
|
||||||
|
# 3. Configurer les variables
|
||||||
|
export REGISTRY_URL=registry.example.com
|
||||||
|
export REGISTRY_NAMESPACE=myorg
|
||||||
|
export IMAGE_TAG=latest
|
||||||
|
|
||||||
|
# 4. Démarrer avec docker-compose.prod.yml
|
||||||
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Avantages des images pré-construites
|
||||||
|
|
||||||
|
✅ **Déploiement rapide** : Pas de compilation sur le serveur
|
||||||
|
✅ **Reproductibilité** : Même image en dev/staging/prod
|
||||||
|
✅ **Multi-architecture** : Support AMD64 et ARM64
|
||||||
|
✅ **Cache optimisé** : Build incrémental via GitHub Actions cache
|
||||||
|
✅ **Versioning** : Tags par branche et version
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🎯 Performances
|
## 🎯 Performances
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Dockerfile pour Backend FastAPI
|
# Dockerfile pour Backend FastAPI
|
||||||
FROM python:3.12-slim
|
FROM docker.io/library/python:3.12-slim
|
||||||
|
|
||||||
# Variables d'environnement
|
# Variables d'environnement
|
||||||
ENV PYTHONUNBUFFERED=1 \
|
ENV PYTHONUNBUFFERED=1 \
|
||||||
|
|||||||
24
docker-compose.prod.yml
Normal file
24
docker-compose.prod.yml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Docker Compose pour Production avec images du registre
|
||||||
|
# Usage: docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
||||||
|
#
|
||||||
|
# Variables d'environnement requises:
|
||||||
|
# REGISTRY_URL - URL de votre registre Docker (ex: registry.example.com, ghcr.io, docker.io)
|
||||||
|
# REGISTRY_NAMESPACE - Namespace/organisation (ex: notytex, username)
|
||||||
|
# IMAGE_TAG - Tag de l'image (défaut: latest)
|
||||||
|
#
|
||||||
|
# Exemple:
|
||||||
|
# export REGISTRY_URL=registry.example.com
|
||||||
|
# export REGISTRY_NAMESPACE=myorg
|
||||||
|
# export IMAGE_TAG=latest
|
||||||
|
# docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
|
||||||
|
|
||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
image: ${REGISTRY_URL}/${REGISTRY_NAMESPACE}/notytex-backend:${IMAGE_TAG:-latest}
|
||||||
|
build: null # Désactive le build local
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
image: ${REGISTRY_URL}/${REGISTRY_NAMESPACE}/notytex-frontend:${IMAGE_TAG:-latest}
|
||||||
|
build: null # Désactive le build local
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Dockerfile pour Frontend Vue.js
|
# Dockerfile pour Frontend Vue.js
|
||||||
# Stage 1: Build
|
# Stage 1: Build
|
||||||
FROM node:22-alpine AS builder
|
FROM docker.io/library/node:22-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ COPY . .
|
|||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Production avec Nginx
|
# Stage 2: Production avec Nginx
|
||||||
FROM nginx:alpine
|
FROM docker.io/library/nginx:alpine
|
||||||
|
|
||||||
# Copier le build depuis le stage précédent
|
# Copier le build depuis le stage précédent
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
|||||||
Reference in New Issue
Block a user