From 67b5f637147039d0bf7e5927e8cc4818164e1a0e Mon Sep 17 00:00:00 2001 From: tituspijean Date: Wed, 12 Apr 2023 20:57:37 +0200 Subject: [PATCH] Introduce personal-ci or official-infra contexts --- check_process | 3 +- conf/yunorunner.config.py | 6 +- manifest.json | 11 +++- scripts/_common.sh | 122 ++++++++++++++++++++++++++++++++++++++ scripts/install | 17 +++++- scripts/upgrade | 9 --- 6 files changed, 150 insertions(+), 18 deletions(-) diff --git a/check_process b/check_process index 5f69854..7f5c3c4 100644 --- a/check_process +++ b/check_process @@ -1,9 +1,8 @@ ;; Test complet - ; pre-install - sudo git clone --quiet https://github.com/YunoHost/CI_package_check /home/CI_package_check ; Manifest domain="domain.tld" path="/path" + context="personal-ci" mode="manual" cluster="no" ; Checks diff --git a/conf/yunorunner.config.py b/conf/yunorunner.config.py index eb77e8e..354c7fe 100644 --- a/conf/yunorunner.config.py +++ b/conf/yunorunner.config.py @@ -1,10 +1,10 @@ BASE_URL = "https://__DOMAIN____PATH__" PORT = __PORT__ PACKAGE_CHECK_DIR = "__FINALPATH__/package_check/" -MONITOR_APPS_LIST = False -MONITOR_GIT = False +MONITOR_APPS_LIST = __AUTO__ +MONITOR_GIT = __AUTO__ MONITOR_ONLY_GOOD_QUALITY_APPS = False -MONTHLY_JOBS = False +MONTHLY_JOBS = __AUTO__ WORKER_COUNT = 1 YNH_BRANCH = "stable" DIST = "bullseye" diff --git a/manifest.json b/manifest.json index 30b2a36..7f1e2f7 100644 --- a/manifest.json +++ b/manifest.json @@ -39,7 +39,16 @@ "default": "/ci" }, { - "name": "", + "name": "context", + "type": "select", + "choices": ["personal-ci", "official-infra"], + "default": "personal-ci", + "ask": { + "en": "Leave it to 'personal-ci'. If set to 'official-infra', Yunorunner will take over your server and disable vital services to run alone." + } + }, + { + "name": "mode", "type": "select", "choices": ["auto", "manual"], "default": "manual", diff --git a/scripts/_common.sh b/scripts/_common.sh index ac4384b..48b39a5 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -15,6 +15,128 @@ yunorunner_release="52ef23a2cb37cb4fe13debca58eb589bb2f4d927" # PERSONAL HELPERS #================================================= +function tweak_yunohost() { + + # Idk why this is needed but wokay I guess >_> + echo -e "\n127.0.0.1 $domain #CI_APP" >> /etc/hosts + + ynh_print_info "Disabling unecessary services to save up RAM..." + for SERVICE in mysql php7.4-fpm metronome rspamd dovecot postfix redis-server postsrsd yunohost-api avahi-daemon + do + systemctl stop $SERVICE + systemctl disable $SERVICE --quiet + done + + yunohost app makedefault -d "$domain" $app + +} + +function setup_lxd() { + if ! yunohost app list --output-as json --quiet | jq -e '.apps[] | select(.id == "lxd")' >/dev/null + then + ynh_script_progression --message="Installing LXD... (this make take a long time!" + yunohost app install --force https://github.com/YunoHost-Apps/lxd_ynh + fi + + mkdir .lxd + pushd .lxd + + ynh_print_info "Configuring lxd..." + + if [ "$lxd_cluster" == "cluster" ] + then + local free_space=$(df --output=avail / | sed 1d) + local btrfs_size=$(( $free_space * 90 / 100 / 1024 / 1024 )) + local lxc_network=$((1 + $RANDOM % 254)) + + yunohost firewall allow TCP 8443 + cat >./preseed.conf <> "/etc/cron.d/yunorunner" << EOF +# self-upgrade every night +0 3 * * * root "$YUNORUNNER_HOME/maintenance/self_upgrade.sh" >> "$YUNORUNNER_HOME/maintenance/self_upgrade.log" 2>&1 +EOF +} + +# ========================= +# Main stuff +# ========================= + +# Add permission to the user for the entire yunorunner home because it'll be the one running the tests (as a non-root user) +chown -R $ci_user $YUNORUNNER_HOME + +echo "Done!" +echo " " +echo "N.B. : If you want to enable Matrix notification, you should look at " +echo "the instructions inside lib/chat_notify.sh to deploy matrix-commander" +echo "" +echo "You may also want to tweak the 'config' file to run test with a different branch / arch" +echo "" +echo "When you're ready to start the CI, run: systemctl restart $ci_user" + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/install b/scripts/install index 41212ac..7ff5cea 100644 --- a/scripts/install +++ b/scripts/install @@ -25,6 +25,7 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH +context=$YNH_APP_ARG_CONTEXT mode=$YNH_APP_ARG_MODE cluster=$YNH_APP_ARG_CLUSTER @@ -89,6 +90,8 @@ pushd "$final_path" ynh_exec_as $app git remote add origin "$yunorunner_repository" ynh_exec_as $app git fetch --quiet --depth=1 origin "$yunorunner_release" ynh_exec_as $app git reset --quiet --hard FETCH_HEAD + setup_lxd + git clone https://github.com/YunoHost/package_check "./package_check" popd chmod 750 "$final_path" @@ -123,6 +126,12 @@ popd #================================================= ynh_script_progression --message="Adding a config file..." +if $mode = "auto"; then + auto = "True" +else + auto = "False" +fi + ynh_add_config --template="yunorunner.config.py" --destination="$final_path/config.py" chmod 400 "$final_path/config.py" @@ -133,9 +142,11 @@ chown $app:$app "$final_path/config.py" #================================================= ynh_script_progression --message="Run Yunorunner's finish_install script..." -pushd "$final_path" - ./finish_install.sh $mode $cluster -popd +if [ $context != "personal-ci" ] && [ ${PACKAGE_CHECK_EXEC:-0} -ne 0 ]; then + tweak_yunohost +fi + +add_cron_jobs #================================================= # SETUP SYSTEMD diff --git a/scripts/upgrade b/scripts/upgrade index 0f5eed8..17a41ac 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -151,15 +151,6 @@ pushd $final_path venv/bin/pip install -r requirements-frozen.txt popd -#================================================= -# FINISH INSTALL -#================================================= -ynh_script_progression --message="Run Yunorunner's finish_install script..." - -pushd "$final_path" - ./finish_install.sh -popd - #================================================= # UPDATE A CONFIG FILE #=================================================