Jenkins: skip the duplicate CI build on main, clean up stage images, plain build log.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
421e8062e6
commit
c1069820db
3 files changed
+18
-19
No files matched your search
Vendored
+15
-17
@@ -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 {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
@@ -25,31 +30,24 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
|
// main is built by Deploy itself; building here too would double the time.
|
||||||
|
when { not { expression { isMain() } } }
|
||||||
steps {
|
steps {
|
||||||
// Same Dockerfile the NAS builds; the agent shares the host daemon,
|
// Image check only. The agent uses the legacy builder, which leaves untagged images
|
||||||
// so this also warms the build cache for the Deploy stage.
|
// for the deps/build stages, so tag every stage and remove them all afterwards.
|
||||||
sh '''
|
sh '''
|
||||||
set -eu
|
set -eu
|
||||||
tag="registry-aio-app-ci:$(printf '%s' "$BUILD_TAG" | tr -c 'A-Za-z0-9_.-' '-' | cut -c1-128)"
|
tag="registry-aio-app-ci:$(printf '%s' "$BUILD_TAG" | tr -c 'A-Za-z0-9_.-' '-' | cut -c1-120)"
|
||||||
trap 'docker image rm "$tag" >/dev/null 2>&1 || true' EXIT
|
trap 'docker image rm "$tag-deps" "$tag-build" "$tag" >/dev/null 2>&1 || true' EXIT
|
||||||
docker build -t "$tag" app
|
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') {
|
stage('Deploy') {
|
||||||
when {
|
when { expression { isMain() } }
|
||||||
allOf {
|
|
||||||
not { changeRequest() }
|
|
||||||
anyOf {
|
|
||||||
branch 'main'
|
|
||||||
expression {
|
|
||||||
def branch = env.GIT_BRANCH ?: env.BRANCH_NAME ?: ''
|
|
||||||
branch == 'main' || branch == 'origin/main' || branch == 'refs/heads/main'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
// Keep the existing flow: the NAS checkout is the deployment.
|
// 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.
|
// Fast-forward it to the built commit, then rebuild app and `compose up -d` there.
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ app/ # Nuxt + Prisma
|
|||||||
`Jenkinsfile`은 Gitea 멀티브랜치 파이프라인용입니다.
|
`Jenkinsfile`은 Gitea 멀티브랜치 파이프라인용입니다.
|
||||||
|
|
||||||
1. **Validate** — `docker compose config -q`, 배포 스크립트 문법 검사
|
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` 실행
|
3. **Deploy** — `main`만. SSH(`SEJONG-NAS`)로 배포 디렉터리의 체크아웃을 빌드한 커밋까지 fast-forward한 뒤 `scripts/deploy.sh` 실행
|
||||||
|
|
||||||
`scripts/deploy.sh`는 `app`을 다시 빌드하고 `docker compose up -d` 후 `app`이 healthy가 될 때까지 기다립니다.
|
`scripts/deploy.sh`는 `app`을 다시 빌드하고 `docker compose up -d` 후 `app`이 healthy가 될 때까지 기다립니다.
|
||||||
|
|||||||
+2
-1
@@ -10,7 +10,8 @@ HEALTH_TIMEOUT="${HEALTH_TIMEOUT:-180}"
|
|||||||
echo "deploy: $(git log -1 --format='%h %s' 2>/dev/null || echo unknown)"
|
echo "deploy: $(git log -1 --format='%h %s' 2>/dev/null || echo unknown)"
|
||||||
|
|
||||||
docker compose config -q
|
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
|
docker compose up -d
|
||||||
|
|
||||||
# registry's healthcheck always passes, so the app health is what tells us the deploy worked.
|
# registry's healthcheck always passes, so the app health is what tells us the deploy worked.
|
||||||
|
|||||||
Reference in new issue
Block a user