harbor-arm-build/Jenkinsfile

163 lines
4.9 KiB
Plaintext
Raw Normal View History

2025-12-16 19:23:46 -03:00
pipeline {
2025-12-17 02:05:53 -03:00
triggers {
pollSCM('H/5 * * * *')
}
2025-12-16 22:41:23 -03:00
agent {
kubernetes {
label 'harbor-arm-build'
2025-12-16 23:12:01 -03:00
defaultContainer 'builder'
2025-12-16 22:41:23 -03:00
yaml """
apiVersion: v1
kind: Pod
spec:
nodeSelector:
kubernetes.io/arch: arm64
hardware: rpi5
2025-12-16 22:41:23 -03:00
containers:
2025-12-16 23:12:01 -03:00
- name: dind
image: docker:27-dind
securityContext:
privileged: true
env:
- name: DOCKER_TLS_CERTDIR
value: ""
args:
- --mtu=1400
2025-12-16 22:41:23 -03:00
volumeMounts:
2025-12-16 23:12:01 -03:00
- name: dind-storage
mountPath: /var/lib/docker
- name: builder
image: docker:27
command: ["cat"]
2025-12-16 22:41:23 -03:00
tty: true
2025-12-16 23:12:01 -03:00
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
- name: DOCKER_TLS_CERTDIR
value: ""
2025-12-16 22:41:23 -03:00
volumeMounts:
2025-12-16 23:12:01 -03:00
- name: workspace-volume
mountPath: /home/jenkins/agent
- name: docker-config-writable
mountPath: /root/.docker
- name: docker-config-secret
mountPath: /docker-config
2025-12-16 22:41:23 -03:00
volumes:
- name: docker-config-secret
secret:
secretName: harbor-robot-pipeline
items:
- key: .dockerconfigjson
path: config.json
- name: docker-config-writable
emptyDir: {}
2025-12-16 22:41:23 -03:00
- name: workspace-volume
emptyDir: {}
2025-12-16 23:12:01 -03:00
- name: dind-storage
emptyDir: {}
2025-12-16 22:41:23 -03:00
"""
}
}
2025-12-16 19:23:46 -03:00
environment {
2025-12-16 23:12:01 -03:00
VERSION = 'v2.14.1'
TAG_SUFFIX = '-arm64'
2025-12-17 12:27:57 -03:00
// Avoid `REGISTRY` here because Harbor's Makefiles use `REGISTRY=registry` and
// run sub-makes with `-e`, so environment variables override make vars.
2025-12-17 12:24:07 -03:00
IMAGE_NAMESPACE = 'registry.bstein.dev/infra'
2025-12-16 23:12:01 -03:00
HARBOR_TARBALL = "https://github.com/goharbor/harbor/archive/refs/tags/${VERSION}.tar.gz"
}
options {
disableConcurrentBuilds()
2025-12-16 19:23:46 -03:00
}
stages {
2025-12-16 23:12:01 -03:00
stage('Checkout Jenkinsfile') {
2025-12-16 19:23:46 -03:00
steps {
2025-12-16 23:12:01 -03:00
git credentialsId: 'gitea-pat', url: 'https://scm.bstein.dev/bstein/harbor-arm-build.git'
}
}
stage('Prep toolchain') {
steps {
container('builder') {
sh '''
set -euo pipefail
apk add --no-cache bash curl make tar gzip git coreutils go ncurses
2025-12-16 23:12:01 -03:00
'''
2025-12-16 22:41:23 -03:00
}
2025-12-16 19:23:46 -03:00
}
}
2025-12-16 23:12:01 -03:00
stage('Fetch harbor source') {
2025-12-16 19:23:46 -03:00
steps {
2025-12-16 23:12:01 -03:00
container('builder') {
2025-12-16 19:23:46 -03:00
sh '''
2025-12-16 23:12:01 -03:00
set -euo pipefail
rm -rf harbor-src
mkdir -p harbor-src
curl -sSL "${HARBOR_TARBALL}" | tar xz -C harbor-src
'''
}
}
}
stage('Build & push arm64 images') {
steps {
container('builder') {
sh '''
set -euo pipefail
VERSIONTAG="${VERSION}${TAG_SUFFIX}.${BUILD_NUMBER}"
export VERSIONTAG
mkdir -p /root/.docker
cp /docker-config/config.json /root/.docker/config.json
# Harbor's build uses git metadata; Jenkins workspace ownership can trigger
# Git's safe.directory protection in containerized builds.
git config --global --add safe.directory '*'
2025-12-16 22:41:23 -03:00
2025-12-17 02:36:39 -03:00
# `harbor-src/` itself matches `harbor-*`, so exclude it.
SRC_DIR=$(find harbor-src -mindepth 1 -maxdepth 1 -type d -name "harbor-*" | head -n1)
cd "${SRC_DIR}"
2025-12-16 22:41:23 -03:00
export DOCKER_BUILDKIT=1
2025-12-16 23:12:01 -03:00
2025-12-17 11:11:43 -03:00
# Harbor's root Makefile hard-sets many defaults (e.g. IMAGENAMESPACE=goharbor,
# PULL_BASE_FROM_DOCKERHUB=true). Environment exports are not sufficient because
# makefile assignments override the environment. Pass overrides on the make
# command line so they win.
make compile
2025-12-17 11:11:43 -03:00
make \
VERSIONTAG="${VERSIONTAG}" \
BASEIMAGETAG="${VERSIONTAG}" \
2025-12-17 12:24:07 -03:00
IMAGENAMESPACE="${IMAGE_NAMESPACE}" \
BASEIMAGENAMESPACE="${IMAGE_NAMESPACE}" \
2025-12-17 11:11:43 -03:00
PULL_BASE_FROM_DOCKERHUB=false \
BUILD_BASE=true \
BUILDTRIVYADP=false \
BUILD_INSTALLER=true \
build
# Retag a few upstream image names to our internal naming convention
# (so Helm values can keep using `harbor-*` consistently).
2025-12-17 12:24:07 -03:00
docker tag "${IMAGE_NAMESPACE}/prepare:${VERSIONTAG}" "${IMAGE_NAMESPACE}/harbor-prepare:${VERSIONTAG}" || true
docker tag "${IMAGE_NAMESPACE}/redis-photon:${VERSIONTAG}" "${IMAGE_NAMESPACE}/harbor-redis:${VERSIONTAG}" || true
docker tag "${IMAGE_NAMESPACE}/nginx-photon:${VERSIONTAG}" "${IMAGE_NAMESPACE}/harbor-nginx:${VERSIONTAG}" || true
docker tag "${IMAGE_NAMESPACE}/registry-photon:${VERSIONTAG}" "${IMAGE_NAMESPACE}/harbor-registry:${VERSIONTAG}" || true
# Push every image we just built for this tag under our namespace.
docker images --format '{{.Repository}}:{{.Tag}}' \
2025-12-17 12:24:07 -03:00
| awk -v ns="${IMAGE_NAMESPACE}/" -v tag="${VERSIONTAG}" 'index($0, ns)==1 && $0 ~ ":"tag"$"' \
| sort -u \
| while read -r img; do
echo "Pushing ${img}"
docker push "${img}"
done
'''
2025-12-16 19:23:46 -03:00
}
}
}
}
2025-12-16 23:12:01 -03:00
post {
always { echo 'done' }
2025-12-16 23:12:01 -03:00
}
2025-12-16 19:23:46 -03:00
}