Compare commits

...

6 Commits

Author SHA1 Message Date
df209edb27 fix(jenkins): new docker host rootless
All checks were successful
Portfolio/pipeline/head This commit looks good
2026-01-27 18:38:43 +01:00
f1794abe7e fix(jenkins): fix lighthouse audit launch in jenkinsfile
All checks were successful
Portfolio/pipeline/head This commit looks good
2026-01-12 19:03:20 +01:00
351256483f refactor(lighthouse): lighthouse local use same docker compose as jenkins 2026-01-12 19:03:20 +01:00
db7e655d4f perf(docker): add npm cache 2026-01-12 19:03:20 +01:00
952c75127a fix(lighthouse): change audit export path and config 2026-01-12 19:03:20 +01:00
fa8e84514a fix(lighthouse): switch to docker volumes 2026-01-12 19:01:53 +01:00
4 changed files with 65 additions and 28 deletions

View File

@@ -4,6 +4,7 @@ module.exports = {
staticDistDir: '/app/dist',
settings: {
chromeFlags: '--no-sandbox --disable-setuid-sandbox --headless=new --disable-gpu --disable-dev-shm-usage',
targets: ['filesystem'],
},
numberOfRuns: 1
},
@@ -16,7 +17,8 @@ module.exports = {
},
},
upload: {
target: 'temporary-public-storage',
target: 'filesystem',
outputDir: './.lighthouseci', // C'est ici que Jenkins ira chercher les fichiers
},
},
};

40
Jenkinsfile vendored
View File

@@ -1,8 +1,9 @@
pipeline {
agent any
environment {
DOCKER_HOST = "unix:///var/run/docker.sock"
DOCKER_HOST = "unix:///run/user/1001/docker.sock"
APP_VERSION = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
DOCKER_CONFIG = "${env.WORKSPACE}/.docker"
}
stages {
stage('Build') {
@@ -18,15 +19,31 @@ 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"
// Launch special service in docker compose
sh "docker compose --profile audit run --rm lighthouse-audit"
// Create volumes but no run with safety
sh "docker rm -f audit-tmp lighthouse-audit || true"
sh "docker compose --profile audit create --no-build --remove-orphans lighthouse-audit"
// Extract astro data from temp container to tmp-dist folder
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"
sh "rm -rf ./tmp-dist"
// Now run
sh "docker start -a lighthouse-audit"
// Get reports
sh "mkdir -p ./.lighthouseci"
sh "docker cp lighthouse-audit:/app/.lighthouseci/. ./.lighthouseci/"
// Clean
sh "docker rm -f lighthouse-audit"
}
}
stage('Deploy') {
@@ -55,12 +72,11 @@ pipeline {
alwaysLinkToLastBuild: true,
keepAll: false,
reportDir: '.lighthouseci',
reportFiles: 'index.html',
reportFiles: '*.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." }

View File

@@ -18,13 +18,18 @@ 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
- npm_cache:/root/.npm
environment:
- CHROME_PATH=/usr/bin/chromium-browser
working_dir: /app
command: npx @lhci/cli@${LHCI_VERSION} collect --config=/app/.lighthouserc.cjs
command: npx --prefer-offline @lhci/cli@${LHCI_VERSION} autorun --config=/app/dist/audit-config.cjs
volumes:
audit_dist:
audit_reports:
npm_cache:
networks:
reverse-proxy:

View File

@@ -1,14 +1,28 @@
#!/bin/bash
mkdir -p ./.lighthouseci
# Clean old audits and containers
rm -rf ./.lighthouseci
docker rm -f lighthouse-audit || true
docker run --rm \
--user 0:0 \
-v ./dist:/app/dist \
-v ./.lighthouserc.cjs:/app/.lighthouserc.cjs \
-v ./.lighthouseci:/app/.lighthouseci \
-w /app \
-e CHROME_PATH=/usr/bin/chromium-browser \
zenika/alpine-chrome:with-node \
npx @lhci/cli@0.15.x collect \
--config=/app/.lighthouserc.cjs
# Load env file and avoid warning for unused portofolio version
if [ -f .env.dist ]; then
export $(grep -v '^#' .env.dist | xargs)
fi
export PORTFOLIO_VERSION="local-audit"
# Create container but no start
docker compose --profile audit create --no-build --remove-orphans lighthouse-audit
# Inject data and config to container
docker cp ./dist/. lighthouse-audit:/app/dist/
docker cp .lighthouserc.cjs lighthouse-audit:/app/dist/audit-config.cjs
# Now run
docker start -a lighthouse-audit
# Get reports
mkdir -p ./.lighthouseci
docker cp lighthouse-audit:/app/.lighthouseci/. ./.lighthouseci/
# Clean container
docker rm -f lighthouse-audit