mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
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:
parent
2e25bcac4f
commit
61fde67ba6
7
.ci/gitlab-runner/custom-driver/README
Normal file
7
.ci/gitlab-runner/custom-driver/README
Normal 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.
|
||||
4
.ci/gitlab-runner/custom-driver/base.sh
Normal file
4
.ci/gitlab-runner/custom-driver/base.sh
Normal 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"
|
||||
10
.ci/gitlab-runner/custom-driver/cleanup.sh
Executable file
10
.ci/gitlab-runner/custom-driver/cleanup.sh
Executable 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"
|
||||
48
.ci/gitlab-runner/custom-driver/prepare.sh
Executable file
48
.ci/gitlab-runner/custom-driver/prepare.sh
Executable 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
|
||||
14
.ci/gitlab-runner/custom-driver/run.sh
Executable file
14
.ci/gitlab-runner/custom-driver/run.sh
Executable 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
|
||||
Loading…
x
Reference in New Issue
Block a user