ci: Add Jenkins build pipeline
dustin/tmpl/pipeline/head There was a failure building this commit Details

We'll build and publish `tmpl` with a container image, to make it easier
for other container images to include it.
Dustin 2024-01-13 10:44:44 -06:00
parent 4c7192582d
commit 36f86b30cd
6 changed files with 116 additions and 0 deletions

4
.containerignore Normal file
View File

@ -0,0 +1,4 @@
*
!src
!Cargo.toml
!Cargo.lock

25
Containerfile Normal file
View File

@ -0,0 +1,25 @@
FROM registry.fedoraproject.org/fedora-minimal:39 AS build
RUN --mount=type=cache,target=/var/cache \
microdnf install -y \
--setopt install_weak_deps=0 \
cargo\
&& :
COPY . /src
WORKDIR /src
RUN cargo build --release --locked
FROM registry.fedoraproject.org/fedora-minimal:39
COPY --from=build /src/target/release/tmpl /usr/local/bin
ENTRYPOINT ["/usr/local/bin/tmpl"]
LABEL name='tmpl' \
vendor='Dustin C. Hatch' \
license='MIT OR APACHE-2.0' \
version='0.1.0'

64
ci/Jenkinsfile vendored Normal file
View File

@ -0,0 +1,64 @@
pipeline {
agent none
stages {
stage('tmpl') {
matrix {
axes {
axis {
name 'ARCH'
values 'amd64', 'arm64'
}
}
stages {
stage('tmpl') {
agent {
kubernetes {
yamlFile 'podTemplate.yaml'
yamlMergeStrategy merge()
defaultContainer 'build'
nodeSelector "kubernetes.io/arch=${ARCH}"
}
}
env {
REGISTRY_AUTH_FILE = "${env.WORKSPACE_TMP}/auth.json"
}
stages {
stage('Build') {
steps {
sh '. ci/build.sh'
}
post {
success {
archiveArtifacts "${ARCH}/*"
}
}
}
stage('Publish') {
steps {
withCredentials([usernamePassword(
credentialsId: 'jenkins-packages',
usernameVariable: 'BUILDAH_USERNAME',
passwordVariable: 'BUILDAH_PASSWORD',
)]) {
sh """
buildah login \
--username \${BUILDAH_USERNAME} \
--password \${BUILDAH_PASSWORD} \
git.pyrocufflink.net
"""
}
sh '. ci/publish.sh'
}
}
}
}
}
}
}
}
}

7
ci/build.sh Normal file
View File

@ -0,0 +1,7 @@
. ci/common.sh
buildah push "${IMAGE_NAME}:${TAG}"
buildah push "${IMAGE_NAME}:${TAG}" "${IMAGE_NAME}:${TAG}-${BUILD_NUMBER}"
if [ ${BRANCH_NAME} = master ]; then
buildah push "${IMAGE_NAME}:${TAG}" "${IMAGE_NAME}:latest"
fi

13
ci/common.sh Normal file
View File

@ -0,0 +1,13 @@
escape_name() {
echo "$1" \
| tr A-Z a-z \
| sed -e 's/[^a-zA-Z0-9._-]/-/g' -e 's/^[.-]/_/'
}
REGISTRY_URL=git.pyrocufflink.net
NAMESPACE=containerimages
NAME="${JOB_NAME#*/}"
NAME=$(escape_name "${NAME%/*}")
TAG=$(escape_name "${BRANCH_NAME}")
IMAGE_NAME="${REGISTRY_URL}/${NAMESPACE}/${NAME}"

3
ci/publish.sh Normal file
View File

@ -0,0 +1,3 @@
. ci/common.sh
buildah build -t "${IMAGE_NAME}:${TAG}" .