From 61fabf77a7c31f2521b60689183781fde3dde596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 15 Mar 2024 11:59:13 +0100 Subject: [PATCH] Manifest v2 --- .github/workflows/updater.sh | 64 ------------ .github/workflows/updater.yml | 50 ---------- check_process | 31 ------ conf/cron | 2 + conf/nginx.conf | 4 +- conf/systemd.service | 5 +- conf/yunorunner.config.py | 4 +- manifest.json | 70 ------------- manifest.toml | 85 ++++++++++++++++ scripts/_common.sh | 181 ++++++++++++++-------------------- scripts/backup | 26 +---- scripts/change_url | 120 +--------------------- scripts/install | 166 ++++++------------------------- scripts/remove | 70 +------------ scripts/restore | 110 ++++----------------- scripts/upgrade | 164 +++++++----------------------- tests.toml | 16 +++ 17 files changed, 282 insertions(+), 886 deletions(-) delete mode 100644 .github/workflows/updater.sh delete mode 100644 .github/workflows/updater.yml delete mode 100644 check_process create mode 100644 conf/cron delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 tests.toml diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh deleted file mode 100644 index 80d4473..0000000 --- a/.github/workflows/updater.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash - -#================================================= -# PACKAGE UPDATING HELPER -#================================================= - -# This script is meant to be run by GitHub Actions -# The YunoHost-Apps organisation offers a template Action to run this script periodically - -#================================================= -# FETCHING LATEST RELEASE AND ITS ASSETS -#================================================= - -# Fetching information -current_version=$(cat manifest.json | jq -j '.version|split("~")[0]') -current_yunorunner_release=$(grep -Po 'yunorunner_release="\K.*?(?=")' scripts/_common.sh) -repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]') -# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions) -version=$(curl --silent "https://api.github.com/repos/$repo/commits/master" | jq -r '.commit.committer.date | split("T")[0] | gsub("-";".")') -yunorunner_release=$(curl --silent "https://api.github.com/repos/$repo/commits/master" | jq -r '.sha') - -# Setting up the environment variables -echo "Current version: $current_version" -echo "Latest release from upstream: $version" -echo "VERSION=$version" >> $GITHUB_ENV -# For the time being, let's assume the script will fail -echo "PROCEED=false" >> $GITHUB_ENV - -# Proceed only if the retrieved version is greater than the current one -if [[ ! "$version" > "$current_version" ]]; then - echo "::warning ::No new version available" - exit 0 -# Proceed only if a PR for this new version does not already exist -elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then - echo "::warning ::A branch already exists for this update" - exit 0 -fi - -#================================================= -# UPDATE SOURCE FILES -#================================================= - -sed -i "s/$current_yunorunner_release/$yunorunner_release/gi" scripts/_common.sh - -#================================================= -# SPECIFIC UPDATE STEPS -#================================================= - -# Any action on the app's source code can be done. -# The GitHub Action workflow takes care of committing all changes after this script ends. - -#================================================= -# GENERIC FINALIZATION -#================================================= - -# Replace new version in manifest -echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json - -# No need to update the README, yunohost-bot takes care of it - -# The Action will proceed only if the PROCEED environment variable is set to true -echo "PROCEED=true" >> $GITHUB_ENV -exit 0 - diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml deleted file mode 100644 index 08ec1b3..0000000 --- a/.github/workflows/updater.yml +++ /dev/null @@ -1,50 +0,0 @@ -# This workflow allows GitHub Actions to automagically update your app whenever a new upstream release is detected. -# You need to enable Actions in your repository settings, and fetch this Action from the YunoHost-Apps organization. -# This file should be enough by itself, but feel free to tune it to your needs. -# It calls updater.sh, which is where you should put the app-specific update steps. -name: Check for new upstream releases -on: - # Allow to manually trigger the workflow - workflow_dispatch: - # Run it every day at 6:00 UTC - schedule: - - cron: '0 6 * * *' -jobs: - updater: - runs-on: ubuntu-latest - steps: - - name: Fetch the source code - uses: actions/checkout@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - - name: Run the updater script - id: run_updater - run: | - # Setting up Git user - git config --global user.name 'yunohost-bot' - git config --global user.email 'yunohost-bot@users.noreply.github.com' - # Run the updater script - /bin/bash .github/workflows/updater.sh - - name: Commit changes - id: commit - if: ${{ env.PROCEED == 'true' }} - run: | - git commit -am "Upgrade to v$VERSION" - - name: Create Pull Request - id: cpr - if: ${{ env.PROCEED == 'true' }} - uses: peter-evans/create-pull-request@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: Update to version ${{ env.VERSION }} - committer: 'yunohost-bot ' - author: 'yunohost-bot ' - signoff: false - base: testing - branch: ci-auto-update-v${{ env.VERSION }} - delete-branch: true - title: 'Upgrade to version ${{ env.VERSION }}' - body: | - Upgrade to v${{ env.VERSION }} - draft: false - diff --git a/check_process b/check_process deleted file mode 100644 index 7f5c3c4..0000000 --- a/check_process +++ /dev/null @@ -1,31 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - path="/path" - context="personal-ci" - mode="manual" - cluster="no" - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=0 - setup_public=1 - upgrade=1 - # 2021-03-05~ynh1 - upgrade=1 from_commit=f0e9373aa2403bf04f84c67646ac5d34376b7959 - # 2021-09-22~ynh1 - upgrade=1 from_commit=fea498cd83a7da12a102efe2f47397dace3cddda - backup_restore=1 - multi_instance=1 - port_already_use=1 (4242) - change_url=1 -;;; Options -Email= -Notification=down -;;; Upgrade options - ; commit=f0e9373aa2403bf04f84c67646ac5d34376b7959 - name=2021-03-05~ynh1 - ; commit=fea498cd83a7da12a102efe2f47397dace3cddda - name=2021-09-22~ynh1 diff --git a/conf/cron b/conf/cron new file mode 100644 index 0000000..2bf2ef9 --- /dev/null +++ b/conf/cron @@ -0,0 +1,2 @@ +# self-upgrade every night +0 3 * * * root "__INSTALL_DIR__/maintenance/self_upgrade.sh" >> "__INSTALL_DIR__/maintenance/self_upgrade.log" 2>&1 diff --git a/conf/nginx.conf b/conf/nginx.conf index 8fb8d61..ce2b44e 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -11,13 +11,13 @@ location __PATH__/ { include conf.d/yunohost_panel.conf.inc; location __PATH__/logs { - alias __FINALPATH__/results/logs/; + alias __INSTALL_DIR__/results/logs/; autoindex on; default_type "text/plain"; } location __PATH__/summary/ { - alias __FINALPATH__/results/summary/; + alias __INSTALL_DIR__/results/summary/; autoindex on; etag off; more_set_headers "Cache-control: max-age=300, s-maxage=300"; diff --git a/conf/systemd.service b/conf/systemd.service index ad977e3..12e1fae 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,8 +7,9 @@ Type=simple Restart=always User=__APP__ Group=__APP__ -WorkingDirectory=__FINALPATH__/ -ExecStart=__FINALPATH__/venv/bin/python ./run.py +WorkingDirectory=__INSTALL_DIR__/ +ExecStart=__INSTALL_DIR__/venv/bin/python ./run.py +Environment=YNHDEV_BACKEND=__BACKEND__ # Sandboxing options to harden security # Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html diff --git a/conf/yunorunner.config.py b/conf/yunorunner.config.py index 354c7fe..5b2adea 100644 --- a/conf/yunorunner.config.py +++ b/conf/yunorunner.config.py @@ -1,6 +1,8 @@ +#!/usr/bin/env python3 + BASE_URL = "https://__DOMAIN____PATH__" PORT = __PORT__ -PACKAGE_CHECK_DIR = "__FINALPATH__/package_check/" +PACKAGE_CHECK_DIR = "__INSTALL_DIR__/package_check/" MONITOR_APPS_LIST = __AUTO__ MONITOR_GIT = __AUTO__ MONITOR_ONLY_GOOD_QUALITY_APPS = False diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 37af0ce..0000000 --- a/manifest.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "YunoRunner", - "id": "yunorunner", - "packaging_format": 1, - "description": { - "en": "CI runner of YunoHost", - "fr": "Runner d'intégration continue de YunoHost" - }, - "version": "2023.04.05~ynh1", - "url": "https://github.com/YunoHost/yunorunner", - "upstream": { - "license": "GPL-3.0-or-later", - "code": "https://github.com/YunoHost/yunorunner" - }, - "license": "GPL-3.0-or-later", - "maintainer": { - "name": "" - }, - "previous_maintainer": { - "name": "Maniack Crudelis", - "email": "maniackc_dev@crudelis.fr" - }, - "requirements": { - "yunohost": ">= 4.3.0" - }, - "multi_instance": true, - "services": [ - "nginx" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "path", - "type": "path", - "default": "/ci" - }, - { - "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", - "ask": { - "en": "Should the jobs be automatically run from the apps list? In manual mode, Yunorunner will expect to be triggered by the `ciclic` command or webhooks (like ci-apps-dev). In auto mode, all apps of the catalog will be scheduled to be tested at least once a month and upon any change in their designated main branch (like ci-apps)." - } - }, - { - "name": "cluster", - "type": "select", - "choices": ["cluster", "no"], - "default": "no", - "ask": { - "en": "Should an LXD cluster be created with this server as first node? (cluster mode is experimental)" - } - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..eae9aac --- /dev/null +++ b/manifest.toml @@ -0,0 +1,85 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "yunorunner" +name = "YunoRunner" +description.en = "CI runner of YunoHost" +description.fr = "Runner d'intégration continue de YunoHost" + +version = "2023.04.05~ynh2" + +maintainers = [] + +[upstream] +license = "GPL-3.0-or-later" +code = "https://github.com/YunoHost/yunorunner" +website = "https://github.com/YunoHost/yunorunner" + +[integration] +yunohost = ">= 11.2" +architectures = "all" +multi_instance = true +ldap = "not_relevant" +sso = "not_relevant" +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" + +[install] + [install.domain] + type = "domain" + + [install.path] + type = "path" + default = "/ci" + + [install.init_main_permission] + type = "group" + default = "visitors" + + [install.context] + 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." + type = "select" + choices.personal_ci = "Personal CI" + choices.official_infra = "Official infra" + default = "personal_ci" + + [install.mode] + ask.en = "Should the jobs be automatically run from the apps list? In manual mode, Yunorunner will expect to be triggered by the `ciclic` command or webhooks (like ci-apps-dev). In auto mode, all apps of the catalog will be scheduled to be tested at least once a month and upon any change in their designated main branch (like ci-apps)." + type = "select" + choices.auto = "Automatically from the catalog" + choices.manual = "Manually via ciclic or webhook" + default = "manual" + + [install.cluster] + ask.en = "Should an LXD cluster be created with this server as first node? (cluster mode is experimental)" + type = "boolean" + default = false + + [install.backend] + ask.en = "Should you use LXD or Incus (LXD support will be removed soon)" + type = "select" + choices = ["lxd", "incus"] + default = "incus" + +[resources] + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + main.url = "/" + + [resources.ports] + main.default = 8095 + + [resources.apt] + packages = [ + "python3-venv", + "python3-dev", + "python3-pip", + "sqlite3", + "wkhtmltopdf", + "optipng", + ] diff --git a/scripts/_common.sh b/scripts/_common.sh index dd5a08b..b45be1c 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,9 +4,6 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -pkg_dependencies="python3-venv python3-dev python3-pip sqlite3 wkhtmltopdf optipng" - yunorunner_repository="https://github.com/YunoHost/yunorunner" yunorunner_release="52ef23a2cb37cb4fe13debca58eb589bb2f4d927" @@ -15,42 +12,48 @@ yunorunner_release="52ef23a2cb37cb4fe13debca58eb589bb2f4d927" # PERSONAL HELPERS #================================================= -function tweak_yunohost() { - +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 + 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 +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 [ "$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)) + if [ "$cluster" == "cluster" ]; then + setup_lxd + else + lxd init --auto # --storage-backend=dir + fi - yunohost firewall allow TCP 8443 - cat >./preseed.conf <"$tmpfile" <> "/etc/cron.d/yunorunner" << EOF -# self-upgrade every night -0 3 * * * root "$final_path/maintenance/self_upgrade.sh" >> "$final_path/maintenance/self_upgrade.log" 2>&1 -EOF + lxc config set core.https_address "[::]" } #================================================= @@ -130,78 +114,63 @@ EOF #================================================= ynh_maintenance_mode_ON () { - # Load value of $path_url and $domain from the config if their not set - if [ -z $path_url ]; then - path_url=$(ynh_app_setting_get $app path) - fi - if [ -z $domain ]; then - domain=$(ynh_app_setting_get $app domain) - fi - - # Create an html to serve as maintenance notice - echo " + # Create an html to serve as maintenance notice + cat > "/var/www/html/maintenance.$app.html" < - - -Your app $app is currently under maintenance! - - - -

Your app $app is currently under maintenance!

-

This app has been put under maintenance by your administrator at $(date)

-

Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.

+ + + Your app $app is currently under maintenance! + + + +

Your app $app is currently under maintenance!

+

This app has been put under maintenance by your administrator at $(date)

+

Please wait until the maintenance operation is done. This page will be reloaded as soon as your app will be back.

+ + +EOF - -" > "/var/www/html/maintenance.$app.html" - - # Create a new nginx config file to redirect all access to the app to the maintenance notice instead. - echo "# All request to the app will be redirected to ${path_url}_maintenance and fall on the maintenance notice -rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/? redirect; + # Create a new nginx config file to redirect all access to the app to the maintenance notice instead. + cat > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" < "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" - - # The current config file will redirect all requests to the root of the app. - # To keep the full path, we can use the following rewrite rule: - # rewrite ^${path_url}/(.*)$ ${path_url}_maintenance/\$1? redirect; - # The difference will be in the $1 at the end, which keep the following queries. - # But, if it works perfectly for a html request, there's an issue with any php files. - # This files are treated as simple files, and will be downloaded by the browser. - # Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was. - - systemctl reload nginx + # The current config file will redirect all requests to the root of the app. + # To keep the full path, we can use the following rewrite rule: + # rewrite ^${path}/(.*)$ ${path}_maintenance/\$1? redirect; + # The difference will be in the $1 at the end, which keep the following queries. + # But, if it works perfectly for a html request, there's an issue with any php files. + # This files are treated as simple files, and will be downloaded by the browser. + # Would be really be nice to be able to fix that issue. So that, when the page is reloaded after the maintenance, the user will be redirected to the real page he was. + systemctl reload nginx } ynh_maintenance_mode_OFF () { - # Load value of $path_url and $domain from the config if their not set - if [ -z $path_url ]; then - path_url=$(ynh_app_setting_get $app path) - fi - if [ -z $domain ]; then - domain=$(ynh_app_setting_get $app domain) - fi + # Rewrite the nginx config file to redirect from ${path}_maintenance to the real url of the app. + echo "rewrite ^${path}_maintenance/(.*)$ ${path}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" + systemctl reload nginx - # Rewrite the nginx config file to redirect from ${path_url}_maintenance to the real url of the app. - echo "rewrite ^${path_url}_maintenance/(.*)$ ${path_url}/\$1 redirect;" > "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" - systemctl reload nginx + # Sleep 4 seconds to let the browser reload the pages and redirect the user to the app. + sleep 4 - # Sleep 4 seconds to let the browser reload the pages and redirect the user to the app. - sleep 4 + # Then remove the temporary files used for the maintenance. + rm "/var/www/html/maintenance.$app.html" + rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" - # Then remove the temporary files used for the maintenance. - rm "/var/www/html/maintenance.$app.html" - rm "/etc/nginx/conf.d/$domain.d/maintenance.$app.conf" - - systemctl reload nginx + systemctl reload nginx } diff --git a/scripts/backup b/scripts/backup index d72c557..1b0da06 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,26 +8,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -39,7 +17,7 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION @@ -55,6 +33,8 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup --src_path="/etc/cron.d/$app" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/change_url b/scripts/change_url index d9ca583..921ae41 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC STARTING #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -9,135 +7,27 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -port=$(ynh_app_setting_get --app=$app --key=port) - -#================================================= -# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# ACTIVATE MAINTENANCE MODE -#================================================= - -path_url=$old_path -domain=$old_domain -ynh_maintenance_mode_ON - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 -fi - -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped YunoRunner CI" --timeout=30 +ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" --line_match="Stopped YunoRunner CI" --timeout=30 #================================================= # MODIFY URL IN NGINX CONF #================================================= ynh_script_progression --message="Updating NGINX web server configuration..." -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf +ynh_change_url_nginx_config -# Change the path in the NGINX config file -if [ $change_path -eq 1 ] -then - # Make a backup of the original NGINX config file if modified - ynh_backup_if_checksum_is_different --file="$nginx_conf_path" - # Set global variables for NGINX helper - domain="$old_domain" - path_url="$new_path" - - # Store path_url setting - ynh_app_setting_set --app=$app --key=path_url --value="$path_url" - - # Create a dedicated NGINX config - ynh_add_nginx_config -fi - -# Change the domain for NGINX -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf - # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" -fi - -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started YunoRunner CI" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload - -#================================================= -# DEACTIVE MAINTENANCE MODE -#================================================= - -path_url=$old_path -domain=$old_domain -ynh_maintenance_mode_OFF +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Started YunoRunner CI" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 5445d22..cf9b2a1 100644 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -9,116 +7,36 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -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 - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." - -final_path=/var/www/$app -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - -# Register (book) web path -ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." - -ynh_app_setting_set --app=$app --key=domain --value=$domain -ynh_app_setting_set --app=$app --key=path --value=$path_url - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -ynh_script_progression --message="Finding an available port..." - -# Find an available port -port=$(ynh_find_port --port=8095) -ynh_app_setting_set --app=$app --key=port --value=$port - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." - -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." -ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -mkdir "$final_path" -chown $app:$app "$final_path" -pushd "$final_path" - ynh_exec_as $app git init - 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 +ynh_exec_as "$app" git -C "$install_dir" init +ynh_exec_as "$app" git -C "$install_dir" remote add origin "$yunorunner_repository" +ynh_exec_as "$app" git -C "$install_dir" fetch --quiet --depth=1 origin "$yunorunner_release" +ynh_exec_as "$app" git -C "$install_dir" reset --quiet --hard FETCH_HEAD +ynh_exec_as "$app" git clone https://github.com/YunoHost/package_check "$install_dir/package_check" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app "$final_path" -chown $app:www-data "$final_path" -chown -R $app:www-data "$final_path/results" +chown "$app:$app" "$install_dir" -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring NGINX web server..." +setup_lxd -# Create a dedicated NGINX config -ynh_add_nginx_config +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" +chown "$app:www-data" "$install_dir" +chown -R "$app:www-data" "$install_dir/results" -#================================================= -# SPECIFIC SETUP #================================================= # INSTALL PYTHON DEPENDENCIES #================================================= ynh_script_progression --message="Installing Python dependencies..." -pushd $final_path - python3 -m venv venv - venv/bin/pip install --upgrade pip - venv/bin/pip install -r requirements-frozen.txt +pushd "$install_dir" + python3 -m venv venv + venv/bin/pip install --upgrade pip + venv/bin/pip install -r requirements-frozen.txt popd #================================================= @@ -127,66 +45,46 @@ popd ynh_script_progression --message="Adding a config file..." if [ $mode = "auto" ]; then - auto="True" + auto="True" else - auto="False" + auto="False" fi -ynh_add_config --template="yunorunner.config.py" --destination="$final_path/config.py" +ynh_add_config --template="yunorunner.config.py" --destination="$install_dir/config.py" -chmod 400 "$final_path/config.py" -chown $app:$app "$final_path/config.py" +chmod 400 "$install_dir/config.py" +chown "$app:$app" "$install_dir/config.py" #================================================= # FINISH INSTALL #================================================= ynh_script_progression --message="Run Yunorunner's finish_install script..." -if [ $context != "personal-ci" ] && [ ${PACKAGE_CHECK_EXEC:-0} -ne 0 ]; then - tweak_yunohost +if [ $context != "personal-ci" ] && [ "${PACKAGE_CHECK_EXEC:-0}" -ne 0 ]; then + tweak_yunohost fi -add_cron_jobs +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." +# Create a dedicated NGINX config +ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config +yunohost service add "$app" --description="$app daemon for YunoRunner" -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app --description="$app daemon for YunoRunner" +ynh_add_config --template="cron" --destination="/etc/cron.d/$app" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started YunoRunner CI" --timeout=30 - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." - -# Make app public -ynh_permission_update --permission="main" --add="visitors" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Started YunoRunner CI" --timeout=30 #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 524c878..47a0324 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,81 +8,21 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then - ynh_script_progression --message="Removing $app service integration..." - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." - # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." - # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - ynh_script_progression --message="Closing port $port..." - ynh_exec_warn_less yunohost firewall disallow TCP $port -fi - -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." - -# Delete a system user -ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index a51a6ae..2b5f6c4 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,123 +8,53 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." - -test ! -d $final_path || ynh_die --message="There is already a directory: $final_path " - #================================================= # ACTIVATE MAINTENANCE MODE #================================================= ynh_maintenance_mode_ON -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." -ynh_restore_file --origin_path="$final_path" +ynh_restore_file --origin_path="$install_dir" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." - -# Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" #================================================= # INSTALL PYTHON DEPENDENCIES #================================================= ynh_script_progression --message="Installing Python dependencies..." -pushd $final_path - python3 -m venv venv - venv/bin/pip install --upgrade pip - venv/bin/pip install -r requirements-frozen.txt +pushd "$install_dir" + python3 -m venv venv + venv/bin/pip install --upgrade pip + venv/bin/pip install -r requirements-frozen.txt popd #================================================= -# RESTORE SYSTEMD +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service --quiet +systemctl enable "$app.service" --quiet +yunohost service add "$app" --description="$app daemon for YunoRunner" + +ynh_restore_file --origin_path="/etc/cron.d/$app" #================================================= -# INTEGRATE SERVICE IN YUNOHOST +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 -yunohost service add $app --description="$app daemon for YunoRunner" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." - -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started YunoRunner CI" --timeout=30 - -#================================================= -# DEACTIVE MAINTENANCE MODE -#================================================= - -ynh_maintenance_mode_OFF - -#================================================= -# GENERIC FINALIZATION -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Started YunoRunner CI" --timeout=30 ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 17a41ac..b280edf 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -9,146 +7,60 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -port=$(ynh_app_setting_get --app=$app --key=port) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - ynh_script_progression --message="Closing port $port" - ynh_exec_warn_less yunohost firewall disallow TCP $port -fi - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # ACTIVATE MAINTENANCE MODE #================================================= ynh_maintenance_mode_ON -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped YunoRunner CI" +ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" --line_match="Stopped YunoRunner CI" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# If port doesn't exist, create it -if [ -z "$port" ]; then - port=4242 - ynh_app_setting_set --app=$app --key=port --value=$port +if [ ! -d "$install_dir/.git/" ]; then + ynh_exec_as "$app" git -C "$install_dir" init + git -C "$install_dir" remote add origin "$yunorunner_repository" fi -if [[ ! -d "$final_path/.git/" ]] -then - git init "$final_path" - pushd "$final_path" - git remote add origin "$yunorunner_repository" - popd -fi - -# Cleaning legacy permissions -if ynh_legacy_permissions_exists; then - ynh_legacy_permissions_delete_all - - ynh_app_setting_delete --app=$app --key=is_public +# Close a legacy port +if yunohost firewall list | grep -q "\- $port$"; then + ynh_exec_warn_less yunohost firewall disallow TCP "$port" fi # Remove Pythonz -ynh_secure_remove --file="$final_path/.pythonz" - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path +ynh_secure_remove --file="$install_dir/.pythonz" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." +# Download, check integrity, uncompress and patch the source from app.src +pushd "$install_dir" + ynh_exec_as "$app" git fetch --quiet --depth=1 origin "$yunorunner_release" + ynh_exec_as "$app" git reset --quiet --hard FETCH_HEAD +popd - # Download, check integrity, uncompress and patch the source from app.src - pushd "$final_path" - ynh_exec_as $app git fetch --quiet --depth=1 origin "$yunorunner_release" - ynh_exec_as $app git reset --quiet --hard FETCH_HEAD - popd -fi +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." - -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# SPECIFIC UPGRADE #================================================= # INSTALL PYTHON DEPENDENCIES #================================================= ynh_script_progression --message="Installing Python dependencies..." -pushd $final_path - python3 -m venv venv - venv/bin/pip install --upgrade pip - venv/bin/pip install -r requirements-frozen.txt +pushd "$install_dir" + python3 -m venv venv + venv/bin/pip install --upgrade pip + venv/bin/pip install -r requirements-frozen.txt popd #================================================= @@ -156,34 +68,31 @@ popd #================================================= ynh_script_progression --message="Updating a config file..." -ynh_backup_if_checksum_is_different --file="$final_path/config.py" +ynh_backup_if_checksum_is_different --file="$install_dir/config.py" -chmod 400 "$final_path/config.py" -chown $app:$app "$final_path/config.py" +chmod 400 "$install_dir/config.py" +chown "$app:$app" "$install_dir/config.py" #================================================= -# SETUP SYSTEMD +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config +yunohost service add "$app" --description="$app daemon for YunoRunner" -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app --description="$app daemon for YunoRunner" +ynh_add_config --template="cron" --destination="/etc/cron.d/$app" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started YunoRunner CI" --timeout=30 +ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Started YunoRunner CI" --timeout=30 #================================================= # DEACTIVE MAINTENANCE MODE @@ -191,13 +100,6 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --l ynh_maintenance_mode_OFF -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..40b75ac --- /dev/null +++ b/tests.toml @@ -0,0 +1,16 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + args.context = "personal-ci" + args.mode = "manual" + args.cluster = false + + # ------------ + # Tests to run + # ------------ + + test_upgrade_from.f0e9373aa2403bf04f84c67646ac5d34376b7959.name = "2021-03-05~ynh1" + test_upgrade_from.fea498cd83a7da12a102efe2f47397dace3cddda.name = "2021-09-22~ynh1"