Compare commits

...

6 Commits

Author SHA1 Message Date
da8cbc96b5 fix(jenkins): new docker host rootless
All checks were successful
Portfolio/pipeline/head This commit looks good
2026-01-27 19:13:34 +00: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 77 additions and 44 deletions

View File

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

68
Jenkinsfile vendored
View File

@@ -1,8 +1,9 @@
pipeline { pipeline {
agent any agent any
environment { environment {
DOCKER_HOST = "unix:///var/run/docker.sock" DOCKER_HOST = "unix:///run/user/1001/docker.sock"
APP_VERSION = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" APP_VERSION = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
DOCKER_CONFIG = "${env.WORKSPACE}/.docker"
} }
stages { stages {
stage('Build') { stage('Build') {
@@ -16,19 +17,35 @@ pipeline {
sh "docker compose build" sh "docker compose build"
} }
} }
stage('Lighthouse Audit') { // stage('Lighthouse Audit') {
steps { // 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 // // Create volumes but no run with safety
sh "docker compose --profile audit run --rm lighthouse-audit" // 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') { stage('Deploy') {
// Deploy only master branch // Deploy only master branch
when { when {
@@ -40,27 +57,22 @@ pipeline {
// Update caddy-reverse-proxy cache // Update caddy-reverse-proxy cache
sh "docker exec caddy-reverse-proxy caddy reload --config /etc/caddy/Caddyfile" sh "docker exec caddy-reverse-proxy caddy reload --config /etc/caddy/Caddyfile"
// Keep updated docker-compose.yml and Caddyfile for safety
sh "cp docker-compose.yml /backup-portfolio/docker-compose.yml"
sh "docker cp portfolio:/etc/caddy/Caddyfile /backup-portfolio/Caddyfile"
} }
} }
} }
post { post {
always { always {
echo "Publish Lighthouse audit..." // echo "Publish Lighthouse audit..."
publishHTML([ // publishHTML([
allowMissing: true, // allowMissing: true,
alwaysLinkToLastBuild: true, // alwaysLinkToLastBuild: true,
keepAll: false, // keepAll: false,
reportDir: '.lighthouseci', // reportDir: '.lighthouseci',
reportFiles: 'index.html', // reportFiles: '*.html',
reportName: 'Lighthouse Report' // reportName: 'Lighthouse Report'
]) // ])
echo "Clean unused image and files..." echo "Clean unused image"
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." }

View File

@@ -18,13 +18,18 @@ services:
container_name: lighthouse-audit container_name: lighthouse-audit
user: "0:0" user: "0:0"
volumes: volumes:
- ./dist-audit:/app/dist - audit_dist:/app/dist
- ./.lighthouseci:/app/.lighthouseci - audit_reports:/app/.lighthouseci
- ./.lighthouserc.cjs:/app/.lighthouserc.cjs - npm_cache:/root/.npm
environment: environment:
- CHROME_PATH=/usr/bin/chromium-browser - CHROME_PATH=/usr/bin/chromium-browser
working_dir: /app 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: networks:
reverse-proxy: reverse-proxy:

View File

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