ci(lighthouse): add jenkins lighthouse automated audit
Some checks failed
Portfolio/pipeline/head There was a failure building this commit
Some checks failed
Portfolio/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
NODE_VERSION=24
|
||||
CADDY_VERSION=2.10.2
|
||||
CADDY_VERSION=2.10.2
|
||||
LHCI_VERSION=0.15.x
|
||||
ZENIKA_VERSION=124-with-node
|
||||
27
Jenkinsfile
vendored
27
Jenkinsfile
vendored
@@ -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." }
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user