From a7c1fb7aa975ab92a33834a487fadc6f2ab898f6 Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 14:29:08 +0100 Subject: [PATCH 01/12] ci: add workflow for self-hosted runner --- .github/workflows/self-hosted-ci.yml | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/self-hosted-ci.yml diff --git a/.github/workflows/self-hosted-ci.yml b/.github/workflows/self-hosted-ci.yml new file mode 100644 index 000000000..404a2f4a4 --- /dev/null +++ b/.github/workflows/self-hosted-ci.yml @@ -0,0 +1,32 @@ +name: Self-Hosted CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + # Ajout d'un déclencheur manuel pour faciliter les tests + workflow_dispatch: + +jobs: + build-and-test: + # Spécifie d'utiliser votre runner auto-hébergé au lieu des runners GitHub + runs-on: self-hosted + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log Node.js version + run: node --version + + - name: Log available disk space + run: | + echo "Checking available disk space:" + df -h + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test -- --watch=false --browsers=ChromeHeadless --no-progress From 4228545b335605acc0bb08b57e6c6ae245696e2d Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 14:45:45 +0100 Subject: [PATCH 02/12] Changed YAML --- .github/workflows/self-hosted-ci.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/self-hosted-ci.yml b/.github/workflows/self-hosted-ci.yml index 404a2f4a4..eb4854751 100644 --- a/.github/workflows/self-hosted-ci.yml +++ b/.github/workflows/self-hosted-ci.yml @@ -5,12 +5,10 @@ on: branches: [ main ] pull_request: branches: [ main ] - # Ajout d'un déclencheur manuel pour faciliter les tests workflow_dispatch: jobs: build-and-test: - # Spécifie d'utiliser votre runner auto-hébergé au lieu des runners GitHub runs-on: self-hosted steps: @@ -20,13 +18,21 @@ jobs: - name: Log Node.js version run: node --version - - name: Log available disk space - run: | - echo "Checking available disk space:" - df -h + - name: Cache node modules + uses: actions/cache@v3 + id: npm-cache + with: + path: node_modules + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- - name: Install dependencies + if: steps.npm-cache.outputs.cache-hit != 'true' run: npm ci - name: Run tests run: npm test -- --watch=false --browsers=ChromeHeadless --no-progress + + - name: Build application + run: npm run build -- --configuration production From 3d3777a6fd3723b2b327271214e83633528f726a Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 15:02:54 +0100 Subject: [PATCH 03/12] Modification du Runner --- .github/workflows/self-hosted-ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/self-hosted-ci.yml b/.github/workflows/self-hosted-ci.yml index eb4854751..1ecfb7a0a 100644 --- a/.github/workflows/self-hosted-ci.yml +++ b/.github/workflows/self-hosted-ci.yml @@ -36,3 +36,16 @@ jobs: - name: Build application run: npm run build -- --configuration production + + cleanup: + runs-on: self-hosted + needs: build-and-test + if: always() + + steps: + - name: Clean workspace + run: | + echo "Cleaning workspace to free up disk space" + rm -rf node_modules || true + rm -rf dist || true + npm cache clean --force || true From 99b9021773105c31c458ff0b9cd80a45a22a9807 Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 15:05:03 +0100 Subject: [PATCH 04/12] Modification du Runner (encore) --- .github/workflows/self-hosted-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/self-hosted-ci.yml b/.github/workflows/self-hosted-ci.yml index 1ecfb7a0a..8ec2e9bd8 100644 --- a/.github/workflows/self-hosted-ci.yml +++ b/.github/workflows/self-hosted-ci.yml @@ -29,7 +29,7 @@ jobs: - name: Install dependencies if: steps.npm-cache.outputs.cache-hit != 'true' - run: npm ci + run: npm ci --force - name: Run tests run: npm test -- --watch=false --browsers=ChromeHeadless --no-progress From 88f24e338b11ecb4491417150d472ab5255ce0c7 Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 15:14:18 +0100 Subject: [PATCH 05/12] Modification du Runner (encore et encore) --- .github/workflows/self-hosted-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/self-hosted-ci.yml b/.github/workflows/self-hosted-ci.yml index 8ec2e9bd8..b5e8d343d 100644 --- a/.github/workflows/self-hosted-ci.yml +++ b/.github/workflows/self-hosted-ci.yml @@ -29,7 +29,7 @@ jobs: - name: Install dependencies if: steps.npm-cache.outputs.cache-hit != 'true' - run: npm ci --force + run: npm i --force - name: Run tests run: npm test -- --watch=false --browsers=ChromeHeadless --no-progress From e2d5d50898e48f81b1e7bc828e3958c21d3a70c5 Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 15:57:37 +0100 Subject: [PATCH 06/12] Modification du Runner (encore et encore et encore) --- .github/workflows/self-hosted-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/self-hosted-ci.yml b/.github/workflows/self-hosted-ci.yml index b5e8d343d..2b975f158 100644 --- a/.github/workflows/self-hosted-ci.yml +++ b/.github/workflows/self-hosted-ci.yml @@ -32,7 +32,7 @@ jobs: run: npm i --force - name: Run tests - run: npm test -- --watch=false --browsers=ChromeHeadless --no-progress + run: npm test -- --watch=false --browsers=edge --no-progress - name: Build application run: npm run build -- --configuration production @@ -46,6 +46,6 @@ jobs: - name: Clean workspace run: | echo "Cleaning workspace to free up disk space" - rm -rf node_modules || true - rm -rf dist || true - npm cache clean --force || true + rm -rf node_modules | true + rm -rf dist | true + npm cache clean --force | true From 57e04b6dbe62931e133983b9a69841a377fb4082 Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 16:28:58 +0100 Subject: [PATCH 07/12] Tst --- .github/workflows/self-hosted-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/self-hosted-ci.yml b/.github/workflows/self-hosted-ci.yml index 2b975f158..65a05f9a1 100644 --- a/.github/workflows/self-hosted-ci.yml +++ b/.github/workflows/self-hosted-ci.yml @@ -46,6 +46,6 @@ jobs: - name: Clean workspace run: | echo "Cleaning workspace to free up disk space" - rm -rf node_modules | true - rm -rf dist | true - npm cache clean --force | true + rm -rf node_modules || true + rm -rf dist || true + npm cache clean --force || true From aa87ca7607ac436d4c38406372e8e7e51c3061ac Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 16:32:09 +0100 Subject: [PATCH 08/12] ci: add Docker build and container testing --- .github/workflows/self-hosted-ci.yml | 34 +++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/.github/workflows/self-hosted-ci.yml b/.github/workflows/self-hosted-ci.yml index 65a05f9a1..a76a050ab 100644 --- a/.github/workflows/self-hosted-ci.yml +++ b/.github/workflows/self-hosted-ci.yml @@ -29,17 +29,38 @@ jobs: - name: Install dependencies if: steps.npm-cache.outputs.cache-hit != 'true' - run: npm i --force + run: npm ci - name: Run tests - run: npm test -- --watch=false --browsers=edge --no-progress + run: npm test -- --watch=false --browsers=ChromeHeadless --no-progress - name: Build application run: npm run build -- --configuration production - cleanup: + docker-build: runs-on: self-hosted needs: build-and-test + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Build Docker image + run: docker build -t angular-app:${{ github.sha }} . + + - name: Test Docker image + run: | + echo "Testing Docker image..." + docker run -d --name test-container -p 8080:80 angular-app:${{ github.sha }} + echo "Container started, waiting for it to initialize..." + sleep 10 + curl -s http://localhost:8080 | grep -q "conduit" && echo "Application is running correctly" || echo "Failed to verify application" + docker stop test-container + docker rm test-container + + cleanup: + runs-on: self-hosted + needs: [build-and-test, docker-build] if: always() steps: @@ -49,3 +70,10 @@ jobs: rm -rf node_modules || true rm -rf dist || true npm cache clean --force || true + + - name: Prune Docker images + run: | + echo "Keeping only recent Docker images" + docker image ls + # Conserver seulement les 3 images les plus récentes + docker image prune -a -f --filter "until=24h" From 52ba1a3622167320072998be311574735dd6a09e Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 16:45:19 +0100 Subject: [PATCH 09/12] ci: add Docker build and container testing2 --- Dockerfile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..d42dabba7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +# Étape 1: Build de l'application +FROM node:16 as build +WORKDIR /app +COPY package.json package-lock.json ./ +RUN npm i -f +COPY . . +RUN npm run build --configuration prod + +# Étape 2: Servir l'application avec NGINX +FROM nginx:alpine +COPY --from=build /app/dist/ /usr/share/nginx/html +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file From 4ce0e9dba0a7ac4c325e3a12acfc7e8a682f1ab5 Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 16:46:58 +0100 Subject: [PATCH 10/12] ci: add Docker build and container testing3 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d42dabba7..28c7b70d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /app COPY package.json package-lock.json ./ RUN npm i -f COPY . . -RUN npm run build --configuration prod +RUN npm run build # Étape 2: Servir l'application avec NGINX FROM nginx:alpine From acd7d25bddbd74d14f057c55cc5ec3187b20720b Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 16:50:06 +0100 Subject: [PATCH 11/12] ci: add Docker build and container testing4 --- Dockerfile | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 28c7b70d9..b5a577c2a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,31 @@ # Étape 1: Build de l'application -FROM node:16 as build +FROM node:16-alpine as build WORKDIR /app + +# Optimisation des couches de cache COPY package.json package-lock.json ./ -RUN npm i -f +RUN npm ci + +# Copie du reste des fichiers COPY . . -RUN npm run build +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;"] \ No newline at end of file +CMD ["nginx", "-g", "daemon off;"] From 2d006fb92bc52d48c94fd246dacf9329d02cd096 Mon Sep 17 00:00:00 2001 From: Mudzz Date: Mon, 3 Mar 2025 16:51:35 +0100 Subject: [PATCH 12/12] ci: add Docker build and container testing5 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b5a577c2a..be8b37fb9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /app # Optimisation des couches de cache COPY package.json package-lock.json ./ -RUN npm ci +RUN npm i --force # Copie du reste des fichiers COPY . .