ci(lighthouse): add jenkins lighthouse automated audit
This commit is contained in:
@@ -1,2 +1,4 @@
|
|||||||
NODE_VERSION=24
|
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
|
agent any
|
||||||
environment {
|
environment {
|
||||||
DOCKER_HOST = "unix:///var/run/docker.sock"
|
DOCKER_HOST = "unix:///var/run/docker.sock"
|
||||||
|
APP_VERSION = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
@@ -9,12 +10,25 @@ pipeline {
|
|||||||
// Get Caddy version
|
// Get Caddy version
|
||||||
sh "cp .env.dist .env"
|
sh "cp .env.dist .env"
|
||||||
// Push portfolio version
|
// 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..."
|
echo "Building new portfolio version..."
|
||||||
sh "docker compose build"
|
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') {
|
stage('Deploy') {
|
||||||
// Deploy only master branch
|
// Deploy only master branch
|
||||||
when {
|
when {
|
||||||
@@ -35,8 +49,17 @@ pipeline {
|
|||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
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 "docker image prune -f"
|
||||||
|
sh "rm -rf ./dist-audit"
|
||||||
}
|
}
|
||||||
success { echo "Success !" }
|
success { echo "Success !" }
|
||||||
failure { echo "Failed." }
|
failure { echo "Failed." }
|
||||||
|
|||||||
@@ -11,6 +11,21 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- reverse-proxy
|
- 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:
|
networks:
|
||||||
reverse-proxy:
|
reverse-proxy:
|
||||||
external: true
|
external: true
|
||||||
Reference in New Issue
Block a user