diff --git a/Jenkinsfile b/Jenkinsfile index e1863e9..2c07463 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,15 +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" - 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" + // Create volumes but no run + sh "docker compose --profile audit create lighthouse-audit" - // Launch special service in docker compose - sh "docker compose --profile audit run --rm lighthouse-audit" + // Extract astro data from image to tmp-dist + sh "docker create --name audit-tmp portfolio:${env.APP_VERSION}" + sh "mkdir -p ./tmp-dist" + sh "docker cp audit-tmp:/usr/share/caddy/. ./tmp-dist" + + // 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" + + // 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') { @@ -58,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 92ae65e..b9428a8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,13 +18,16 @@ services: container_name: lighthouse-audit user: "0:0" volumes: - - ./dist-audit:/app/dist - - ./.lighthouseci:/app/.lighthouseci - - ./.lighthouserc.cjs:/app/.lighthouserc.cjs + - 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/.lighthouserc.cjs + command: npx @lhci/cli@${LHCI_VERSION} collect --config=/app/dist/audit-config.cjs + +volumes: + audit_dist: + audit_reports: networks: reverse-proxy: