diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 000000000..711f0d826 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,68 @@ +name: Continuous Deployment + +on: + # Déclenché manuellement ou après un merge sur main + workflow_dispatch: + push: + branches: [ main ] + +jobs: + # Job de construction de l'image + build: + runs-on: self-hosted + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Build Docker image + run: | + echo "Building Docker image..." + docker build -t angular-app:${{ github.sha }} . + + - name: Tag images for environments + run: | + docker tag angular-app:${{ github.sha }} angular-app:staging + docker tag angular-app:${{ github.sha }} angular-app:production + + # Déploiement en staging + deploy-staging: + needs: build + runs-on: self-hosted + environment: staging + + steps: + - name: Deploy to staging + run: | + echo "Deploying to staging environment..." + docker-compose up -d app-staging + echo "Deployment to staging completed." + + - name: Verify staging deployment + run: | + echo "Verifying staging deployment..." + # Attendre que l'application soit prête + sleep 5 + # Vérifier que l'application répond + curl -s http://localhost:8080 | grep -q "conduit" && echo "✅ Application is running correctly in staging" || (echo "❌ Staging verification failed" && exit 1) + + # Déploiement en production + deploy-production: + needs: deploy-staging + runs-on: self-hosted + environment: production + + steps: + - name: Deploy to production + run: | + echo "Deploying to production environment..." + docker-compose up -d app-production + echo "Deployment to production completed." + + - name: Verify production deployment + run: | + echo "Verifying production deployment..." + # Attendre que l'application soit prête + sleep 5 + # Vérifier que l'application répond + curl -s http://localhost:80 | grep -q "conduit" && echo "✅ Application is running correctly in production" || (echo "❌ Production verification failed" && exit 1) diff --git a/DEPLOYMENT_CI.md b/DEPLOYMENT_CI.md new file mode 100644 index 000000000..1436f372b --- /dev/null +++ b/DEPLOYMENT_CI.md @@ -0,0 +1,17 @@ +# Déploiement automatisé avec CI/CD + +Ce document décrit comment configurer le déploiement automatisé via GitHub Actions. + +## Avantages du CI/CD + +- Déploiement automatique à chaque push sur main +- Vérification de qualité systématique +- Cohérence entre environnements +- Traçabilité des déploiements + +## Configuration requise + +- Compte GitHub +- Docker Hub +- Serveur de production +Ligne ajoutée par master diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..3d8c5d362 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: '3.8' + +services: + # Environnement de staging + app-staging: + image: angular-app:staging + container_name: app-staging + ports: + - "8080:80" + restart: unless-stopped + networks: + - app-network + + # Environnement de production + app-production: + image: angular-app:production + container_name: app-production + ports: + - "80:80" + restart: unless-stopped + networks: + - app-network + +networks: + app-network: + driver: bridge +