feat(ci): add automated Lighthouse audit pipeline

This commit is contained in:
2026-01-12 17:50:50 +01:00
parent ee13b191c3
commit c6b0cde818
8 changed files with 106 additions and 18 deletions

43
Jenkinsfile vendored
View File

@@ -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,41 @@ 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 {
// Create volumes but no run with safety
sh "docker rm -f audit-tmp lighthouse-audit || true"
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 "mkdir -p ./tmp-dist"
sh "docker cp audit-tmp:/usr/share/caddy/. ./tmp-dist"
sh "docker rm -f audit-tmp"
// 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
sh "docker rm -f lighthouse-audit"
sh "rm -rf ./tmp-dist"
}
}
stage('Deploy') {
// Deploy only master branch
when {
@@ -35,7 +65,16 @@ pipeline {
}
post {
always {
echo "Clean unused image..."
echo "Publish Lighthouse audit..."
publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: true,
keepAll: false,
reportDir: '.lighthouseci',
reportFiles: '*.html',
reportName: 'Lighthouse Report'
])
echo "Clean unused image"
sh "docker image prune -f"
}
success { echo "Success !" }