From e8517f1ea1f4ed01dcef98b73297472605474180 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Fri, 11 Jun 2021 13:47:25 +0200 Subject: [PATCH] ability to upgrade to a specfic version with the script --- CHANGELOG.md | 4 +- doc/production_readme.md | 17 +++++++-- setup/upgrade.sh | 79 ++++++++++++++++++++++++++++++++-------- 3 files changed, 81 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b06a1fb72..161775868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog Fab-manager +- Ability to upgrade to a specific version with the script + ## v5.0.1 2021 June 10 - Updated upgrade instructions @@ -23,7 +25,7 @@ - Generate footprints in a more reproductible way - Task to reset the stripe payment methods in test mode - Validate on server side the reservation of slots restricted to subscribers -− Unified and documented upgrade exit codes +- Unified and documented upgrade exit codes - During setup, ask for the name of the external network and create it, if it does not already exists - Fix a bug: cannot select the recurrence end date on Safari or Internet Explorer - Fix a bug: build status badge is not working diff --git a/doc/production_readme.md b/doc/production_readme.md index 893ce4cfd..741453936 100644 --- a/doc/production_readme.md +++ b/doc/production_readme.md @@ -19,7 +19,9 @@ You will need to be root through the rest of the setup. 4.2. [Update manually](#update-manually)
4.2.2. [Manual update steps](#manual-update-steps)
4.3. [Upgrade to the last version](#upgrade-to-the-last-version)
-4.4. [Upgrade to a specific version](#upgrade-to-a-specific-version) +4.4. [Upgrade to a specific version](#upgrade-to-a-specific-version)
+4.4.1. [With scripted update](#with-scripted-update)
+4.4.2. [With manual update](#with-manual-update)
## Preliminary steps @@ -172,7 +174,7 @@ Then, you'll need to perform the upgrade with the following command: > - v3.1.2 > - v4.0.4 > - v4.4.6 -> - v4.7.12 +> - v4.7.13 > After that, you can finally update to the last version > ⚠ With versions < 4.3.3, you must replace `bundle exec rails` with `bundle exec rake` in all the commands above @@ -231,7 +233,16 @@ __Example:__ to update from v2.4.0 to v2.4.3, you will run the specific commands ### Upgrade to a specific version -Edit your [/apps/fabmanager/docker-compose.yml](../setup/docker-compose.yml#L4) file and change the following line: + +#### With scripted update +The easiest way to proceed is to provide the target version to the upgrade script, with the `-t` parameter, like this: +```bash +\curl -sSL upgrade.fab.mn | bash -s -- -t 4.7.13 +``` + + +#### With manual update +If you are upgrading manually, edit your [/apps/fabmanager/docker-compose.yml](../setup/docker-compose.yml#L4) file and change the following line: ```yaml image: sleede/fab-manager ``` diff --git a/setup/upgrade.sh b/setup/upgrade.sh index 32ff14b8b..63d686b37 100644 --- a/setup/upgrade.sh +++ b/setup/upgrade.sh @@ -6,11 +6,15 @@ parseparams() SCRIPTS=() ENVIRONMENTS=() PREPROCESSING=() - while getopts "hys:p:c:e:" opt; do + while getopts "hyt:s:p:c:e:" opt; do case "${opt}" in y) Y=true ;; + t) + TARGET=$OPTARG + FORCE_TARGET=true + ;; s) SCRIPTS+=("$OPTARG") ;; @@ -39,9 +43,10 @@ jq() { docker run --rm -i -v "${PWD}:/data" imega/jq "$@" } +# set $SERVICE and $YES_ALL config() { - echo -ne "Checking user... " + echo -e "Checking user... " if [[ "$(whoami)" != "root" ]] && ! groups | grep docker then echo "Please add your current user to the docker group OR run this script as root." @@ -74,30 +79,51 @@ verlt() { [ "$1" = "$2" ] && return 1 || verlte "$1" "$2" } +# set $TAG and $TARGET +target_version() +{ + TAG=$(yq eval ".services.$SERVICE.image" docker-compose.yml | grep -o ':.*') + + if [ -n "$TARGET" ]; then return; fi + + if [[ "$TAG" =~ ^:release-v[\.0-9]+$ ]]; then + TARGET=$(echo "$TAG" | grep -Eo '[\.0-9]{5}') + elif [ "$TAG" = ":latest" ]; then + TARGET=$(\curl -sSL "https://hub.fab-manager.com/api/versions/latest" | jq -r '.semver') + else + TARGET='custom' + fi +} + version_error() { printf "\n\n\e[91m[ ❌ ] You are running Fab-manager version %s\n\e[39m" "${VERSION:-undetermined}" - printf "You must upgrade Fab-manager to %s first.\nPlease refer to http://update.doc.fab.mn for instructions\n" "$1" 1>&2 + printf "You must upgrade Fab-manager to %s.\nPlease refer to http://update.doc.fab.mn for instructions\n" "$1" 1>&2 exit 3 } +# set $VERSION version_check() { VERSION=$(docker-compose exec -T "$SERVICE" cat .fabmanager-version 2>/dev/null) if [[ $? = 1 ]]; then VERSION=$(docker-compose exec -T "$SERVICE" cat package.json | jq -r '.version') fi + target_version + if [ "$TARGET" = 'custom' ]; then return; fi - if verlt "$VERSION" 2.8.3; then - version_error "v2.8.3" - elif verlt "$VERSION" 3.1.2; then - version_error "v3.1.2" - elif verlt "$VERSION" 4.0.4; then - version_error "v4.0.4" - elif verlt "$VERSION" 4.4.6; then - version_error "v4.4.6" - elif verlt "$VERSION" 4.7.12; then - version_error "v4.7.12" + if verlt "$VERSION" 2.8.3 && verlt 2.8.3 "$TARGET"; then + version_error "v2.8.3 first" + elif verlt "$VERSION" 3.1.2 && verlt 3.1.2 "$TARGET"; then + version_error "v3.1.2 first" + elif verlt "$VERSION" 4.0.4 && verlt 4.0.4 "$TARGET"; then + version_error "v4.0.4 first" + elif verlt "$VERSION" 4.4.6 && verlt 4.4.6 "$TARGET"; then + version_error "v4.4.6 first" + elif verlt "$VERSION" 4.7.13 && verlt 4.7.13 "$TARGET"; then + version_error "v4.7.13 first" + elif verlt "$TARGET" "$VERSION"; then + version_error "a version > $VERSION" fi } @@ -126,6 +152,7 @@ compile_assets() ENV_ARGS=$(for i in "${COMPOSE_ENVS[@]}"; do sed 's/: /=/g;s/^/-e /g' <<< "$i"; done) PG_ID=$(docker-compose ps -q postgres) if [[ "$PG_ID" = "" ]]; then + restore_tag printf "\e[91m[ ❌ ] PostgreSQL container is not running, unable to compile the assets\e[39m\nExiting..." exit 4 fi @@ -133,6 +160,7 @@ compile_assets() clean_env_file # shellcheck disable=SC2068 if ! docker run --rm --env-file ./config/env ${ENV_ARGS[@]} --link "$PG_ID" --net "$PG_NET_ID" -v "${PWD}/public/new_packs:/usr/src/app/public/packs" "$IMAGE" bundle exec rake assets:precompile; then + restore_tag printf "\e[91m[ ❌ ] Something went wrong while compiling the assets, please check the logs above.\e[39m\nExiting...\n" exit 4 fi @@ -141,13 +169,29 @@ compile_assets() mv public/new_packs public/packs } +force_version() +{ + if [ "$FORCE_TARGET" != "true" ]; then return; fi + + yq -i eval ".services.$SERVICE.image = \"sleede/fab-manager:release-v$TARGET\"" docker-compose.yml +} + +restore_tag() +{ + if [ "$FORCE_TARGET" != "true" ]; then return; fi + + yq -i eval ".services.$SERVICE.image = \"sleede/fab-manager$TAG\"" docker-compose.yml +} + upgrade() { - [[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp ":: Proceed with the upgrade? (Y/n) " confirm Force the upgrade to target the specified version -p Run the preprocessing command (TODO DEPLOY) -c Provides additional upgrade command, run in the context of the app (TODO DEPLOY) -s Executes a remote script (TODO DEPOY)