pipeline { agent { kubernetes { defaultContainer 'python' yaml """ apiVersion: v1 kind: Pod metadata: labels: atlas.bstein.dev/workload: hermes-chat-router-image-builder spec: serviceAccountName: hermes-image-builder automountServiceAccountToken: false enableServiceLinks: false restartPolicy: Never securityContext: fsGroup: 1000 fsGroupChangePolicy: OnRootMismatch nodeSelector: kubernetes.io/arch: arm64 affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: [titan-20] imagePullSecrets: - name: harbor-bstein-robot containers: - name: jnlp image: jenkins/inbound-agent@sha256:8eda4fe2a66bcf6a5e43436d9918fc14c306204dc8fcd75f4e15e0e6e5dc759a securityContext: allowPrivilegeEscalation: false capabilities: drop: ["ALL"] runAsNonRoot: true runAsUser: 1000 seccompProfile: type: RuntimeDefault resources: requests: {cpu: 25m, memory: 128Mi} limits: {cpu: 500m, memory: 512Mi} - name: python image: registry.bstein.dev/bstein/python@sha256:269541d3387baae008df4608ead893dba2b5cdaad1a5a380731a88992d34b808 command: ["sleep"] args: ["99d"] tty: true securityContext: allowPrivilegeEscalation: false capabilities: drop: ["ALL"] runAsNonRoot: true runAsUser: 1000 seccompProfile: type: RuntimeDefault resources: requests: {cpu: 25m, memory: 64Mi} limits: {cpu: 250m, memory: 256Mi} - name: golang image: golang:1.24-alpine@sha256:8bee1901f1e530bfb4a7850aa7a479d17ae3a18beb6e09064ed54cfd245b7191 command: ["sleep"] args: ["99d"] tty: true env: - {name: GOCACHE, value: /tmp/go-cache} securityContext: allowPrivilegeEscalation: false capabilities: drop: ["ALL"] runAsNonRoot: true runAsUser: 1000 seccompProfile: type: RuntimeDefault resources: requests: {cpu: 100m, memory: 128Mi} limits: {cpu: "1", memory: 1Gi} - name: kaniko image: gcr.io/kaniko-project/executor@sha256:c3109d5926a997b100c4343944e06c6b30a6804b2f9abe0994d3de6ef92b028e command: ["/busybox/sh", "-c"] args: ["/busybox/sleep 99d"] tty: true securityContext: allowPrivilegeEscalation: false capabilities: drop: ["ALL"] add: ["CHOWN", "FOWNER", "DAC_OVERRIDE", "SETGID", "SETUID"] privileged: false runAsUser: 0 seccompProfile: type: RuntimeDefault resources: requests: cpu: 100m memory: 256Mi ephemeral-storage: 2Gi limits: cpu: "1" memory: 2Gi ephemeral-storage: 5Gi """ } } parameters { booleanParam( name: 'PUBLISH_IMAGE', defaultValue: false, description: 'Publish the reviewed main revision to Harbor.' ) string( name: 'EXPECTED_SOURCE_REVISION', defaultValue: '', description: 'Full reviewed commit that must be contained by titan/atlas-iac main.' ) string( name: 'CONFIRM_PUBLISH', defaultValue: '', description: 'Enter PUBLISH HERMES CHAT ROUTER to confirm the release.' ) } environment { HERMES_IMAGE = 'registry.bstein.dev/bstein/hermes-chat-router' } options { disableConcurrentBuilds() buildDiscarder(logRotator(daysToKeepStr: '30', numToKeepStr: '100', artifactDaysToKeepStr: '30', artifactNumToKeepStr: '100')) skipDefaultCheckout(true) timeout(time: 45, unit: 'MINUTES') } stages { stage('Checkout reviewed source') { steps { checkout scm } } stage('Enforce release boundary') { steps { container('jnlp') { sh ''' set -eu mkdir -p build test "${PUBLISH_IMAGE}" = "true" test "${CONFIRM_PUBLISH}" = "PUBLISH HERMES CHAT ROUTER" case "${EXPECTED_SOURCE_REVISION}" in *[!0-9a-f]*|'') echo "EXPECTED_SOURCE_REVISION must be a lowercase full commit" >&2 exit 2 ;; esac test "${#EXPECTED_SOURCE_REVISION}" -eq 40 main_revision="$(git rev-parse HEAD)" test "${main_revision}" = "$(git rev-parse origin/main)" git merge-base --is-ancestor "${EXPECTED_SOURCE_REVISION}" "${main_revision}" git checkout --detach "${EXPECTED_SOURCE_REVISION}" actual_revision="$(git rev-parse HEAD)" test "${actual_revision}" = "${EXPECTED_SOURCE_REVISION}" test -z "$(git status --porcelain)" test -f dockerfiles/Dockerfile.hermes-chat-router case "${BUILD_NUMBER}" in ''|0*|*[!0-9]*) echo "BUILD_NUMBER must be a positive decimal integer" >&2 exit 2 ;; esac printf '%s\n' \ "${HERMES_IMAGE}:git-${actual_revision}-build-${BUILD_NUMBER}" \ > build/hermes-chat-router.destination printf '%s\n' "${actual_revision}" \ > build/hermes-chat-router.source-revision ''' } } } stage('Validate reviewed router source') { steps { container('python') { sh ''' set -eu python3 -m pip install --disable-pip-version-check --no-cache-dir \ --target=/tmp/hermes-chat-router-test-deps \ pytest==8.3.4 PyYAML==6.0.2 PYTHONPATH=/tmp/hermes-chat-router-test-deps \ python3 -m pytest -q \ testing/tests/test_hermes_chat_router_release.py \ testing/tests/test_hermes_oci_promote.py \ testing/tests/test_hermes_image_automation.py ''' } container('golang') { sh ''' set -eu cd services/hermes/router GO111MODULE=off CGO_ENABLED=0 go test ./... ''' } } } stage('Reject replay before publish') { steps { withCredentials([usernamePassword( credentialsId: 'harbor-robot', usernameVariable: 'HARBOR_USER', passwordVariable: 'HARBOR_PASSWORD' )]) { sh ''' set -eu set +x destination="$(cat build/hermes-chat-router.destination)" source_revision="$(cat build/hermes-chat-router.source-revision)" python3 ci/scripts/hermes_chat_router_release.py assert-absent \ --source-revision "${source_revision}" \ --build-number "${BUILD_NUMBER}" \ --destination "${destination}" ''' } } } stage('Build and publish without a daemon') { steps { container('kaniko') { withCredentials([usernamePassword( credentialsId: 'harbor-robot', usernameVariable: 'HARBOR_USER', passwordVariable: 'HARBOR_PASSWORD' )]) { sh '''#!/busybox/sh set -eu set +x config_path=/kaniko/.docker/config.json destination="$(cat build/hermes-chat-router.destination)" source_revision="$(cat build/hermes-chat-router.source-revision)" umask 077 auth="$(printf '%s:%s' "${HARBOR_USER}" "${HARBOR_PASSWORD}" | /busybox/base64 | /busybox/tr -d '\n')" /busybox/mkdir -p /kaniko/.docker /busybox/printf '{"auths":{"registry.bstein.dev":{"auth":"%s"}}}\n' "${auth}" > "${config_path}" unset HARBOR_USER HARBOR_PASSWORD auth trap '/busybox/rm -f "${config_path}"' EXIT HUP INT TERM umask 022 /kaniko/executor \ --registry-mirror=harbor-core.harbor.svc.cluster.local \ --insecure-registry=harbor-core.harbor.svc.cluster.local \ --context="dir://${WORKSPACE}" \ --dockerfile="${WORKSPACE}/dockerfiles/Dockerfile.hermes-chat-router" \ --destination="${destination}" \ --digest-file="${WORKSPACE}/build/hermes-chat-router.digest" \ --image-name-tag-with-digest-file="${WORKSPACE}/build/hermes-chat-router.image" \ --label="org.opencontainers.image.revision=${source_revision}" \ --label="org.opencontainers.image.source=https://scm.bstein.dev/titan/atlas-iac" \ --label="org.opencontainers.image.title=hermes-chat-router" \ --cleanup \ --push-retry=3 /busybox/chmod 644 \ build/hermes-chat-router.digest build/hermes-chat-router.image ''' } } } } stage('Render reviewed Flux handoff') { steps { withCredentials([usernamePassword( credentialsId: 'harbor-robot', usernameVariable: 'HARBOR_USER', passwordVariable: 'HARBOR_PASSWORD' )]) { sh ''' set -eu set +x destination="$(cat build/hermes-chat-router.destination)" source_revision="$(cat build/hermes-chat-router.source-revision)" python3 ci/scripts/hermes_chat_router_release.py render \ --digest-file build/hermes-chat-router.digest \ --image-file build/hermes-chat-router.image \ --source-revision "${source_revision}" \ --build-number "${BUILD_NUMBER}" \ --destination "${destination}" \ --manifest services/hermes/chat-router.yaml \ --output-dir build/hermes-chat-router-release ''' } } } stage('Verify and archive release evidence') { steps { sh ''' set -eu expected_files="$(printf '%s\n' \ build/hermes-chat-router.destination \ build/hermes-chat-router.digest \ build/hermes-chat-router.image \ build/hermes-chat-router.source-revision \ build/hermes-chat-router-release/hermes-chat-router-deployment.yaml \ build/hermes-chat-router-release/hermes-chat-router-image-update.patch \ build/hermes-chat-router-release/hermes-chat-router-image.json \ | LC_ALL=C sort)" actual_files="$(find build -type f -print | LC_ALL=C sort)" test "${actual_files}" = "${expected_files}" destination="$(cat build/hermes-chat-router.destination)" source_revision="$(cat build/hermes-chat-router.source-revision)" python3 ci/scripts/hermes_chat_router_release.py verify-evidence \ --digest-file build/hermes-chat-router.digest \ --image-file build/hermes-chat-router.image \ --source-revision "${source_revision}" \ --build-number "${BUILD_NUMBER}" \ --destination "${destination}" \ --manifest services/hermes/chat-router.yaml \ --output-dir build/hermes-chat-router-release ''' archiveArtifacts( artifacts: 'build/hermes-chat-router.destination,build/hermes-chat-router.digest,build/hermes-chat-router.image,build/hermes-chat-router.source-revision,build/hermes-chat-router-release/hermes-chat-router-deployment.yaml,build/hermes-chat-router-release/hermes-chat-router-image-update.patch,build/hermes-chat-router-release/hermes-chat-router-image.json', allowEmptyArchive: false, fingerprint: true ) } } stage('Publish Flux release tag') { steps { withCredentials([usernamePassword( credentialsId: 'harbor-robot', usernameVariable: 'HARBOR_USER', passwordVariable: 'HARBOR_PASSWORD' )]) { sh ''' set -eu set +x destination="$(cat build/hermes-chat-router.destination)" source_revision="$(cat build/hermes-chat-router.source-revision)" python3 ci/scripts/hermes_oci_promote.py \ --destination "${destination}" \ --digest-file build/hermes-chat-router.digest \ --source-revision "${source_revision}" \ --build-number "${BUILD_NUMBER}" ''' } } } } }