diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh new file mode 100644 index 0000000..c66f0cf --- /dev/null +++ b/.github/workflows/updater.sh @@ -0,0 +1,145 @@ +#!/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 +# Since each app is different, maintainers can adapt its contents so as to perform +# automatic actions when a new upstream release is detected. + +#================================================= +# FETCHING LATEST RELEASE AND ITS ASSETS +#================================================= + +# Fetching information +current_version=$(cat manifest.json | jq -j '.version|split("~")[0]') +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/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1) +assets=($(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '[ .[] | select(.tag_name=="'$version'").assets[].browser_download_url ] | join(" ") | @sh' | tr -d "'")) + +# Later down the script, we assume the version has only digits and dots +# Sometimes the release name starts with a "v", so let's filter it out. +# You may need more tweaks here if the upstream repository has different naming conventions. +if [[ ${version:0:1} == "v" || ${version:0:1} == "V" ]]; then + version=${version:1} +fi + +# 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 ! dpkg --compare-versions "$current_version" "lt" "$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 + +# Each release can hold multiple assets (e.g. binaries for different architectures, source code, etc.) +echo "${#assets[@]} available asset(s)" + +#================================================= +# UPDATE SOURCE FILES +#================================================= + +# Here we use the $assets variable to get the resources published in the upstream release. +# Here is an example for Grav, it has to be adapted in accordance with how the upstream releases look like. + +# Let's loop over the array of assets URLs +for asset_url in ${assets[@]}; do + +echo "Handling asset at $asset_url" + +# Assign the asset to a source file in conf/ directory +# Here we base the source file name upon a unique keyword in the assets url +# Leave $src empty to ignore the asset +case $asset_url in + *"linux-386"*) + src="app.386" + ;; + *"linux-amd64"*) + src="app.amd64" + ;; + *"linux-arm64"*) + src="app.arm64" + ;; + *"linux-armv5"*) + src="app.armv5" + ;; + *"linux-armv6"*) + src="app.armv6" + ;; + *"linux-armv7"*) + src="app.armv7" + ;; + *) + src="" + ;; +esac + +# If $src is not empty, let's process the asset +if [ ! -z "$src" ]; then + +# Create the temporary directory +tempdir="$(mktemp -d)" + +# Download sources and calculate checksum +filename=${asset_url##*/} +curl --silent -4 -L $asset_url -o "$tempdir/$filename" +checksum=$(sha256sum "$tempdir/$filename" | head -c 64) + +# Delete temporary directory +rm -rf $tempdir + +# Get extension +if [[ $filename == *.tar.gz ]]; then + extension=tar.gz +else + extension=${filename##*.} +fi + +# Rewrite source file +cat < conf/$src.src +SOURCE_URL=$asset_url +SOURCE_SUM=$checksum +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=$extension +SOURCE_IN_SUBDIR=true +EOT +echo "... conf/$src.src updated" + +else +echo "... asset ignored" +fi + +done + +#================================================= +# 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 new file mode 100644 index 0000000..b037c1b --- /dev/null +++ b/.github/workflows/updater.yml @@ -0,0 +1,50 @@ +# 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 7:00 UTC + schedule: + - cron: '0 7 * * *' +jobs: + updater: + runs-on: ubuntu-latest + steps: + - name: Fetch the source code + uses: actions/checkout@v2 + 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@v3 + 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/README.md b/README.md index cc592d9..cf7e53b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in Monitoring system and time series database -**Shipped version:** 2.28.0~ynh1 +**Shipped version:** 2.33.1~ynh1 **Demo:** https://demo.do.prometheus.io diff --git a/README_fr.md b/README_fr.md index e06e414..6a6208a 100644 --- a/README_fr.md +++ b/README_fr.md @@ -13,7 +13,7 @@ Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour Supervision chronologique de systèmes et services -**Version incluse :** 2.28.0~ynh1 +**Version incluse :** 2.33.1~ynh1 **Démo :** https://demo.do.prometheus.io diff --git a/conf/app.386.src b/conf/app.386.src index 5020061..a6dba8c 100644 --- a/conf/app.386.src +++ b/conf/app.386.src @@ -1,7 +1,5 @@ -SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.28.0/prometheus-2.28.0.linux-386.tar.gz -SOURCE_SUM=9666d90c981f80d82b605e022eb2af61b65e7d0962a95b6b5fe67cc395cbf915 +SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.33.1/prometheus-2.33.1.linux-386.tar.gz +SOURCE_SUM=2a02adc1ba695c4efd0ca9c466d253c4c3008d49c2d65339ce4f0f98e2052ee2 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true -SOURCE_EXTRACT=true -SOURCE_FILENAME=prometheus.tar.gz diff --git a/conf/app.amd64.src b/conf/app.amd64.src index aa9d32f..1ff5a63 100644 --- a/conf/app.amd64.src +++ b/conf/app.amd64.src @@ -1,7 +1,5 @@ -SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.28.0/prometheus-2.28.0.linux-amd64.tar.gz -SOURCE_SUM=d2d0ded275090a13208114b633abe41c40e14c83ff5ec07230d79b4da1d8e701 +SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.33.1/prometheus-2.33.1.linux-amd64.tar.gz +SOURCE_SUM=55de29727fc4d3977d3400c54fa222ebb52755bd0201936f1e1052fea6f2b44b SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true -SOURCE_EXTRACT=true -SOURCE_FILENAME=prometheus.tar.gz diff --git a/conf/app.arm64.src b/conf/app.arm64.src index 3f98241..abc695c 100644 --- a/conf/app.arm64.src +++ b/conf/app.arm64.src @@ -1,7 +1,5 @@ -SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.28.0/prometheus-2.28.0.linux-arm64.tar.gz -SOURCE_SUM=c6ef6c0ef92bfc9682c9ae5275c5bd5ab2c6f74178201e15f2bfd08cc8a139a8 +SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.33.1/prometheus-2.33.1.linux-arm64.tar.gz +SOURCE_SUM=21d89df7a98882a1a872bd3210aeaac3915a7f7be9f2ad28c986c80ad64ee77d SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true -SOURCE_EXTRACT=true -SOURCE_FILENAME=prometheus.tar.gz diff --git a/conf/app.armv5.src b/conf/app.armv5.src index bffef3d..8f15a66 100644 --- a/conf/app.armv5.src +++ b/conf/app.armv5.src @@ -1,7 +1,5 @@ -SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.28.0/prometheus-2.28.0.linux-armv5.tar.gz -SOURCE_SUM=5cc36a0254c118639a461e52f7736f4b86e0f2775ab552cb426f0a4748c8cd8b +SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.33.1/prometheus-2.33.1.linux-armv5.tar.gz +SOURCE_SUM=bc51a6073ac1d90c8ebd548694baeb8c6dff91945cf00b763c65a11412b7f945 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true -SOURCE_EXTRACT=true -SOURCE_FILENAME=prometheus.tar.gz diff --git a/conf/app.armv6.src b/conf/app.armv6.src index 55e35d9..e35210d 100644 --- a/conf/app.armv6.src +++ b/conf/app.armv6.src @@ -1,7 +1,5 @@ -SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.28.0/prometheus-2.28.0.linux-armv6.tar.gz -SOURCE_SUM=8346908ad57777d1cd7b2a3e95e0b7beb9891251f768caf863895bb051a65209 +SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.33.1/prometheus-2.33.1.linux-armv6.tar.gz +SOURCE_SUM=16769a890ce803f571a5c68689dd9c6401a9d80e491352eaefd5eeff6441e460 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true -SOURCE_EXTRACT=true -SOURCE_FILENAME=prometheus.tar.gz diff --git a/conf/app.armv7.src b/conf/app.armv7.src index d68a186..b49fcd6 100644 --- a/conf/app.armv7.src +++ b/conf/app.armv7.src @@ -1,7 +1,5 @@ -SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.28.0/prometheus-2.28.0.linux-armv7.tar.gz -SOURCE_SUM=214632282772a45d4ac2c7053f95d252b8eb8c279ff228aba2ac25329ae903f8 +SOURCE_URL=https://github.com/prometheus/prometheus/releases/download/v2.33.1/prometheus-2.33.1.linux-armv7.tar.gz +SOURCE_SUM=09e285f098c36a5f2e7cf065fb38bd8f65ef262aeda728aac48b8cbb40ef34cc SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true -SOURCE_EXTRACT=true -SOURCE_FILENAME=prometheus.tar.gz diff --git a/conf/nginx.conf b/conf/nginx.conf index 3af9f44..a25d1a1 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -6,7 +6,7 @@ location __PATH__ { rewrite ^ https://$server_name$request_uri? permanent; } - proxy_pass http://127.0.0.1:__PORT____PATH__; + proxy_pass http://127.0.0.1:__PORT__; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/conf/systemd.service b/conf/systemd.service index f2ba69c..d7eda5c 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -9,7 +9,8 @@ Group=__APP__ WorkingDirectory=__FINALPATH__/ ExecStart=__FINALPATH__/prometheus \ --config.file=__FINALPATH__/prometheus.yml --web.enable-admin-api \ - --web.external-url=__PATH__ \ + --web.external-url=__PATH__/ \ + --web.route-prefix=__PATH__/ \ --web.listen-address=localhost:__PORT__ StandardOutput=append:/var/log/__APP__/__APP__.log StandardError=inherit diff --git a/manifest.json b/manifest.json index 0e496e0..9d903ab 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Monitoring system and time series database", "fr": "Supervision chronologique de systèmes et services" }, - "version": "2.28.0~ynh1", + "version": "2.33.1~ynh1", "url": "https://prometheus.io", "upstream": { "license": "Apache-2.0", @@ -30,7 +30,7 @@ "mysql" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain", diff --git a/scripts/_common.sh b/scripts/_common.sh index 2e05e4d..b1a92dd 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,12 +7,14 @@ version="2.28.0" architecture="" case $(uname -m) in - i386) architecture="386" ;; - x86_64) architecture="amd64" ;; - armv5) architecture="armv5" ;; - armv6) architecture="armv6" ;; - armv7) architecture="armv7" ;; - arm) dpkg --print-architecture | grep -q "arm64" && architecture="arm64" || architecture="unsupported arm" ;; + i386) architecture="386" ;; + x86_64) architecture="amd64" ;; + armv5) architecture="armv5" ;; + armv6) architecture="armv6" ;; + armv7) architecture="armv7" ;; + armv7l) architecture="armv7" ;; + aarch64) architecture="arm64" ;; + *) ynh_die --message="Sorry, your architecture $YNH_ARCH is not supported." ;; esac #================================================= diff --git a/scripts/change_url b/scripts/change_url index 084986c..fa17761 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -94,6 +94,8 @@ then ynh_add_nginx_config # Create a dedicated service config ynh_add_systemd_config +else + path_url="$old_path" fi # Change the domain for NGINX diff --git a/scripts/install b/scripts/install index 94ad0e8..2815c83 100755 --- a/scripts/install +++ b/scripts/install @@ -113,6 +113,7 @@ ynh_add_systemd_config ynh_script_progression --message="Configuring the app..." --weight=2 ynh_replace_string --match_string="localhost:9090" --replace_string="localhost:$port" --target_file="$final_path/prometheus.yml" +echo " metrics_path: $path_url/metrics" >> "$final_path/prometheus.yml" #================================================= # GENERIC FINALIZATION