Skip to content

Commit

Permalink
Add CI support for building Agent containers
Browse files Browse the repository at this point in the history
PBENCH-332
  • Loading branch information
webbnh committed Jan 13, 2023
1 parent f2a0f33 commit bfe23fe
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 29 deletions.
12 changes: 11 additions & 1 deletion agent/containers/images/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ _PBENCH_REPO_NAME = pbench-${_LOCAL_MAJORMINOR}${_TEST_SUFFIX}
# By default we use the pbench Quay.io organization for the image
# repository. You can override this default using an environment
# variable as appropriate.
IMAGE_REPO = docker://quay.io/pbench
IMAGE_REPO ?= docker://quay.io/pbench
IMAGE_TAG ?= latest

# Convenience reference to the repo template in the pbench tree.
# Not intended to be overridden with an environment variable.
Expand Down Expand Up @@ -293,6 +294,15 @@ centos-7-base.Dockerfile: _PKGMGR = yum
# Push local images for the given tag and distribution.
#-

# Special push target for the CI which pushes all the container images for the
# distribution to the specified registry with the specified tag.
$(_DEFAULT_DISTROS:%=%-push-ci): %-push-ci:
for image in base tools tool-meister tool-data-sink workloads all; do \
buildah push \
localhost/pbench-agent-$${image}-${*}:${_LOCAL_GIT_HASH} \
${IMAGE_REPO}/pbench-agent-$${image}-${*}:${IMAGE_TAG} ; \
done

define _PUSH_RULE
%-push-$(1): %-tags.lis
./push ${IMAGE_REPO} $$* $(1)
Expand Down
69 changes: 49 additions & 20 deletions jenkins/Pipeline.gy
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,18 @@ pipeline {
PY_COLORS=0
TERM='dumb'

// The remaining variables are for `jenkins/run-server-func-tests`.

// Configuration for remote container registries
PODMAN_INTERNAL=credentials('12b404ca-3036-4960-9929-979148b9e49a')
KEYCLOAK_CLIENT_SECRET=credentials('5cf0304d-8a00-48a4-ade5-9f59cb37ba68')
PB_CONTAINER_REG=credentials('c3e2d737-0e56-4c1e-a945-d86bc644384c')

PODMAN_EXTERNAL=credentials('87ad2797-02eb-464f-989f-8ab78d63cdf3')
PB_INTERNAL_CONTAINER_REG=credentials('c3e2d737-0e56-4c1e-a945-d86bc644384c')
PB_EXTERNAL_CONTAINER_REG=credentials('24a93506-ecd6-403a-b4f0-386f9cc943e9')
PB_ORG_NAME="pbench"

PB_SERVER_IMAGE_NAME="pbench-server-ci"
// Set the tag to the PR number (i.e., the Jenkins CHANGE_ID) if run for
// a PR; otherwise set it to the branch name (e.g., `main`). Set a
// shorthand for the Pbench Server image path, and set a variable for
// the Server Pod name, based on the image tag, so that we don't
// interfere with other pods on this executor.
PB_SERVER_IMAGE_TAG="""${sh(
returnStdout: true,
script: 'echo ${CHANGE_ID:-${BRANCH_NAME}}'
)}""".trim()

PB_DASHBOARD_DIR="${WORKSPACE}/dashboard/build/"
// If we are executing for a PR, as opposed to executing for a branch
// like `main`, the CHANGE_ID will be defined to the PR number. If it
// is defined we'll use its value for the container image tag;
// otherwise we set it to the branch name (e.g., `main`).
PB_IMAGE_TAG="${env.CHANGE_ID ?: env.BRANCH_NAME}"
}
stages {
stage('Agent Python3.6 Check') {
Expand All @@ -50,14 +42,51 @@ pipeline {
}
}
stage('Build the Pbench Server Container') {
environment {
KEYCLOAK_CLIENT_SECRET=credentials('5cf0304d-8a00-48a4-ade5-9f59cb37ba68')
}
steps {
sh 'buildah login -u="${PODMAN_INTERNAL_USR}" -p="${PODMAN_INTERNAL_PSW}" ${PB_CONTAINER_REG}'
sh 'buildah login -u="${PODMAN_INTERNAL_USR}" -p="${PODMAN_INTERNAL_PSW}" ${PB_INTERNAL_CONTAINER_REG}'
sh 'RPM_PATH=${WORKSPACE_TMP}/rpmbuild/RPMS/noarch/pbench-server-*.rpm bash -ex ./server/pbenchinacan/container-build-ci.sh'
sh 'buildah push localhost/pbench-server:${PB_SERVER_IMAGE_TAG} ${PB_CONTAINER_REG}/${PB_ORG_NAME}/pbench-server:${PB_SERVER_IMAGE_TAG}'
sh 'buildah push localhost/${PB_SERVER_IMAGE_NAME}:${PB_SERVER_IMAGE_TAG} ${PB_CONTAINER_REG}/${PB_ORG_NAME}/${PB_SERVER_IMAGE_NAME}:${PB_SERVER_IMAGE_TAG}'
sh 'buildah push localhost/pbench-server:${PB_IMAGE_TAG} ${PB_INTERNAL_CONTAINER_REG}/${PB_ORG_NAME}/pbench-server:${PB_IMAGE_TAG}'
sh 'buildah push localhost/${PB_SERVER_IMAGE_NAME}:${PB_IMAGE_TAG} ${PB_INTERNAL_CONTAINER_REG}/${PB_ORG_NAME}/${PB_SERVER_IMAGE_NAME}:${PB_IMAGE_TAG}'
}
}
stage('Build the Pbench Agent Containers') {
environment {
// If CHANGE_ID is defined, then we are building a PR, so use
// the internal container registry; otherwise, we are building
// a branch (like `main`), so use the external registry.
PB_AGENT_CONTAINER_REG="${env.CHANGE_ID ? env.PB_INTERNAL_CONTAINER_REG : env.PB_EXTERNAL_CONTAINER_REG}"
PB_AGENT_DISTRO="fedora-36"
}
stages {
stage('Login to external container registry') {
when { equals expected: env.PB_EXTERNAL_CONTAINER_REG, actual: env.PB_AGENT_CONTAINER_REG }
steps {
sh 'buildah login -u="${PODMAN_EXTERNAL_USR}" -p="${PODMAN_EXTERNAL_PSW}" ${PB_EXTERNAL_CONTAINER_REG}'
}
}
stage('Login to internal container registry') {
when { equals expected: env.PB_INTERNAL_CONTAINER_REG, actual: env.PB_AGENT_CONTAINER_REG }
steps {
sh 'buildah login -u="${PODMAN_INTERNAL_USR}" -p="${PODMAN_INTERNAL_PSW}" ${PB_INTERNAL_CONTAINER_REG}'
}
}
stage('Do the build') {
steps {
sh '/usr/bin/python3 -m pip install --user jinja2-cli'
sh 'make -C agent/containers/images CI_RPM_ROOT=${WORKSPACE_TMP} clean ${PB_AGENT_DISTRO}-everything'
sh 'make -C agent/containers/images IMAGE_REPO=${PB_AGENT_CONTAINER_REG}/${PB_ORG_NAME} IMAGE_TAG=${PB_IMAGE_TAG} ${PB_AGENT_DISTRO}-push-ci'
}
}
}
}
stage('Deploy server and run functional tests') {
environment {
PB_CONTAINER_REG="${PB_INTERNAL_CONTAINER_REG}"
PB_DASHBOARD_DIR="${WORKSPACE}/dashboard/build/"
}
steps {
sh 'jenkins/run-server-func-tests --cleanup'
}
Expand Down
4 changes: 2 additions & 2 deletions jenkins/run-server-func-tests
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export IMAGE_KIND=${IMAGE_KIND:-"fedora"}
export IMAGE_REPO=${IMAGE_REPO:-"quay.io/pbench"}
export IMAGE_ROLE=${IMAGE_ROLE:-"ci"}

export PB_SERVER_IMAGE_TAG=${PB_SERVER_IMAGE_TAG:-"$(cat jenkins/branch.name)"}
export PB_POD_NAME=${PB_POD_NAME:-"pbench-in-a-can_${PB_SERVER_IMAGE_TAG}"}
export PB_IMAGE_TAG=${PB_IMAGE_TAG:-"$(cat jenkins/branch.name)"}
export PB_POD_NAME=${PB_POD_NAME:-"pbench-in-a-can_${PB_IMAGE_TAG}"}

function cleanup {
# Remove the pod which we just created and ran; remove any dangling
Expand Down
4 changes: 2 additions & 2 deletions jenkins/runlocal
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export PB_CONTAINER_REG=images.paas.redhat.com
export PB_ORG_NAME=pbench
export PB_SERVER_IMAGE_NAME=pbench-server-ci
export PB_SERVER_IMAGE_TAG=${USER}
export PB_IMAGE_TAG=${USER}
export PB_DASHBOARD_DIR=$(pwd)/dashboard/build

make -C server/rpm clean rpm
Expand All @@ -24,6 +24,6 @@ make -C server/rpm clean rpm
# $ buildah login -u='$app' -p="${__LOGIN_SECRET__}" ${PB_CONTAINER_REG}

RPM_PATH=${HOME}/rpmbuild/RPMS/noarch/pbench-server-*.rpm bash -ex ./server/pbenchinacan/container-build-ci.sh
buildah push localhost/${PB_SERVER_IMAGE_NAME}:${PB_SERVER_IMAGE_TAG} ${PB_CONTAINER_REG}/${PB_ORG_NAME}/${PB_SERVER_IMAGE_NAME}:${PB_SERVER_IMAGE_TAG}
buildah push localhost/${PB_SERVER_IMAGE_NAME}:${PB_IMAGE_TAG} ${PB_CONTAINER_REG}/${PB_ORG_NAME}/${PB_SERVER_IMAGE_NAME}:${PB_IMAGE_TAG}

jenkins/run-server-func-tests
4 changes: 2 additions & 2 deletions server/pbenchinacan/container-build-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PBINC_DIR=${PBINC_SERVER}/pbenchinacan

# Open a copy of the base pbench server container. Docker format is required
# in order to set the hostname.
container=$(buildah from --format=docker pbench-server:${PB_SERVER_IMAGE_TAG})
container=$(buildah from --format=docker pbench-server:${PB_IMAGE_TAG})

buildah config \
--label maintainer="Pbench Maintainers <[email protected]>" \
Expand Down Expand Up @@ -54,4 +54,4 @@ buildah run $container cp /usr/share/nginx/html/404.html /usr/share/nginx/html/5
buildah run $container chown --recursive pbench:pbench /srv/pbench

# Create the container image
buildah commit $container localhost/${PB_SERVER_IMAGE_NAME}:${PB_SERVER_IMAGE_TAG}
buildah commit $container localhost/${PB_SERVER_IMAGE_NAME}:${PB_IMAGE_TAG}
4 changes: 2 additions & 2 deletions server/pbenchinacan/container-build-sa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GITTOP=${GITTOP:-$(git rev-parse --show-toplevel)}

PBINC_SERVER=${GITTOP}/server
# Image tag determined from jenkins/branch.name
PB_SERVER_IMAGE_TAG=${PB_SERVER_IMAGE_TAG:-$(< ${GITTOP}/jenkins/branch.name)}
PB_IMAGE_TAG=${PB_IMAGE_TAG:-$(< ${GITTOP}/jenkins/branch.name)}

# Locations inside the container
INSTALL_ROOT=/opt/pbench-server
Expand Down Expand Up @@ -80,4 +80,4 @@ buildah run $container systemctl enable rsyslog
buildah run $container systemctl enable pbench-server

# Create the container image.
buildah commit $container localhost/pbench-server:${PB_SERVER_IMAGE_TAG}
buildah commit $container localhost/pbench-server:${PB_IMAGE_TAG}

0 comments on commit bfe23fe

Please sign in to comment.