diff --git a/.env.dist b/.env.dist index 94d81fc..ef9ae76 100644 --- a/.env.dist +++ b/.env.dist @@ -1,2 +1,4 @@ NODE_VERSION=24 -CADDY_VERSION=2.10.2 \ No newline at end of file +CADDY_VERSION=2.10.2 +LHCI_VERSION=0.15.x +ZENIKA_VERSION=124-with-node \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile index 2140067..5831652 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,6 +2,7 @@ pipeline { agent any environment { DOCKER_HOST = "unix:///var/run/docker.sock" + APP_VERSION = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" } stages { stage('Build') { @@ -9,12 +10,25 @@ pipeline { // Get Caddy version sh "cp .env.dist .env" // Push portfolio version - sh "echo '\nPORTFOLIO_VERSION=${env.BRANCH_NAME}-${env.BUILD_NUMBER}' >> .env" + sh "echo '\nPORTFOLIO_VERSION=${env.APP_VERSION}' >> .env" echo "Building new portfolio version..." sh "docker compose build" } } + 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" + + // Launch special service in docker compose + sh "docker compose --profile audit run --rm lighthouse-audit" + } + } stage('Deploy') { // Deploy only master branch when { @@ -35,8 +49,17 @@ pipeline { } post { always { - echo "Clean unused image..." + echo "Publish Lighthouse audit..." + publishHTML([ + allowMissing: true, + alwaysLinkToLastBuild: true, + reportDir: '.lighthouseci', + reportFiles: 'index.html', + reportName: 'Lighthouse Report' + ]) + echo "Clean unused image and files..." 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 acdd627..92ae65e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,21 @@ services: networks: - reverse-proxy + lighthouse-audit: + profiles: + - audit + image: zenika/alpine-chrome:${ZENIKA_VERSION} + container_name: lighthouse-audit + user: "0:0" + volumes: + - ./dist-audit:/app/dist + - ./.lighthouseci:/app/.lighthouseci + - ./.lighthouserc.cjs:/app/.lighthouserc.cjs + environment: + - CHROME_PATH=/usr/bin/chromium-browser + working_dir: /app + command: npx @lhci/cli@${LHCI_VERSION} collect --config=/app/.lighthouserc.cjs + networks: reverse-proxy: external: true \ No newline at end of file