mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
ability to upgrade to a specfic version with the script
This commit is contained in:
parent
bd2688feb6
commit
e8517f1ea1
@ -1,5 +1,7 @@
|
|||||||
# Changelog Fab-manager
|
# Changelog Fab-manager
|
||||||
|
|
||||||
|
- Ability to upgrade to a specific version with the script
|
||||||
|
|
||||||
## v5.0.1 2021 June 10
|
## v5.0.1 2021 June 10
|
||||||
|
|
||||||
- Updated upgrade instructions
|
- Updated upgrade instructions
|
||||||
@ -23,7 +25,7 @@
|
|||||||
- Generate footprints in a more reproductible way
|
- Generate footprints in a more reproductible way
|
||||||
- Task to reset the stripe payment methods in test mode
|
- Task to reset the stripe payment methods in test mode
|
||||||
- Validate on server side the reservation of slots restricted to subscribers
|
- 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
|
- 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: cannot select the recurrence end date on Safari or Internet Explorer
|
||||||
- Fix a bug: build status badge is not working
|
- Fix a bug: build status badge is not working
|
||||||
|
@ -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. [Update manually](#update-manually)<br/>
|
||||||
4.2.2. [Manual update steps](#manual-update-steps)<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.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>
|
<a name="preliminary-steps"></a>
|
||||||
## Preliminary steps
|
## Preliminary steps
|
||||||
@ -172,7 +174,7 @@ Then, you'll need to perform the upgrade with the following command:
|
|||||||
> - v3.1.2
|
> - v3.1.2
|
||||||
> - v4.0.4
|
> - v4.0.4
|
||||||
> - v4.4.6
|
> - v4.4.6
|
||||||
> - v4.7.12
|
> - v4.7.13
|
||||||
> After that, you can finally update to the last version
|
> 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
|
> ⚠ 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>
|
<a name="upgrade-to-a-specific-version"></a>
|
||||||
### Upgrade to a specific version
|
### 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
|
```yaml
|
||||||
image: sleede/fab-manager
|
image: sleede/fab-manager
|
||||||
```
|
```
|
||||||
|
@ -6,11 +6,15 @@ parseparams()
|
|||||||
SCRIPTS=()
|
SCRIPTS=()
|
||||||
ENVIRONMENTS=()
|
ENVIRONMENTS=()
|
||||||
PREPROCESSING=()
|
PREPROCESSING=()
|
||||||
while getopts "hys:p:c:e:" opt; do
|
while getopts "hyt:s:p:c:e:" opt; do
|
||||||
case "${opt}" in
|
case "${opt}" in
|
||||||
y)
|
y)
|
||||||
Y=true
|
Y=true
|
||||||
;;
|
;;
|
||||||
|
t)
|
||||||
|
TARGET=$OPTARG
|
||||||
|
FORCE_TARGET=true
|
||||||
|
;;
|
||||||
s)
|
s)
|
||||||
SCRIPTS+=("$OPTARG")
|
SCRIPTS+=("$OPTARG")
|
||||||
;;
|
;;
|
||||||
@ -39,9 +43,10 @@ jq() {
|
|||||||
docker run --rm -i -v "${PWD}:/data" imega/jq "$@"
|
docker run --rm -i -v "${PWD}:/data" imega/jq "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# set $SERVICE and $YES_ALL
|
||||||
config()
|
config()
|
||||||
{
|
{
|
||||||
echo -ne "Checking user... "
|
echo -e "Checking user... "
|
||||||
if [[ "$(whoami)" != "root" ]] && ! groups | grep docker
|
if [[ "$(whoami)" != "root" ]] && ! groups | grep docker
|
||||||
then
|
then
|
||||||
echo "Please add your current user to the docker group OR run this script as root."
|
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"
|
[ "$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()
|
version_error()
|
||||||
{
|
{
|
||||||
printf "\n\n\e[91m[ ❌ ] You are running Fab-manager version %s\n\e[39m" "${VERSION:-undetermined}"
|
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
|
exit 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# set $VERSION
|
||||||
version_check()
|
version_check()
|
||||||
{
|
{
|
||||||
VERSION=$(docker-compose exec -T "$SERVICE" cat .fabmanager-version 2>/dev/null)
|
VERSION=$(docker-compose exec -T "$SERVICE" cat .fabmanager-version 2>/dev/null)
|
||||||
if [[ $? = 1 ]]; then
|
if [[ $? = 1 ]]; then
|
||||||
VERSION=$(docker-compose exec -T "$SERVICE" cat package.json | jq -r '.version')
|
VERSION=$(docker-compose exec -T "$SERVICE" cat package.json | jq -r '.version')
|
||||||
fi
|
fi
|
||||||
|
target_version
|
||||||
|
if [ "$TARGET" = 'custom' ]; then return; fi
|
||||||
|
|
||||||
if verlt "$VERSION" 2.8.3; then
|
if verlt "$VERSION" 2.8.3 && verlt 2.8.3 "$TARGET"; then
|
||||||
version_error "v2.8.3"
|
version_error "v2.8.3 first"
|
||||||
elif verlt "$VERSION" 3.1.2; then
|
elif verlt "$VERSION" 3.1.2 && verlt 3.1.2 "$TARGET"; then
|
||||||
version_error "v3.1.2"
|
version_error "v3.1.2 first"
|
||||||
elif verlt "$VERSION" 4.0.4; then
|
elif verlt "$VERSION" 4.0.4 && verlt 4.0.4 "$TARGET"; then
|
||||||
version_error "v4.0.4"
|
version_error "v4.0.4 first"
|
||||||
elif verlt "$VERSION" 4.4.6; then
|
elif verlt "$VERSION" 4.4.6 && verlt 4.4.6 "$TARGET"; then
|
||||||
version_error "v4.4.6"
|
version_error "v4.4.6 first"
|
||||||
elif verlt "$VERSION" 4.7.12; then
|
elif verlt "$VERSION" 4.7.13 && verlt 4.7.13 "$TARGET"; then
|
||||||
version_error "v4.7.12"
|
version_error "v4.7.13 first"
|
||||||
|
elif verlt "$TARGET" "$VERSION"; then
|
||||||
|
version_error "a version > $VERSION"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +152,7 @@ compile_assets()
|
|||||||
ENV_ARGS=$(for i in "${COMPOSE_ENVS[@]}"; do sed 's/: /=/g;s/^/-e /g' <<< "$i"; done)
|
ENV_ARGS=$(for i in "${COMPOSE_ENVS[@]}"; do sed 's/: /=/g;s/^/-e /g' <<< "$i"; done)
|
||||||
PG_ID=$(docker-compose ps -q postgres)
|
PG_ID=$(docker-compose ps -q postgres)
|
||||||
if [[ "$PG_ID" = "" ]]; then
|
if [[ "$PG_ID" = "" ]]; then
|
||||||
|
restore_tag
|
||||||
printf "\e[91m[ ❌ ] PostgreSQL container is not running, unable to compile the assets\e[39m\nExiting..."
|
printf "\e[91m[ ❌ ] PostgreSQL container is not running, unable to compile the assets\e[39m\nExiting..."
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
@ -133,6 +160,7 @@ compile_assets()
|
|||||||
clean_env_file
|
clean_env_file
|
||||||
# shellcheck disable=SC2068
|
# 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
|
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"
|
printf "\e[91m[ ❌ ] Something went wrong while compiling the assets, please check the logs above.\e[39m\nExiting...\n"
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
@ -141,13 +169,29 @@ compile_assets()
|
|||||||
mv public/new_packs public/packs
|
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()
|
upgrade()
|
||||||
{
|
{
|
||||||
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp "[91m::[0m [1mProceed with the upgrade?[0m (Y/n) " confirm </dev/tty
|
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp "[91m::[0m [1mProceed with upgrading to version $TARGET ?[0m (Y/n) " confirm </dev/tty
|
||||||
if [[ "$confirm" = "n" ]]; then exit 2; fi
|
if [[ "$confirm" = "n" ]]; then exit 2; fi
|
||||||
|
|
||||||
add_environments
|
add_environments
|
||||||
|
force_version
|
||||||
if ! docker-compose pull "$SERVICE"; then
|
if ! docker-compose pull "$SERVICE"; then
|
||||||
|
restore_tag
|
||||||
printf "\e[91m[ ❌ ] An error occurred, detected service name: %s\e[39m\nExiting..." "$SERVICE"
|
printf "\e[91m[ ❌ ] An error occurred, detected service name: %s\e[39m\nExiting..." "$SERVICE"
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
@ -164,29 +208,33 @@ upgrade()
|
|||||||
if [[ $? != 0 ]]; then
|
if [[ $? != 0 ]]; then
|
||||||
printf "\e[93m[ ⚠ ] Something may have went wrong while running \"%s\", please check the logs above...\e[39m\n" "$SCRIPT"
|
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 "[91m::[0m [1mIgnore and continue?[0m (Y/n) " confirm </dev/tty
|
[[ "$YES_ALL" = "true" ]] && confirm="y" || read -rp "[91m::[0m [1mIgnore and continue?[0m (Y/n) " confirm </dev/tty
|
||||||
if [[ "$confirm" = "n" ]]; then exit 4; fi
|
if [[ "$confirm" = "n" ]]; then restore_tag; exit 4; fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
for PRE in "${PREPROCESSING[@]}"; do
|
for PRE in "${PREPROCESSING[@]}"; do
|
||||||
printf "\e[91m::\e[0m \e[1mRunning preprocessing command %s...\e[0m\n" "$PRE"
|
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
|
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"
|
printf "\e[91m[ ❌ ] Something went wrong while running \"%s\", please check the logs above.\e[39m\nExiting...\n" "$PRE"
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
compile_assets
|
compile_assets
|
||||||
if ! docker-compose run --rm "$SERVICE" bundle exec rake db:migrate; then
|
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"
|
printf "\e[91m[ ❌ ] Something went wrong while migrating the database, please check the logs above.\e[39m\nExiting...\n"
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
for COMMAND in "${COMMANDS[@]}"; do
|
for COMMAND in "${COMMANDS[@]}"; do
|
||||||
printf "\e[91m::\e[0m \e[1mRunning command %s...\e[0m\n" "$COMMAND"
|
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
|
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"
|
printf "\e[91m[ ❌ ] Something went wrong while running \"%s\", please check the logs above.\e[39m\nExiting...\n" "$COMMAND"
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
|
restore_tag
|
||||||
docker ps
|
docker ps
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,6 +254,7 @@ usage()
|
|||||||
Options:
|
Options:
|
||||||
-h Print this message and quit
|
-h Print this message and quit
|
||||||
-y Answer yes to all questions
|
-y Answer yes to all questions
|
||||||
|
-t <string> Force the upgrade to target the specified version
|
||||||
-p <string> Run the preprocessing command (TODO DEPLOY)
|
-p <string> Run the preprocessing command (TODO DEPLOY)
|
||||||
-c <string> Provides additional upgrade command, run in the context of the app (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)
|
-s <string> Executes a remote script (TODO DEPOY)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user