diff --git a/.ci/gitlab-runner/custom-driver/README b/.ci/gitlab-runner/custom-driver/README new file mode 100644 index 000000000..91c8823f7 --- /dev/null +++ b/.ci/gitlab-runner/custom-driver/README @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later + +This directory contains a custom driver for Gitlab-CI Runner. This is used to +run functional tests. + +Based on https://docs.gitlab.com/runner/executors/custom_examples/lxd.html under +Expat license. diff --git a/.ci/gitlab-runner/custom-driver/base.sh b/.ci/gitlab-runner/custom-driver/base.sh new file mode 100644 index 000000000..c4618898d --- /dev/null +++ b/.ci/gitlab-runner/custom-driver/base.sh @@ -0,0 +1,4 @@ +#!/usr/bin/bash +# SPDX-License-Identifier: AGPL-3.0-or-later + +CONTAINER_ID="runner-$CUSTOM_ENV_CI_RUNNER_ID-project-$CUSTOM_ENV_CI_PROJECT_ID-concurrent-$CUSTOM_ENV_CI_CONCURRENT_PROJECT_ID-$CUSTOM_ENV_CI_JOB_ID" diff --git a/.ci/gitlab-runner/custom-driver/cleanup.sh b/.ci/gitlab-runner/custom-driver/cleanup.sh new file mode 100755 index 000000000..5094ef44a --- /dev/null +++ b/.ci/gitlab-runner/custom-driver/cleanup.sh @@ -0,0 +1,10 @@ +#!/usr/bin/bash +# SPDX-License-Identifier: AGPL-3.0-or-later + +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source ${current_dir}/base.sh # Get variables from base. + +echo "Deleting container $CONTAINER_ID" + +podman container stop "$CONTAINER_ID" +podman container rm -f "$CONTAINER_ID" diff --git a/.ci/gitlab-runner/custom-driver/prepare.sh b/.ci/gitlab-runner/custom-driver/prepare.sh new file mode 100755 index 000000000..e8fcbbeb3 --- /dev/null +++ b/.ci/gitlab-runner/custom-driver/prepare.sh @@ -0,0 +1,48 @@ +#!/usr/bin/bash +# SPDX-License-Identifier: AGPL-3.0-or-later + +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source ${current_dir}/base.sh # Get variables from base. + +set -eo pipefail + +# trap any error, and mark it as a system failure. +trap "exit $SYSTEM_FAILURE_EXIT_CODE" ERR + +start_container () { + if podman container exists "$CONTAINER_ID" ; then + echo 'Found old container, deleting' + podman container stop "$CONTAINER_ID" + podman container rm -f "$CONTAINER_ID" + fi + + podman pull registry.salsa.debian.org/freedombox-team/freedombox:functional-tests-stable + podman run --name "$CONTAINER_ID" --systemd=always \ + --privileged \ + --cap-add=SYS_ADMIN --cap-add=NET_ADMIN --cap-add=MKNOD \ + --detach registry.salsa.debian.org/freedombox-team/freedombox:functional-tests-stable /sbin/init + + if podman exec "$CONTAINER_ID" systemctl is-system-running --wait; then + echo 'Container started.' + else + echo 'Container started degraded.' + fi +} + +install_dependencies () { + podman exec "$CONTAINER_ID" /usr/bin/bash < /etc/apt/preferences.d/unstable +echo 'Pin: release a=unstable' >> /etc/apt/preferences.d/unstable +echo 'Pin-Priority: 400' >> /etc/apt/preferences.d/unstable +echo 'deb http://deb.debian.org/debian unstable main' > /etc/apt/sources.list.d/unstable.list +apt-get update +DEBIAN_FRONTEND=noninteractive apt-get install -y gitlab-runner git-lfs +EOF +} + +echo "Running in $CONTAINER_ID" + +start_container + +install_dependencies diff --git a/.ci/gitlab-runner/custom-driver/run.sh b/.ci/gitlab-runner/custom-driver/run.sh new file mode 100755 index 000000000..0950d4699 --- /dev/null +++ b/.ci/gitlab-runner/custom-driver/run.sh @@ -0,0 +1,14 @@ +#!/usr/bin/bash +# SPDX-License-Identifier: AGPL-3.0-or-later + +set -eo pipefail + +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source ${current_dir}/base.sh # Get variables from base. + +podman exec --interactive "$CONTAINER_ID" /bin/bash < "${1}" +if [ $? -ne 0 ]; then + # Exit using the variable, to make the build as failure in GitLab + # CI. + exit $BUILD_FAILURE_EXIT_CODE +fi