ci: Add a custom driver for gitlab runner for podman

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2024-10-11 19:40:21 -07:00 committed by Veiko Aasa
parent 2e25bcac4f
commit 61fde67ba6
No known key found for this signature in database
GPG Key ID: 478539CAE680674E
5 changed files with 83 additions and 0 deletions

View File

@ -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.

View File

@ -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"

View File

@ -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"

View File

@ -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 <<EOF
set -eo pipefail
echo 'Package: *' > /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

View File

@ -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