mirror of
https://github.com/YunoHost-Apps/gitlab-runner_ynh.git
synced 2024-09-03 19:15:58 +02:00
108 lines
3.4 KiB
Bash
Executable file
108 lines
3.4 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
#=================================================
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
# By default, the runner will use docker to run your builds. PR are welcomes to implement more executors
|
|
executor="docker"
|
|
|
|
# Adding a comma at the end
|
|
if [ ${gitlab_url: -1} != "," ]; then
|
|
gitlab_url=${gitlab_url},
|
|
fi
|
|
|
|
# Adding a comma at the end
|
|
if [ ${token: -1} != "," ]; then
|
|
token=${token},
|
|
fi
|
|
|
|
# Adding a comma at the end
|
|
if [ ${docker_image: -1} != "," ]; then
|
|
docker_image=${docker_image},
|
|
fi
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
ynh_script_progression --message="Storing installation settings..."
|
|
|
|
ynh_app_setting_set --app=$app --key=executor --value=$executor
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
# Make sure docker is running before installing gitlab-runner
|
|
if ! systemctl is-active --quiet docker; then
|
|
ynh_systemd_action --service_name=docker --action=restart --line_match="API listen on /run/docker.sock"
|
|
fi
|
|
|
|
tempdir="$(mktemp -d)"
|
|
ynh_setup_source --dest_dir=$tempdir
|
|
dpkg -i $tempdir/gitlab-runner.deb
|
|
ynh_secure_remove --file="$tempdir"
|
|
|
|
#=================================================
|
|
# SPECIFIC SETUP
|
|
#=================================================
|
|
# SETUP GITLAB RUNNER
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring GitLab Runner..."
|
|
|
|
# Can be registered several time, to do this give a list of gitlab_url, token and docker_image separated by a comma.
|
|
split_char=","
|
|
|
|
nb_to_register=$(echo "${gitlab_url}" | awk -F"${split_char}" '{print NF-1}')
|
|
|
|
for i in $(seq $nb_to_register)
|
|
do
|
|
url=$(echo $gitlab_url | cut -d$split_char -f$i)
|
|
tok=$(echo $token | cut -d$split_char -f$i)
|
|
docker_img=$(echo $docker_image | cut -d$split_char -f$i)
|
|
|
|
# Register the runner
|
|
ynh_exec_warn_less $app register \
|
|
--non-interactive \
|
|
--url "$url" \
|
|
--registration-token "$tok" \
|
|
--executor "$executor" \
|
|
--docker-image "$docker_img" \
|
|
--description "YunoHost runner" \
|
|
--tag-list "$executor,$YNH_ARCH" \
|
|
--run-untagged \
|
|
--locked="false"
|
|
done
|
|
|
|
#=================================================
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
#=================================================
|
|
|
|
# Calculate and store the config file checksum into the app settings
|
|
ynh_store_file_checksum "/etc/$app/config.toml"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
yunohost service add $app
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|