Skip to content

Commit

Permalink
docker checks: update script from core
Browse files Browse the repository at this point in the history
  • Loading branch information
trws committed Aug 7, 2023
1 parent f905243 commit ac8b26c
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions src/test/docker/docker-run-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
PROJECT=flux-sched
BASE_DOCKER_REPO=fluxrm/flux-core

WORKDIR=/usr/src
IMAGE=jammy
JOBS=2
MOUNT_HOME_ARGS="--volume=$HOME:/home/$USER -e HOME"

if test "$PROJECT" = "flux-core"; then
FLUX_SECURITY_VERSION=0.4.0
FLUX_SECURITY_VERSION=0.9.0
POISON=t
fi

Expand All @@ -24,8 +25,8 @@ declare -r prog=${0##*/}
die() { echo -e "$prog: $@"; exit 1; }

#
declare -r long_opts="help,quiet,interactive,image:,flux-security-version:,jobs:,no-cache,no-home,distcheck,tag:,build-directory:,install-only,no-poison,recheck,inception"
declare -r short_opts="hqIdi:S:j:t:D:Pr"
declare -r long_opts="help,quiet,interactive,image:,flux-security-version:,jobs:,no-cache,no-home,distcheck,tag:,build-directory:,install-only,no-poison,recheck,unit-test-only,inception,platform:,workdir:,system"
declare -r short_opts="hqIdi:S:j:t:D:Prup:"
declare -r usage="
Usage: $prog [OPTIONS] -- [CONFIGURE_ARGS...]\n\
Build docker image for CI builds, then run tests inside the new\n\
Expand All @@ -39,26 +40,30 @@ Options:\n\
--no-home Skip mounting the host home directory\n\
--install-only Skip make check, only make install\n\
--inception Run tests as flux jobs\n\
--system Run under system instance\n\
-q, --quiet Add --quiet to docker-build\n\
-t, --tag=TAG If checks succeed, tag image as NAME\n\
-i, --image=NAME Use base docker image NAME (default=$IMAGE)\n\
-p, --platform=NAME Run on alternate platform (if supported)\n\
-S, --flux-security-version=N Install flux-security vers N (default=$FLUX_SECURITY_VERSION)\n
-j, --jobs=N Value for make -j (default=$JOBS)\n
-d, --distcheck Run 'make distcheck' instead of 'make check'\n\
-r, --recheck Run 'make recheck' after failure\n\
-u, --unit-test-only Only run unit tests\n\
-P, --no-poison Do not install poison libflux and flux(1)\n\
-D, --build-directory=DIRNAME Name of a subdir to build in, will be made\n\
--workdir=PATH Use PATH as working directory for build\n\
-I, --interactive Instead of running ci build, run docker\n\
image with interactive shell.\n\
"

# check if running in OSX
if [[ "$(uname)" == "Darwin" ]]; then
# BSD getopt
GETOPTS=`/usr/bin/getopt $short_opts -- $*`
GETOPTS=`getopt $short_opts -- $*`
else
# GNU getopt
GETOPTS=`/usr/bin/getopt -u -o $short_opts -l $long_opts -n $prog -- $@`
GETOPTS=`getopt -u -o $short_opts -l $long_opts -n $prog -- $@`
if [[ $? != 0 ]]; then
die "$usage"
fi
Expand All @@ -69,16 +74,21 @@ while true; do
-h|--help) echo -ne "$usage"; exit 0 ;;
-q|--quiet) QUIET="--quiet"; shift ;;
-i|--image) IMAGE="$2"; shift 2 ;;
-p|--platform) PLATFORM="--platform=$2"; shift 2 ;;
-S|--flux-security-version) FLUX_SECURITY_VERSION="$2"; shift 2 ;;
-j|--jobs) JOBS="$2"; shift 2 ;;
-I|--interactive) INTERACTIVE="/bin/bash"; shift ;;
-d|--distcheck) DISTCHECK=t; shift ;;
-r|--recheck) RECHECK=t; shift ;;
-u|--unit-test-only) UNIT_TEST_ONLY=t; shift ;;
-D|--build-directory) BUILD_DIR="$2"; shift 2 ;;
--build-arg) BUILD_ARG=" --build-arg $2" shift 2 ;;
--workdir) WORKDIR="$2"; shift 2 ;;
--no-cache) NO_CACHE="--no-cache"; shift ;;
--no-home) MOUNT_HOME_ARGS=""; shift ;;
--install-only) INSTALL_ONLY=t; shift ;;
--inception) INCEPTION=t; shift ;;
--system) SYSTEM=t; shift ;;
-P|--no-poison) POISON=0; shift ;;
-t|--tag) TAG="$2"; shift 2 ;;
--) shift; break; ;;
Expand All @@ -90,10 +100,16 @@ TOP=$(git rev-parse --show-toplevel 2>&1) \
|| die "not inside $PROJECT git repository!"
which docker >/dev/null \
|| die "unable to find a docker binary"
if docker buildx >/dev/null 2>&1; then
DOCKER_BUILD="docker buildx build --load"
else
DOCKER_BUILD="docker build"
fi

# distcheck incompatible with some configure args
if test "$DISTCHECK" = "t"; then
test "$RECHECK" = "t" && die "--recheck not allowed with --distcheck"
test "$SYSTEM" = "t" && die "--system not allowed with --distcheck"
for arg in "$@"; do
case $arg in
--sysconfdir=*|systemdsystemunitdir=*)
Expand All @@ -117,7 +133,8 @@ else
fi

checks_group "Building image $IMAGE for user $USER $(id -u) group=$(id -g)" \
docker build \
${DOCKER_BUILD} \
${PLATFORM} \
${NO_CACHE} \
${QUIET} \
--build-arg BASE_IMAGE=$IMAGE \
Expand All @@ -126,28 +143,33 @@ checks_group "Building image $IMAGE for user $USER $(id -u) group=$(id -g)" \
--build-arg UID=$(id -u) \
--build-arg GID=$(id -g) \
--build-arg FLUX_SECURITY_VERSION=$FLUX_SECURITY_VERSION \
${BUILD_ARG:- } \
-t ${BUILD_IMAGE} \
${DOCKERFILE} \
|| die "docker build failed"

if [[ -n "$MOUNT_HOME_ARGS" ]]; then
echo "mounting $HOME as /home/$USER"
fi
echo "mounting $TOP as /usr/src"
echo "mounting $TOP as $WORKDIR"

export PLATFORM
export PROJECT
export POISON
export INCEPTION
export JOBS
export DISTCHECK
export RECHECK
export UNIT_TEST_ONLY
export BUILD_DIR
export COVERAGE
export chain_lint

if [[ "$INSTALL_ONLY" == "t" ]]; then
docker run --rm \
--workdir=/usr/src \
--volume=$TOP:/usr/src \
--workdir=$WORKDIR \
--volume=$TOP:$WORKDIR \
${PLATFORM} \
${BUILD_IMAGE} \
sh -c "./autogen.sh &&
./configure --prefix=/usr --sysconfdir=/etc \
Expand All @@ -156,13 +178,17 @@ if [[ "$INSTALL_ONLY" == "t" ]]; then
--with-flux-security \
--enable-caliper &&
make clean &&
make -j${JOBS}" \
|| (docker rm tmp.$$; die "docker run of 'make install' failed")
make -j${JOBS}"
RC=$?
docker rm tmp.$$
test $RC -ne 0 && die "docker run of 'make install' failed"
else
docker run --rm \
--workdir=/usr/src \
--volume=$TOP:/usr/src \
--workdir=$WORKDIR \
--volume=$TOP:$WORKDIR \
${PLATFORM} \
$MOUNT_HOME_ARGS \
-e PLATFORM \
-e CC \
-e CXX \
-e LDFLAGS \
Expand All @@ -176,13 +202,13 @@ else
-e CPPCHECK \
-e DISTCHECK \
-e RECHECK \
-e UNIT_TEST_ONLY \
-e chain_lint \
-e JOBS \
-e USER \
-e PROJECT \
-e CI \
-e TAP_DRIVER_QUIET \
-e TEST_CHECK_PREREQS \
-e FLUX_TEST_TIMEOUT \
-e FLUX_TEST_SIZE_MAX \
-e PYTHON_VERSION \
Expand All @@ -208,9 +234,10 @@ if test -n "$TAG"; then
# Re-run 'make install' in fresh image, otherwise we get all
# the context from the build above
docker run --name=tmp.$$ \
--workdir=/usr/src/${BUILD_DIR} \
--volume=$TOP:/usr/src \
--workdir=${WORKDIR}/${BUILD_DIR} \
--volume=$TOP:${WORKDIR} \
--user="root" \
${PLATFORM} \
${BUILD_IMAGE} \
sh -c "make install && \
userdel $USER" \
Expand Down

0 comments on commit ac8b26c

Please sign in to comment.