ci: build harbor images with dind

This commit is contained in:
bstein 2025-12-16 23:12:01 -03:00
parent 70f29e7582
commit def986a218

137
Jenkinsfile vendored
View File

@ -2,80 +2,127 @@ pipeline {
agent { agent {
kubernetes { kubernetes {
label 'harbor-arm-build' label 'harbor-arm-build'
defaultContainer 'git' defaultContainer 'builder'
yaml """ yaml """
apiVersion: v1 apiVersion: v1
kind: Pod kind: Pod
spec: spec:
securityContext:
runAsUser: 0
containers: containers:
- name: git - name: dind
image: alpine/git:2.45.2 image: docker:27-dind
command: ['cat'] securityContext:
tty: true privileged: true
env:
- name: DOCKER_TLS_CERTDIR
value: ""
args:
- --mtu=1400
- --insecure-registry=registry.bstein.dev
volumeMounts: volumeMounts:
- mountPath: /home/jenkins/agent - name: dind-storage
name: workspace-volume mountPath: /var/lib/docker
- name: kaniko - name: builder
image: gcr.io/kaniko-project/executor:v1.23.2-debug image: docker:27
command: ['cat'] command: ["cat"]
tty: true tty: true
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
- name: DOCKER_TLS_CERTDIR
value: ""
volumeMounts: volumeMounts:
- mountPath: /home/jenkins/agent - name: workspace-volume
name: workspace-volume mountPath: /home/jenkins/agent
- mountPath: /kaniko/.docker - name: dind-storage
name: docker-config mountPath: /var/lib/docker
volumes: volumes:
- name: workspace-volume - name: workspace-volume
emptyDir: {} emptyDir: {}
- name: docker-config - name: dind-storage
secret: emptyDir: {}
secretName: harbor-robot-pipeline
items:
- key: .dockerconfigjson
path: config.json
""" """
} }
} }
environment { environment {
REGISTRY = 'registry.bstein.dev' VERSION = 'v2.14.1'
IMAGE = 'infra/harbor-arm-build' TAG_SUFFIX = '-arm64'
REGISTRY = 'registry.bstein.dev/infra'
HARBOR_TARBALL = "https://github.com/goharbor/harbor/archive/refs/tags/${VERSION}.tar.gz"
}
options {
disableConcurrentBuilds()
} }
stages { stages {
stage('Checkout') { stage('Checkout Jenkinsfile') {
steps { steps {
container('git') {
git credentialsId: 'gitea-pat', url: 'https://scm.bstein.dev/bstein/harbor-arm-build.git' git credentialsId: 'gitea-pat', url: 'https://scm.bstein.dev/bstein/harbor-arm-build.git'
} }
} }
}
stage('Build & Push (kaniko)') { stage('Prep toolchain') {
steps { steps {
container('kaniko') { container('builder') {
sh ''' sh '''
set -euo pipefail set -euo pipefail
cat > app.sh <<'APP' apk add --no-cache bash curl make tar gzip git coreutils
#!/usr/bin/env bash '''
echo "hello harbor arm build $(date)" }
APP }
chmod +x app.sh }
cat > Dockerfile <<'DOCKER' stage('Fetch harbor source') {
FROM alpine:3.20 steps {
COPY app.sh /usr/local/bin/app.sh container('builder') {
RUN chmod +x /usr/local/bin/app.sh sh '''
ENTRYPOINT ["/usr/local/bin/app.sh"] set -euo pipefail
DOCKER rm -rf harbor-src
mkdir -p harbor-src
curl -sSL "${HARBOR_TARBALL}" | tar xz -C harbor-src
'''
}
}
}
/kaniko/executor \ stage('Build & push arm64 images') {
--context "${PWD}" \ environment {
--dockerfile "${PWD}/Dockerfile" \ VERSIONTAG = "${VERSION}${TAG_SUFFIX}"
--destination "${REGISTRY}/${IMAGE}:latest" \ }
--snapshotMode=redo \ steps {
--single-snapshot \ container('builder') {
--verbosity=info withCredentials([usernamePassword(credentialsId: 'harbor-robot', passwordVariable: 'HPASS', usernameVariable: 'HUSER')]) {
sh '''
set -euo pipefail
SRC_DIR=$(find harbor-src -maxdepth 1 -type d -name "harbor-*" | head -n1)
cd "${SRC_DIR}"
docker login -u "${HUSER}" -p "${HPASS}" "$(echo "${REGISTRY}" | cut -d/ -f1)"
export VERSIONTAG="${VERSIONTAG}"
export BASEIMAGETAG="${VERSIONTAG}"
export IMAGENAMESPACE="${REGISTRY}"
export BASEIMAGENAMESPACE="${REGISTRY}"
export PULL_BASE_FROM_DOCKERHUB=false
export BUILD_BASE=true
export PUSHBASEIMAGE=true
export BUILDTRIVYADP=false
export BUILD_INSTALLER=false
export REGISTRYUSER="${HUSER}"
export REGISTRYPASSWORD="${HPASS}"
make compile
make build
make pushimage
''' '''
} }
} }
} }
} }
}
post {
always {
cleanWs()
}
}
} }