Skip to content
Open

maj #30

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.git
.github
npm-debug.log
dist
e2e
coverage
68 changes: 68 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Étape 1: Build de l'application
FROM node:16-alpine as build
WORKDIR /app

# Optimisation des couches de cache
COPY package.json ./
RUN npm i -f

# Copie du reste des fichiers
COPY . .
RUN npm run build --

# Étape 2: Servir l'application avec NGINX
FROM nginx:alpine
COPY --from=build /app/dist/ /usr/share/nginx/html

# Configuration pour les Single Page Applications
RUN echo 'server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html; try_files $uri $uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf

# Sécurité : Exécution en tant qu'utilisateur non-root
RUN chown -R nginx:nginx /usr/share/nginx/html && \
chmod -R 755 /usr/share/nginx/html && \
chown -R nginx:nginx /var/cache/nginx && \
chown -R nginx:nginx /var/log/nginx && \
chown -R nginx:nginx /etc/nginx/conf.d
RUN touch /var/run/nginx.pid && \
chown -R nginx:nginx /var/run/nginx.pid

USER nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
12 changes: 12 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:16-alpine

WORKDIR /app

COPY package.json ./
RUN npm ci

COPY . .

EXPOSE 4200

CMD ["npm", "start"]
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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
Loading