Skip to content

Commit

Permalink
ci: add option for running tests without volume
Browse files Browse the repository at this point in the history
CI_DOCKER_USE_VOLUMES_FOR_CACHE if set to false will mount cache in a directory on the host rather than in a docker volume. Supports saving and restoring caches on Github Actions.
  • Loading branch information
m3dwards committed Jun 19, 2024
1 parent 2d21060 commit 6918b9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions ci/test/00_setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ export CI_BASE_PACKAGES=${CI_BASE_PACKAGES:-build-essential libtool autotools-de
export GOAL=${GOAL:-install}
export DIR_QA_ASSETS=${DIR_QA_ASSETS:-${BASE_SCRATCH_DIR}/qa-assets}
export CI_RETRY_EXE=${CI_RETRY_EXE:-"retry --"}
export CI_DOCKER_USE_VOLUMES_FOR_CACHE=${CI_DOCKER_USE_VOLUMES_FOR_CACHE:-true}
30 changes: 21 additions & 9 deletions ci/test/02_run_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
--tag="${CONTAINER_NAME}" \
"${BASE_READ_ONLY_DIR}"

docker volume create "${CONTAINER_NAME}_ccache" || true
docker volume create "${CONTAINER_NAME}_depends" || true
docker volume create "${CONTAINER_NAME}_depends_sources" || true
docker volume create "${CONTAINER_NAME}_previous_releases" || true

docker network create --ipv6 --subnet 1111:1111::/112 ci-ip6net || true

if [ -n "${RESTART_CI_DOCKER_BEFORE_RUN}" ] ; then
Expand All @@ -47,15 +42,32 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then
# When detecting podman-docker, `--external` should be added.
docker image prune --force --filter "label=$CI_IMAGE_LABEL"

if [ -n "$CI_DOCKER_USE_VOLUMES_FOR_CACHE" ]; then
docker volume create "${CONTAINER_NAME}_ccache" || true
docker volume create "${CONTAINER_NAME}_depends" || true
docker volume create "${CONTAINER_NAME}_depends_sources" || true
docker volume create "${CONTAINER_NAME}_previous_releases" || true

CI_DOCKER_CCACHE_MOUNT="type=volume,src=${CONTAINER_NAME}_ccache,dst=$CCACHE_DIR"
CI_DOCKER_DEPENDS_MOUNT="type=volume,src=${CONTAINER_NAME}_depends,dst=$DEPENDS_DIR/built"
CI_DOCKER_DEPENDS_SOURCES_MOUNT="type=volume,src=${CONTAINER_NAME}_depends_sources,dst=$DEPENDS_DIR/sources"
CI_DOCKER_PREVIOUS_RELEASES_MOUNT="type=volume,src=${CONTAINER_NAME}_previous_releases,dst=$PREVIOUS_RELEASES_DIR"
else
CI_DOCKER_CCACHE_MOUNT="type=bind,src=${CCACHE_DIR},dst=$CCACHE_DIR"
CI_DOCKER_DEPENDS_MOUNT="type=bind,src=${DEPENDS_DIR}/built,dst=$DEPENDS_DIR/built"
CI_DOCKER_DEPENDS_SOURCES_MOUNT="type=bind,src=${DEPENDS_DIR}/sources,dst=$DEPENDS_DIR/sources"
CI_DOCKER_PREVIOUS_RELEASES_MOUNT="type=bind,src=${PREVIOUS_RELEASES_DIR},dst=$PREVIOUS_RELEASES_DIR"
fi

# Append $USER to /tmp/env to support multi-user systems and $CONTAINER_NAME
# to allow support starting multiple runs simultaneously by the same user.
# shellcheck disable=SC2086
CI_CONTAINER_ID=$(docker run --cap-add LINUX_IMMUTABLE $CI_CONTAINER_CAP --rm --interactive --detach --tty \
--mount "type=bind,src=$BASE_READ_ONLY_DIR,dst=$BASE_READ_ONLY_DIR,readonly" \
--mount "type=volume,src=${CONTAINER_NAME}_ccache,dst=$CCACHE_DIR" \
--mount "type=volume,src=${CONTAINER_NAME}_depends,dst=$DEPENDS_DIR/built" \
--mount "type=volume,src=${CONTAINER_NAME}_depends_sources,dst=$DEPENDS_DIR/sources" \
--mount "type=volume,src=${CONTAINER_NAME}_previous_releases,dst=$PREVIOUS_RELEASES_DIR" \
--mount ${CI_DOCKER_CCACHE_MOUNT} \
--mount ${CI_DOCKER_DEPENDS_MOUNT} \
--mount ${CI_DOCKER_DEPENDS_SOURCES_MOUNT} \
--mount ${CI_DOCKER_PREVIOUS_RELEASES_MOUNT} \
--env-file /tmp/env-$USER-$CONTAINER_NAME \
--name "$CONTAINER_NAME" \
--network ci-ip6net \
Expand Down

0 comments on commit 6918b9d

Please sign in to comment.