From a01204a377a3cf075fc2c802a9862fe769f875d7 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 12 Jan 2026 12:16:47 +0100 Subject: [PATCH] fix(lighthouse): switch to docker volumes --- Jenkinsfile | 31 ++++++++++++++++--------- docker-compose.yml | 57 ++++++++++++++++++++++++---------------------- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1eb5b96..2c07463 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,18 +18,28 @@ pipeline { } stage('Lighthouse Audit') { steps { - // Temporary container to get data in /dist folder - // Reuse of just build portfolio image - sh "mkdir -p ./dist-audit ./.lighthouseci" + // Create volumes but no run + sh "docker compose --profile audit create lighthouse-audit" + + // Extract astro data from image to tmp-dist sh "docker create --name audit-tmp portfolio:${env.APP_VERSION}" - sh "docker cp audit-tmp:/usr/share/caddy/. ./dist-audit" - sh "docker rm audit-tmp" + sh "mkdir -p ./tmp-dist" + sh "docker cp audit-tmp:/usr/share/caddy/. ./tmp-dist" - // Add audit config in the same folder - sh "cp .lighthouserc.cjs ./dist-audit/audit-config.cjs" + // Inject data from tmp-dist and config to audit container + sh "docker cp ./tmp-dist/. lighthouse-audit:/app/dist/" + sh "docker cp .lighthouserc.cjs lighthouse-audit:/app/dist/audit-config.cjs" - // Launch special service in docker compose - sh "docker compose --profile audit run --rm lighthouse-audit" + // Now run + sh "docker compose --profile audit run lighthouse-audit" + + // Get reports + sh "mkdir -p ./.lighthouseci" + sh "docker cp lighthouse-audit:/app/.lighthouseci/. ./.lighthouseci/" + + // Clean temp + sh "docker rm lighthouse-audit" + sh "rm -rf ./tmp-dist" } } stage('Deploy') { @@ -61,9 +71,8 @@ pipeline { reportFiles: 'index.html', reportName: 'Lighthouse Report' ]) - echo "Clean unused image and files..." + echo "Clean unused image" sh "docker image prune -f" - sh "rm -rf ./dist-audit" } success { echo "Success !" } failure { echo "Failed." } diff --git a/docker-compose.yml b/docker-compose.yml index 1f6ccfd..b1c96d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,31 +1,34 @@ services: - portfolio: - build: - context: . - args: - - NODE_VERSION=${NODE_VERSION} - - CADDY_VERSION=${CADDY_VERSION} - image: portfolio:${PORTFOLIO_VERSION} - container_name: portfolio - restart: always - networks: - - reverse-proxy +portfolio: + build: + context: . + args: + - NODE_VERSION=${NODE_VERSION} + - CADDY_VERSION=${CADDY_VERSION} + image: portfolio:${PORTFOLIO_VERSION} + container_name: portfolio + restart: always + networks: + - reverse-proxy - lighthouse-audit: - profiles: - - audit - image: zenika/alpine-chrome:${ZENIKA_VERSION} - container_name: lighthouse-audit - user: "0:0" - volumes: - # astro file + config - - ./dist-audit:/app/dist - - ./.lighthouseci:/app/.lighthouseci - environment: - - CHROME_PATH=/usr/bin/chromium-browser - working_dir: /app - command: npx @lhci/cli@${LHCI_VERSION} collect --config=/app/dist/audit-config.cjs +lighthouse-audit: + profiles: + - audit + image: zenika/alpine-chrome:${ZENIKA_VERSION} + container_name: lighthouse-audit + user: "0:0" + volumes: + - audit_dist:/app/dist + - audit_reports:/app/.lighthouseci + environment: + - CHROME_PATH=/usr/bin/chromium-browser + working_dir: /app + command: npx @lhci/cli@${LHCI_VERSION} collect --config=/app/dist/audit-config.cjs + +volumes: +audit_dist: +audit_reports: networks: - reverse-proxy: - external: true \ No newline at end of file +reverse-proxy: + external: true \ No newline at end of file