From 54f4372629289ad623cfb0f94ce10c9bc8777389 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 8 Jan 2026 19:39:17 +0100 Subject: [PATCH] feat(jenkins): manage portfolio version, caddy version and cache --- .env.dist | 1 + Caddyfile | 6 ++---- Dockerfile | 4 +++- Jenkinsfile | 14 +++++++++++--- docker-compose.yml | 6 +++++- 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 .env.dist diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..730f570 --- /dev/null +++ b/.env.dist @@ -0,0 +1 @@ +CADDY_VERSION=2.10.2 \ No newline at end of file diff --git a/Caddyfile b/Caddyfile index 781a256..aa46b45 100644 --- a/Caddyfile +++ b/Caddyfile @@ -2,10 +2,8 @@ root * /usr/share/caddy file_server - # No cache, always update + # Client cache header { - Cache-Control "no-cache, no-store, must-revalidate" - Pragma "no-cache" - Expires "0" + Cache-Control "public, max-age=86400" } } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8ac077f..614f65f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ +ARG CADDY_VERSION + # --- BUILD --- FROM node:24-alpine AS build RUN corepack enable && corepack prepare pnpm@latest --activate @@ -15,7 +17,7 @@ COPY . . RUN pnpm build # --- DEPLOY --- -FROM caddy:alpine +FROM caddy:${CADDY_VERSION}-alpine COPY --from=build /app/dist /usr/share/caddy COPY Caddyfile /etc/caddy/Caddyfile diff --git a/Jenkinsfile b/Jenkinsfile index b4d10c2..2140067 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,10 +4,15 @@ pipeline { DOCKER_HOST = "unix:///var/run/docker.sock" } stages { - stage('Docker Build') { + stage('Build') { steps { - echo "Build new docker image from ${env.BRANCH_NAME}..." - sh "docker build -t portfolio:${env.BRANCH_NAME} ." + // Get Caddy version + sh "cp .env.dist .env" + // Push portfolio version + sh "echo '\nPORTFOLIO_VERSION=${env.BRANCH_NAME}-${env.BUILD_NUMBER}' >> .env" + + echo "Building new portfolio version..." + sh "docker compose build" } } stage('Deploy') { @@ -19,6 +24,9 @@ pipeline { echo "Deploy new portfolio version..." sh "docker compose up -d" + // 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" diff --git a/docker-compose.yml b/docker-compose.yml index 214ee87..9a1f4a1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,10 @@ services: portfolio: - image: portfolio:master + build: + context: . + args: + - CADDY_VERSION=${CADDY_VERSION} + image: portfolio:${PORTFOLIO_VERSION} container_name: portfolio restart: always networks: