mirror of
https://github.com/YunoHost-Apps/yunorunner_ynh.git
synced 2024-09-03 20:36:13 +02:00
Introduce personal-ci or official-infra contexts
This commit is contained in:
parent
6838bfe41c
commit
67b5f63714
6 changed files with 150 additions and 18 deletions
|
@ -1,9 +1,8 @@
|
||||||
;; Test complet
|
;; Test complet
|
||||||
; pre-install
|
|
||||||
sudo git clone --quiet https://github.com/YunoHost/CI_package_check /home/CI_package_check
|
|
||||||
; Manifest
|
; Manifest
|
||||||
domain="domain.tld"
|
domain="domain.tld"
|
||||||
path="/path"
|
path="/path"
|
||||||
|
context="personal-ci"
|
||||||
mode="manual"
|
mode="manual"
|
||||||
cluster="no"
|
cluster="no"
|
||||||
; Checks
|
; Checks
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
BASE_URL = "https://__DOMAIN____PATH__"
|
BASE_URL = "https://__DOMAIN____PATH__"
|
||||||
PORT = __PORT__
|
PORT = __PORT__
|
||||||
PACKAGE_CHECK_DIR = "__FINALPATH__/package_check/"
|
PACKAGE_CHECK_DIR = "__FINALPATH__/package_check/"
|
||||||
MONITOR_APPS_LIST = False
|
MONITOR_APPS_LIST = __AUTO__
|
||||||
MONITOR_GIT = False
|
MONITOR_GIT = __AUTO__
|
||||||
MONITOR_ONLY_GOOD_QUALITY_APPS = False
|
MONITOR_ONLY_GOOD_QUALITY_APPS = False
|
||||||
MONTHLY_JOBS = False
|
MONTHLY_JOBS = __AUTO__
|
||||||
WORKER_COUNT = 1
|
WORKER_COUNT = 1
|
||||||
YNH_BRANCH = "stable"
|
YNH_BRANCH = "stable"
|
||||||
DIST = "bullseye"
|
DIST = "bullseye"
|
||||||
|
|
|
@ -39,7 +39,16 @@
|
||||||
"default": "/ci"
|
"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",
|
"type": "select",
|
||||||
"choices": ["auto", "manual"],
|
"choices": ["auto", "manual"],
|
||||||
"default": "manual",
|
"default": "manual",
|
||||||
|
|
|
@ -15,6 +15,128 @@ yunorunner_release="52ef23a2cb37cb4fe13debca58eb589bb2f4d927"
|
||||||
# PERSONAL HELPERS
|
# 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 <<EOF
|
||||||
|
config:
|
||||||
|
cluster.https_address: $domain:8443
|
||||||
|
core.https_address: ${domain}:8443
|
||||||
|
core.trust_password: ${yuno_pwd}
|
||||||
|
networks:
|
||||||
|
- config:
|
||||||
|
ipv4.address: 192.168.${lxc_network}.1/24
|
||||||
|
ipv4.nat: "true"
|
||||||
|
ipv6.address: none
|
||||||
|
description: ""
|
||||||
|
name: lxdbr0
|
||||||
|
type: bridge
|
||||||
|
project: default
|
||||||
|
storage_pools:
|
||||||
|
- config:
|
||||||
|
size: ${btrfs_size}GB
|
||||||
|
source: /var/lib/lxd/disks/local.img
|
||||||
|
description: ""
|
||||||
|
name: local
|
||||||
|
driver: btrfs
|
||||||
|
profiles:
|
||||||
|
- config: {}
|
||||||
|
description: Default LXD profile
|
||||||
|
devices:
|
||||||
|
lxdbr0:
|
||||||
|
nictype: bridged
|
||||||
|
parent: lxdbr0
|
||||||
|
type: nic
|
||||||
|
root:
|
||||||
|
path: /
|
||||||
|
pool: local
|
||||||
|
type: disk
|
||||||
|
name: default
|
||||||
|
projects:
|
||||||
|
- config:
|
||||||
|
features.images: "true"
|
||||||
|
features.networks: "true"
|
||||||
|
features.profiles: "true"
|
||||||
|
features.storage.volumes: "true"
|
||||||
|
description: Default LXD project
|
||||||
|
name: default
|
||||||
|
cluster:
|
||||||
|
server_name: ${domain}
|
||||||
|
enabled: true
|
||||||
|
EOF
|
||||||
|
cat ./preseed.conf | lxd init --preseed
|
||||||
|
rm ./preseed.conf
|
||||||
|
lxc config set core.https_address [::]
|
||||||
|
else
|
||||||
|
lxd init --auto --storage-backend=dir
|
||||||
|
fi
|
||||||
|
|
||||||
|
popd
|
||||||
|
|
||||||
|
# ci_user will be the one launching job, gives it permission to run lxd commands
|
||||||
|
usermod -a -G lxd $app
|
||||||
|
|
||||||
|
ynh_exec_as $app lxc remote add yunohost https://devbaseimgs.yunohost.org --public --accept-certificate
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_cron_jobs() {
|
||||||
|
ynh_script_progression --message="Configuring the cron jobs.."
|
||||||
|
|
||||||
|
# Cron tasks
|
||||||
|
cat >> "/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
|
# EXPERIMENTAL HELPERS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -25,6 +25,7 @@ ynh_abort_if_errors
|
||||||
|
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path_url=$YNH_APP_ARG_PATH
|
path_url=$YNH_APP_ARG_PATH
|
||||||
|
context=$YNH_APP_ARG_CONTEXT
|
||||||
mode=$YNH_APP_ARG_MODE
|
mode=$YNH_APP_ARG_MODE
|
||||||
cluster=$YNH_APP_ARG_CLUSTER
|
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 remote add origin "$yunorunner_repository"
|
||||||
ynh_exec_as $app git fetch --quiet --depth=1 origin "$yunorunner_release"
|
ynh_exec_as $app git fetch --quiet --depth=1 origin "$yunorunner_release"
|
||||||
ynh_exec_as $app git reset --quiet --hard FETCH_HEAD
|
ynh_exec_as $app git reset --quiet --hard FETCH_HEAD
|
||||||
|
setup_lxd
|
||||||
|
git clone https://github.com/YunoHost/package_check "./package_check"
|
||||||
popd
|
popd
|
||||||
|
|
||||||
chmod 750 "$final_path"
|
chmod 750 "$final_path"
|
||||||
|
@ -123,6 +126,12 @@ popd
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Adding a config file..."
|
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"
|
ynh_add_config --template="yunorunner.config.py" --destination="$final_path/config.py"
|
||||||
|
|
||||||
chmod 400 "$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..."
|
ynh_script_progression --message="Run Yunorunner's finish_install script..."
|
||||||
|
|
||||||
pushd "$final_path"
|
if [ $context != "personal-ci" ] && [ ${PACKAGE_CHECK_EXEC:-0} -ne 0 ]; then
|
||||||
./finish_install.sh $mode $cluster
|
tweak_yunohost
|
||||||
popd
|
fi
|
||||||
|
|
||||||
|
add_cron_jobs
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# SETUP SYSTEMD
|
||||||
|
|
|
@ -151,15 +151,6 @@ pushd $final_path
|
||||||
venv/bin/pip install -r requirements-frozen.txt
|
venv/bin/pip install -r requirements-frozen.txt
|
||||||
popd
|
popd
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# FINISH INSTALL
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Run Yunorunner's finish_install script..."
|
|
||||||
|
|
||||||
pushd "$final_path"
|
|
||||||
./finish_install.sh
|
|
||||||
popd
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# UPDATE A CONFIG FILE
|
# UPDATE A CONFIG FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue