Skip to content

Commit

Permalink
Create method to build stand-alone pbench server
Browse files Browse the repository at this point in the history
We modify the Pbench-in-a-Can build process to first create a
stand-alone Pbench Server container image, and then build an image based
on that image which is used for the CI environment.
  • Loading branch information
portante committed Nov 22, 2022
1 parent 448cb4a commit 8ef5b98
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 137 deletions.
6 changes: 3 additions & 3 deletions jenkins/Pipeline.gy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pipeline {
PB_ELASTICSEARCH_IMAGE_TAG="7.13.3"
PB_POSTGRESQL_IMAGE_NAME="postgresql-13"
PB_POSTGRESQL_IMAGE_TAG="latest"
PB_SERVER_IMAGE_NAME="pbench-server"
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
Expand Down Expand Up @@ -58,8 +58,8 @@ pipeline {
stage('Build the Pbench Server Container') {
steps {
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.sh'
sh 'buildah push localhost/pbench-server:${PB_SERVER_IMAGE_TAG} ${PB_CONTAINER_REG}/${PB_REPO_NAME}/${PB_SERVER_IMAGE_NAME}:${PB_SERVER_IMAGE_TAG}'
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-ci:${PB_SERVER_IMAGE_TAG} ${PB_CONTAINER_REG}/${PB_REPO_NAME}/${PB_SERVER_IMAGE_NAME}:${PB_SERVER_IMAGE_TAG}'
}
}
stage('Deploy server and run functional tests') {
Expand Down
4 changes: 2 additions & 2 deletions server/lib/config/pbench.httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# NOTE: while this file should work as-is, using the routable hostname
# or IP is highly recommended. The pbench-in-a-can container deployment will
# filter this file, replacing the local host placeholder with the full IP:
# pay attention to server/pbenchinacan/container-build.sh when editing this!
# pay attention to server/pbenchinacan/container-build-ci.sh when editing this!
#
<VirtualHost *:80>
ProxyPreserveHost On
Expand All @@ -31,7 +31,7 @@
ProxyPass / !
</VirtualHost>

# Our use of the Apache2 instance in our local setup will send logs to syslog.
# By default, we force the Apache2 instance to emit all logs via syslog.
ErrorLog "| /usr/bin/logger -thttpd -plocal6.err"
<IfModule log_config_module>
CustomLog "| /usr/bin/logger -thttpd -plocal6.notice" combined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@

set -o errexit

#+
# Configuration definition section.
#-

# Main inputs to the container build process
BASE_IMAGE=${BASE_IMAGE:-registry.access.redhat.com/ubi9:latest}
RPM_PATH=${RPM_PATH:-/root/sandbox/rpmbuild/RPMS/noarch/pbench-server-*.rpm}
# First we create the stand-alone Pbench Server container image.
. $(dirname ${0})/container-build-sa.sh

# Locations inside the container
INSTALL_ROOT=/opt/pbench-server
Expand All @@ -28,54 +23,17 @@ CONF_PATH=${SERVER_LIB}/config/pbench-server.cfg
HOSTNAME_F=pbenchinacan

# Locations on the host
GITTOP=${GITTOP:-$(git rev-parse --show-toplevel)}
PBINC_SERVER=${GITTOP}/server
PBINC_DIR=${PBINC_SERVER}/pbenchinacan

# Image tag to use, default determined from jenkins/branch.name
PB_SERVER_IMAGE_TAG=${PB_SERVER_IMAGE_TAG:-$(< ${GITTOP}/jenkins/branch.name)}

#+
# Configuration verification section.
#-

if (( $(ls ${RPM_PATH} 2>/dev/null | wc -l) != 1 ))
then
echo "RPM_PATH (${RPM_PATH}) does not uniquely identify the RPM file" >&2
exit 2
fi

#+
# Container build section.
#-
# 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})

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

# We could mount the container filesystem and access it directly, but we
# instead access it with buildah commands.
# mnt=$(buildah mount $container)

# Consider adding -v datavolume for the Server data, and perhaps SQL and ES data
buildah config \
--label maintainer="Webb Scales <wscales@redhat.com>" \
--label maintainer="Pbench Maintainers <pbench@googlegroups.com>" \
--hostname $HOSTNAME_F \
--stop-signal SIGINT \
--port 8001 `# pbench-server` \
$container

buildah copy $container ${RPM_PATH} /tmp/pbench-server.rpm
buildah copy $container ${PBINC_SERVER}/requirements.txt /tmp
buildah run $container dnf update -y
buildah run $container dnf install -y --setopt=tsflags=nodocs \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
buildah run $container dnf install -y /tmp/pbench-server.rpm httpd
# FIXME: Should we be running Pip with the --user switch under the `pbench` user?
buildah run $container pip install -r /tmp/requirements.txt
buildah run $container dnf clean all
buildah run $container rm -f /tmp/pbench-server.rpm /tmp/requirements.txt

# Skip installing and configuring the Firewall

# Work around a problem with cron running jobs as other users in a container.
Expand Down Expand Up @@ -127,4 +85,4 @@ buildah run $container systemctl enable httpd
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-ci:${PB_SERVER_IMAGE_TAG}
60 changes: 60 additions & 0 deletions server/pbenchinacan/container-build-sa.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
#
# This script builds a stand-alone Pbench Server container with just the base
# software installed.
#

set -o errexit

#+
# Configuration definition section.
#-

BASE_IMAGE=${BASE_IMAGE:-registry.access.redhat.com/ubi9:latest}
RPM_PATH=${RPM_PATH:-/root/sandbox/rpmbuild/RPMS/noarch/pbench-server-*.rpm}

HOSTNAME_F=pbench-server

# Locations on the host
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)}

#+
# Configuration verification section.
#-

if (( $(ls ${RPM_PATH} 2>/dev/null | wc -l) != 1 ))
then
echo "RPM_PATH (${RPM_PATH}) does not uniquely identify the RPM file" >&2
exit 2
fi

#+
# Container build section.
#-

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

# Provide a few useful defaults for labels and the host name to use, and expose
# port 80 for the Apache2 httpd process acting as a proxy.
buildah config \
--label maintainer="Pbench Maintainers <[email protected]>" \
--hostname $HOSTNAME_F \
--port 80 `# pbench-server` \
$container

buildah copy $container ${RPM_PATH} /tmp/pbench-server.rpm
buildah run $container dnf update -y
buildah run $container dnf install -y --setopt=tsflags=nodocs \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
buildah run $container dnf install -y /tmp/pbench-server.rpm httpd
buildah run $container dnf clean all
buildah run $container rm -f /tmp/pbench-server.rpm

# Create the container image
buildah commit $container localhost/pbench-server:${PB_SERVER_IMAGE_TAG}
83 changes: 0 additions & 83 deletions server/pbenchinacan/pbench-server-only.yml

This file was deleted.

0 comments on commit 8ef5b98

Please sign in to comment.