Skip to content
Snippets Groups Projects
Commit 1db28333 authored by Administrator's avatar Administrator
Browse files

Initial commit

The project is a copy of https://git.cbm.gsi.de/f.uhlig/singularity-executor
parents
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
# /home/gitlab-runner/apptainer-executor/base.sh
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"
# If apptainer isn't installed in the PATH add the directory explicitely in the next line
PATH=$PATH
#!/usr/bin/env bash
# /home/gitlab-runner/apptainer-executor/cleanup.sh
currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source ${currentDir}/base.sh # Get variables from base.
echo "Stopping running instance $CONTAINER_ID"
apptainer instance stop "$CONTAINER_ID"
#!/usr/bin/env bash
# /home/gitlab-runner/apptainer-executor/prepare.sh
currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source ${currentDir}/base.sh # Get variables from base.
#CONTAINER_ID="instance1"
set -eo pipefail
# trap any error, and mark it as a system failure.
trap "exit $SYSTEM_FAILURE_EXIT_CODE" ERR
get_path_to_image() {
# Implement here how you get the apptainer image.
# In the end you have to define the variable container_full_path
# which points to the locally available image
# In the current case the images are installed in a mounted directory
if [[ -z ${CUSTOM_ENV_CONTAINER} ]]; then
container_full_path=/cvmfs/vae.gsi.de/${CUSTOM_ENV_OS}/containers/user_container-production.sif
else
container_full_path=${CUSTOM_ENV_CONTAINER}
fi
}
start_instance() {
# Implement here how the image should be started
# This is for example needed to bind all needed directories from the host machine
# or to define the home directory
# get the image location
get_path_to_image
apptainer instance start -H ${currentDir} \
-B /cvmfs:/cvmfs \
${container_full_path} \
"$CONTAINER_ID"
}
start_container () {
# check if container exist already and stop it in that case
# "apptainer instance list" returns one line per match plus one
# extra header line. If the line count is one only the header is found
# in any other case there is a matching instance running
lines=$(apptainer instance list "$CONTAINER_ID" | wc -l)
if [[ $lines -ne 1 ]]; then
echo 'Found old running instance, stopping'
apptainer instance stop "$CONTAINER_ID"
fi
# The container image is hardcoded, but you can use
# the `CI_JOB_IMAGE` predefined variable
# https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
# which is available under `CUSTOM_ENV_CI_JOB_IMAGE` to allow the
# user to specify the image. The rest of the script assumes that
# you are running on an ubuntu image so modifications might be
# required.
# start the apptainer instance
start_instance
# Wait for container to start, we are using systemd to check this,
# for the sake of brevity.
for i in $(seq 1 10); do
apptainer exec instance://"$CONTAINER_ID" cat /etc/os-release >/dev/null 2>/dev/null
if [[ $? -eq 0 ]]; then
break
fi
if [ "$i" == "10" ]; then
echo 'Waited for 10 seconds to start container, exiting..'
# Inform GitLab Runner that this is a system failure, so it
# should be retried.
exit "$SYSTEM_FAILURE_EXIT_CODE"
fi
sleep 1s
done
}
start_container
echo "Running $container_full_path in $CONTAINER_ID"
run.sh 0 → 100755
#!/usr/bin/env bash
# /home/gitlab-runner/apptainer-executor/run.sh
currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source ${currentDir}/base.sh # Get variables from base.
apptainer exec instance://"$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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment