atlasbot/Jenkinsfile

179 lines
4.6 KiB
Plaintext
Raw Permalink Normal View History

2026-01-28 11:46:52 -03:00
pipeline {
agent {
kubernetes {
defaultContainer 'tester'
yaml """
apiVersion: v1
kind: Pod
spec:
nodeSelector:
kubernetes.io/arch: arm64
node-role.kubernetes.io/worker: "true"
containers:
- name: dind
image: docker:27-dind
securityContext:
privileged: true
env:
- name: DOCKER_TLS_CERTDIR
value: ""
args:
- "--mtu=1400"
- "--host=unix:///var/run/docker.sock"
- "--host=tcp://0.0.0.0:2375"
volumeMounts:
- name: dind-storage
mountPath: /var/lib/docker
- name: workspace-volume
mountPath: /home/jenkins/agent
- name: builder
image: docker:27
command:
- cat
tty: true
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
- name: DOCKER_TLS_CERTDIR
value: ""
volumeMounts:
- name: workspace-volume
mountPath: /home/jenkins/agent
- name: docker-config-writable
mountPath: /root/.docker
- name: harbor-config
mountPath: /docker-config
- name: tester
image: python:3.12-slim
command:
- cat
tty: true
volumeMounts:
- name: workspace-volume
mountPath: /home/jenkins/agent
volumes:
- name: docker-config-writable
emptyDir: {}
- name: dind-storage
emptyDir: {}
- name: harbor-config
secret:
2026-02-02 23:25:08 -03:00
secretName: harbor-bstein-robot
2026-01-28 11:46:52 -03:00
items:
- key: .dockerconfigjson
path: config.json
- name: workspace-volume
emptyDir: {}
"""
}
}
environment {
PIP_DISABLE_PIP_VERSION_CHECK = '1'
PYTHONUNBUFFERED = '1'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Prep toolchain') {
steps {
container('builder') {
sh '''
set -euo pipefail
mkdir -p /root/.docker
cp /docker-config/config.json /root/.docker/config.json
'''
}
}
}
stage('Compute version') {
steps {
container('builder') {
script {
2026-02-03 17:15:25 -03:00
def base = sh(returnStdout: true, script: 'cat VERSION_BASE 2>/dev/null || true').trim()
if (!base) {
base = "0.1.0"
2026-01-28 11:46:52 -03:00
}
2026-02-03 17:15:25 -03:00
def buildNum = env.BUILD_NUMBER?.trim()
if (!buildNum) {
buildNum = "0"
}
def semver = "${base}-${buildNum}"
2026-01-28 11:46:52 -03:00
sh "echo SEMVER=${semver} > build.env"
}
}
}
}
stage('Buildx setup') {
steps {
container('builder') {
sh '''
set -euo pipefail
seq 1 10 | while read _; do
docker info && break || sleep 2
done
docker buildx create --name bstein-builder --driver docker-container --bootstrap --use
'''
}
}
}
2026-02-03 19:08:26 -03:00
stage('Unit tests') {
steps {
container('builder') {
sh '''
set -euo pipefail
mkdir -p build
docker buildx build --platform linux/arm64 --target test --load -t atlasbot-test .
docker run --rm -v "$PWD/build:/out" atlasbot-test \
python -m ruff check atlasbot --select C90,PLR
docker run --rm -v "$PWD/build:/out" atlasbot-test \
python -m slipcover --json --out /out/coverage.json --source atlasbot --fail-under 90 \
-m pytest -q --junitxml /out/junit.xml
'''
}
}
}
stage('Publish test metrics') {
steps {
container('builder') {
sh '''
set -euo pipefail
2026-02-03 19:37:22 -03:00
docker run --rm -v "$PWD/build:/out" \
-e JUNIT_PATH=/out/junit.xml \
-e COVERAGE_PATH=/out/coverage.json \
atlasbot-test python scripts/publish_test_metrics.py
2026-02-03 19:08:26 -03:00
'''
}
}
}
2026-01-28 11:46:52 -03:00
stage('Build & push image') {
steps {
container('builder') {
sh '''
set -euo pipefail
VERSION_TAG=$(cut -d= -f2 build.env)
docker buildx build --platform linux/arm64 \
2026-02-03 19:08:26 -03:00
--target runtime \
2026-01-28 11:46:52 -03:00
--tag registry.bstein.dev/bstein/atlasbot:${VERSION_TAG} \
--tag registry.bstein.dev/bstein/atlasbot:latest \
--push .
'''
}
}
}
}
post {
always {
script {
if (fileExists('build.env')) {
def env = readProperties file: 'build.env'
echo "Build complete for ${env.SEMVER}"
}
}
archiveArtifacts artifacts: 'build/*', allowEmptyArchive: true
}
}
}