1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

ability to upgrade to a specfic version with the script

This commit is contained in:
Sylvain 2021-06-11 13:47:25 +02:00
parent bd2688feb6
commit e8517f1ea1
3 changed files with 81 additions and 19 deletions

View File

@ -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

View File

@ -19,7 +19,9 @@ You will need to be root through the rest of the setup.
4.2. [Update manually](#update-manually)<br/>
4.2.2. [Manual update steps](#manual-update-steps)<br/>
4.3. [Upgrade to the last version](#upgrade-to-the-last-version)<br/>
4.4. [Upgrade to a specific version](#upgrade-to-a-specific-version)
4.4. [Upgrade to a specific version](#upgrade-to-a-specific-version)<br/>
4.4.1. [With scripted update](#with-scripted-update)<br/>
4.4.2. [With manual update](#with-manual-update)<br/>
<a name="preliminary-steps"></a>
## 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
<a name="upgrade-to-a-specific-version"></a>
### Upgrade to a specific version
Edit your [/apps/fabmanager/docker-compose.yml](../setup/docker-compose.yml#L4) file and change the following line:
<a name="with-scripted-update"></a>
#### 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
```
<a name="with-manual-update"></a>
#### 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
```

View File

@ -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 </dev/tty
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp ":: Proceed with upgrading to version $TARGET ? (Y/n) " confirm </dev/tty
if [[ "$confirm" = "n" ]]; then exit 2; fi
add_environments
force_version
if ! docker-compose pull "$SERVICE"; then
restore_tag
printf "\e[91m[ ❌ ] An error occurred, detected service name: %s\e[39m\nExiting..." "$SERVICE"
exit 4
fi
@ -164,29 +208,33 @@ upgrade()
if [[ $? != 0 ]]; then
printf "\e[93m[ ⚠ ] Something may have went wrong while running \"%s\", please check the logs above...\e[39m\n" "$SCRIPT"
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp ":: Ignore and continue? (Y/n) " confirm </dev/tty
if [[ "$confirm" = "n" ]]; then exit 4; fi
if [[ "$confirm" = "n" ]]; then restore_tag; exit 4; fi
fi
done
for PRE in "${PREPROCESSING[@]}"; do
printf "\e[91m::\e[0m \e[1mRunning preprocessing command %s...\e[0m\n" "$PRE"
if ! docker-compose run --rm "$SERVICE" bundle exec "$PRE" </dev/tty; then
restore_tag
printf "\e[91m[ ❌ ] Something went wrong while running \"%s\", please check the logs above.\e[39m\nExiting...\n" "$PRE"
exit 4
fi
done
compile_assets
if ! docker-compose run --rm "$SERVICE" bundle exec rake db:migrate; then
restore_tag
printf "\e[91m[ ❌ ] Something went wrong while migrating the database, please check the logs above.\e[39m\nExiting...\n"
exit 4
fi
for COMMAND in "${COMMANDS[@]}"; do
printf "\e[91m::\e[0m \e[1mRunning command %s...\e[0m\n" "$COMMAND"
if ! docker-compose run --rm "$SERVICE" bundle exec "$COMMAND" </dev/tty; then
restore_tag
printf "\e[91m[ ❌ ] Something went wrong while running \"%s\", please check the logs above.\e[39m\nExiting...\n" "$COMMAND"
exit 4
fi
done
docker-compose up -d
restore_tag
docker ps
}
@ -206,6 +254,7 @@ usage()
Options:
-h Print this message and quit
-y Answer yes to all questions
-t <string> Force the upgrade to target the specified version
-p <string> Run the preprocessing command (TODO DEPLOY)
-c <string> Provides additional upgrade command, run in the context of the app (TODO DEPLOY)
-s <string> Executes a remote script (TODO DEPOY)