From c1069820dbad80f26cbc548b6d31ad78b067bdad Mon Sep 17 00:00:00 2001 From: ysj7705 Date: Thu, 8 Oct 2026 10:44:18 +0900 Subject: [PATCH] Jenkins: skip the duplicate CI build on main, clean up stage images, plain build log. Co-Authored-By: Claude Opus 5.5 --- Jenkinsfile | 32 +++++++++++++++----------------- README.md | 2 +- scripts/deploy.sh | 3 ++- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 59c6420..488f8ac 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,8 @@ +def isMain() { + def branch = env.BRANCH_NAME ?: env.GIT_BRANCH ?: '' + return !env.CHANGE_ID && branch in ['main', 'origin/main', 'refs/heads/main'] +} + pipeline { agent any @@ -25,31 +30,24 @@ pipeline { } stage('Build') { + // main is built by Deploy itself; building here too would double the time. + when { not { expression { isMain() } } } steps { - // Same Dockerfile the NAS builds; the agent shares the host daemon, - // so this also warms the build cache for the Deploy stage. + // Image check only. The agent uses the legacy builder, which leaves untagged images + // for the deps/build stages, so tag every stage and remove them all afterwards. sh ''' set -eu - tag="registry-aio-app-ci:$(printf '%s' "$BUILD_TAG" | tr -c 'A-Za-z0-9_.-' '-' | cut -c1-128)" - trap 'docker image rm "$tag" >/dev/null 2>&1 || true' EXIT - docker build -t "$tag" app + tag="registry-aio-app-ci:$(printf '%s' "$BUILD_TAG" | tr -c 'A-Za-z0-9_.-' '-' | cut -c1-120)" + trap 'docker image rm "$tag-deps" "$tag-build" "$tag" >/dev/null 2>&1 || true' EXIT + docker build -q --target deps -t "$tag-deps" app + docker build -q --target build -t "$tag-build" app + docker build -q -t "$tag" app ''' } } stage('Deploy') { - when { - allOf { - not { changeRequest() } - anyOf { - branch 'main' - expression { - def branch = env.GIT_BRANCH ?: env.BRANCH_NAME ?: '' - branch == 'main' || branch == 'origin/main' || branch == 'refs/heads/main' - } - } - } - } + when { expression { isMain() } } steps { // Keep the existing flow: the NAS checkout is the deployment. // Fast-forward it to the built commit, then rebuild app and `compose up -d` there. diff --git a/README.md b/README.md index 3192e85..49811bf 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ app/ # Nuxt + Prisma `Jenkinsfile`은 Gitea 멀티브랜치 파이프라인용입니다. 1. **Validate** — `docker compose config -q`, 배포 스크립트 문법 검사 -2. **Build** — `app` 이미지를 빌드해 확인만 하고 지움 (모든 브랜치·PR) +2. **Build** — `main` 외 브랜치·PR에서 `app` 이미지를 빌드해 확인만 하고 지움 (`main`은 Deploy가 빌드) 3. **Deploy** — `main`만. SSH(`SEJONG-NAS`)로 배포 디렉터리의 체크아웃을 빌드한 커밋까지 fast-forward한 뒤 `scripts/deploy.sh` 실행 `scripts/deploy.sh`는 `app`을 다시 빌드하고 `docker compose up -d` 후 `app`이 healthy가 될 때까지 기다립니다. diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 6407793..65c73b9 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -10,7 +10,8 @@ HEALTH_TIMEOUT="${HEALTH_TIMEOUT:-180}" echo "deploy: $(git log -1 --format='%h %s' 2>/dev/null || echo unknown)" docker compose config -q -docker compose build app +# Plain progress: the Jenkins SSH session has a pty, and the tty view floods the log. +BUILDKIT_PROGRESS=plain docker compose build app docker compose up -d # registry's healthcheck always passes, so the app health is what tells us the deploy worked.