Compare commits
6 Commits
579ab3ec47
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| da8cbc96b5 | |||
| f1794abe7e | |||
| 351256483f | |||
| db7e655d4f | |||
| 952c75127a | |||
| fa8e84514a |
@@ -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
|
||||
},
|
||||
},
|
||||
};
|
||||
68
Jenkinsfile
vendored
68
Jenkinsfile
vendored
@@ -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') {
|
||||
@@ -16,19 +17,35 @@ pipeline {
|
||||
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"
|
||||
// stage('Lighthouse Audit') {
|
||||
// steps {
|
||||
|
||||
// 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') {
|
||||
// Deploy only master branch
|
||||
when {
|
||||
@@ -40,27 +57,22 @@ pipeline {
|
||||
|
||||
// Update caddy-reverse-proxy cache
|
||||
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 {
|
||||
always {
|
||||
echo "Publish Lighthouse audit..."
|
||||
publishHTML([
|
||||
allowMissing: true,
|
||||
alwaysLinkToLastBuild: true,
|
||||
keepAll: false,
|
||||
reportDir: '.lighthouseci',
|
||||
reportFiles: 'index.html',
|
||||
reportName: 'Lighthouse Report'
|
||||
])
|
||||
echo "Clean unused image and files..."
|
||||
// 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"
|
||||
sh "rm -rf ./dist-audit"
|
||||
}
|
||||
success { echo "Success !" }
|
||||
failure { echo "Failed." }
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user