From 063c9437a72964f3cc8148e8e870958e70c17661 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Mon, 19 Apr 2021 02:51:30 +0300 Subject: [PATCH 01/58] Run up command on module add/remove This not only rebuilds the image, but also updates the containers --- commands/modules.sh | 92 ++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/commands/modules.sh b/commands/modules.sh index dd6e7eb..0600635 100755 --- a/commands/modules.sh +++ b/commands/modules.sh @@ -26,6 +26,8 @@ MODE_NO_BUILD=false MODE_NO_SCRIPTS=false MODE_PRINT_ACTIVE_ONLY=false +UP_ARGS=() + while [[ "$#" -gt 0 ]]; do case $1 in -h | --help) @@ -51,9 +53,11 @@ while [[ "$#" -gt 0 ]]; do ;; --no-build) MODE_NO_BUILD=true + UP_ARGS+=("--no-build") ;; --no-scripts) MODE_NO_SCRIPTS=true + UP_ARGS+=("--no-scripts") ;; -a | --active) MODE_PRINT_ACTIVE_ONLY=true @@ -247,63 +251,59 @@ for MODULE in "${MODULES[@]}"; do ;; esac - if ! $MODE_QUIET && ! $MODE_NO_BUILD && $needs_rebuild; then - if ! $MODE_FORCE; then - printf "Do you want to rebuild the project? (run with ${FLG_COL}--force${RESET} to always build)\n" - printf "${YELLOW}WARNING${RESET}: This will ${RED}overwrite${RESET} existing docker files [y/N] " - read -n 1 -r - echo "" - if [[ $REPLY =~ ^[Yy]$ ]]; then - bash $ENTRYPOINT build --force - else - continue - fi - else - bash $ENTRYPOINT build --force - fi + # Add base blueprint module scripts first + path="$BLUEPRINT_DIR/modules/$MODULE/scripts/$ACTION.sh" + if [[ -f "$path" ]]; then + script_paths+=("$path") fi - if ! $MODE_NO_SCRIPTS; then - script_paths=() - - # Add base blueprint module scripts first - path="$BLUEPRINT_DIR/modules/$MODULE/scripts/$ACTION.sh" - if [[ -f "$path" ]]; then - script_paths+=("$path") - fi + # Then add environment module scripts + path="$ENV_DIR/modules/$MODULE/scripts/$ACTION.sh" + if [[ -f "$path" ]]; then + script_paths+=("$path") + fi +done - # Then add environment module scripts - path="$ENV_DIR/modules/$MODULE/scripts/$ACTION.sh" - if [[ -f "$path" ]]; then - script_paths+=("$path") +if ! $MODE_QUIET && ! $MODE_NO_BUILD && $needs_rebuild; then + if ! $MODE_FORCE; then + printf "Do you want to rebuild the project? (run with ${FLG_COL}--force${RESET} to always build)\n" + printf "${YELLOW}WARNING${RESET}: This will ${RED}overwrite${RESET} existing docker files [y/N] " + read -n 1 -r + echo "" + if [[ $REPLY =~ ^[Yy]$ ]]; then + bash $ENTRYPOINT up --force ${UP_ARGS[@]} fi + else + bash $ENTRYPOINT up --force ${UP_ARGS[@]} + fi +fi - status=0 - - # export SCRIPT_VARS - # export SCRIPT_VARS_ENV - # export SCRIPT_VARS_BUILD_ARGS - source "$ROOT_DIR/includes/get-script-vars.sh" +if ! $MODE_NO_SCRIPTS; then + status=0 - for path in "${script_paths[@]}"; do - printf "Running script for module '$MODULE'...\n" - debug_print "Running script: ${path#$BLUEPRINT_DIR/}" + # export SCRIPT_VARS + # export SCRIPT_VARS_ENV + # export SCRIPT_VARS_BUILD_ARGS + source "$ROOT_DIR/includes/get-script-vars.sh" - PROGRAM="$(source "$ROOT_DIR/includes/script/prepare.sh" "$(cat "$path")")" + for path in "${script_paths[@]}"; do + printf "Running script for module '$MODULE'...\n" + debug_print "Running script: ${path#$BLUEPRINT_DIR/}" - command="bash -c \"$PROGRAM\"" - bash $ENTRYPOINT "${SCRIPT_VARS_ENV[@]}" $DEFAULT_SERVICE exec "$command" + PROGRAM="$(source "$ROOT_DIR/includes/script/prepare.sh" "$(cat "$path")")" - status=$? + command="bash -c \"$PROGRAM\"" + bash $ENTRYPOINT "${SCRIPT_VARS_ENV[@]}" $DEFAULT_SERVICE exec "$command" - if [[ $status > 0 ]]; then - break - fi - done + status=$? if [[ $status > 0 ]]; then - printf -- "${RED}ERROR${RESET}: Module script returned non-zero code: ${path#$BLUEPRINT_DIR/}\n" - exit $status + break fi + done + + if [[ $status > 0 ]]; then + printf -- "${RED}ERROR${RESET}: Module script returned non-zero code: ${path#$BLUEPRINT_DIR/}\n" + exit $status fi -done +fi From a17ef401ad2fa17b3f9fd09baffc014a2b8eb22c Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Mon, 19 Apr 2021 02:52:20 +0300 Subject: [PATCH 02/58] Add --no-chown flag to modules command --- commands/modules.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/commands/modules.sh b/commands/modules.sh index 0600635..194fc9c 100755 --- a/commands/modules.sh +++ b/commands/modules.sh @@ -37,6 +37,9 @@ while [[ "$#" -gt 0 ]]; do printf " ${FLG_COL}-a${RESET}, ${FLG_COL}--active${RESET}" printf "\t\tOnly list active modules\n" + printf " ${FLG_COL}--no-chown${RESET}" + printf "\t\t\tPass --no-chown to 'sync' command\n" + printf " ${FLG_COL}--no-build${RESET}" printf "\t\t\tDon't attempt to build\n" @@ -59,6 +62,9 @@ while [[ "$#" -gt 0 ]]; do MODE_NO_SCRIPTS=true UP_ARGS+=("--no-scripts") ;; + --no-chown) + UP_ARGS+=("--no-chown") + ;; -a | --active) MODE_PRINT_ACTIVE_ONLY=true ;; From 1772609ee8e9004446883f90077b6ea6b67b1951 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Mon, 19 Apr 2021 02:52:43 +0300 Subject: [PATCH 03/58] Silence helper scripts by default --- commands/build.sh | 2 +- commands/modules.sh | 3 ++- commands/up.sh | 2 +- includes/blueprint/compile.sh | 2 +- includes/get-script-vars.sh | 31 +++++++++++++++++++++---------- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/commands/build.sh b/commands/build.sh index 3e36ae8..78d2fad 100755 --- a/commands/build.sh +++ b/commands/build.sh @@ -107,7 +107,7 @@ non_debug_print " ${GREEN}done${RESET}\n" # export SCRIPT_VARS # export SCRIPT_VARS_ENV # export SCRIPT_VARS_BUILD_ARGS -source "$ROOT_DIR/includes/get-script-vars.sh" +SILENT=false source "$ROOT_DIR/includes/get-script-vars.sh" # # Build docker-compose.yml diff --git a/commands/modules.sh b/commands/modules.sh index 194fc9c..411143f 100755 --- a/commands/modules.sh +++ b/commands/modules.sh @@ -109,7 +109,7 @@ source "$ROOT_DIR/includes/blueprint/populate_env.sh" "" yq_read_array MODULES_TO_LOAD 'modules' EXPLICIT_MODULES_LIST=(${MODULES_TO_LOAD[@]}) -source "$ROOT_DIR/includes/resolve-dependencies.sh" ${MODULES_TO_LOAD[@]} +SILENT=true source "$ROOT_DIR/includes/resolve-dependencies.sh" ${MODULES_TO_LOAD[@]} ACTIVE_MODULES_LIST=(${MODULES_TO_LOAD[@]}) MODULES_LIST=() @@ -231,6 +231,7 @@ else done fi +script_paths=() needs_rebuild=false for MODULE in "${MODULES[@]}"; do diff --git a/commands/up.sh b/commands/up.sh index 3fda85f..4a9bc9b 100755 --- a/commands/up.sh +++ b/commands/up.sh @@ -131,7 +131,7 @@ if [[ -f "$path" ]]; then debug_print "Found: ${path#$BLUEPRINT_DIR/}" fi -source "$ROOT_DIR/includes/resolve-dependencies.sh" "" +SILENT=true source "$ROOT_DIR/includes/resolve-dependencies.sh" "" ACTIVE_MODULES_LIST=(${MODULES_TO_LOAD[@]}) for module in ${MODULES_TO_LOAD[@]}; do diff --git a/includes/blueprint/compile.sh b/includes/blueprint/compile.sh index 59d4cf9..d8dc845 100755 --- a/includes/blueprint/compile.sh +++ b/includes/blueprint/compile.sh @@ -30,7 +30,7 @@ if [[ -n $CHECKPOINT ]]; then cd "$BLUEPRINT_DIR" git checkout $CHECKPOINT 2> /dev/null if [[ $? -eq 0 ]]; then - printf "Version: ${CYAN}$CHECKPOINT${RESET}\n" + ! $SILENT && printf "Version: ${CYAN}$CHECKPOINT${RESET}\n" else printf "${RED}ERROR${RESET}: Unable to checkout version $CHECKPOINT\n" exit 1 diff --git a/includes/get-script-vars.sh b/includes/get-script-vars.sh index 7a34517..949fc49 100644 --- a/includes/get-script-vars.sh +++ b/includes/get-script-vars.sh @@ -2,14 +2,19 @@ if [[ -z "$BLUEPRINT_PATH" ]]; then # export BLUEPRINT_PATH - SILENT=false source "$ROOT_DIR/includes/blueprint/compile.sh" "$BLUEPRINT" + SILENT=true source "$ROOT_DIR/includes/blueprint/compile.sh" "$BLUEPRINT" +fi + +if [[ -z $SILENT ]]; then + SILENT=false fi # Read values from merged blueprint -debug_newline_print "Reading configuration..." +! $SILENT && debug_newline_print "Reading configuration..." -yq_read_keys BUILD_ARGS_KEYS "build_args" "$BLUEPRINT_PATH" && non_debug_print "." +yq_read_keys BUILD_ARGS_KEYS "build_args" "$BLUEPRINT_PATH" +! $SILENT && non_debug_print "." SCRIPT_VARS=() @@ -23,28 +28,34 @@ add_variable "ENV_DIR" "${ENV_DIR#"$PWD/"}" add_variable "ENV_NAME" "$ENV_NAME" for variable in ${BUILD_ARGS_KEYS[@]}; do - yq_read_value value "build_args.$variable" "$BLUEPRINT_PATH" && non_debug_print "." + yq_read_value value "build_args.$variable" "$BLUEPRINT_PATH" + ! $SILENT && non_debug_print "." # Replace build argument value with env variable value if it is set if [[ -n ${!variable+x} ]]; then value="${!variable:-}" fi - add_variable "$variable" "$value" && non_debug_print "." + add_variable "$variable" "$value" + ! $SILENT && non_debug_print "." done -yq_read_keys DEPENDENCIES_KEYS "dependencies" "$BLUEPRINT_PATH" && non_debug_print "." +yq_read_keys DEPENDENCIES_KEYS "dependencies" "$BLUEPRINT_PATH" +! $SILENT && non_debug_print "." for key in "${DEPENDENCIES_KEYS[@]}"; do - yq_read_array DEPS "dependencies.$key" "$BLUEPRINT_PATH" && non_debug_print "." + yq_read_array DEPS "dependencies.$key" "$BLUEPRINT_PATH" + ! $SILENT && non_debug_print "." key="$(echo "$key" | tr [:lower:] [:upper:])" add_variable "DEPS_$key" "${DEPS[*]}" done -yq_read_keys PURGE_KEYS "purge" "$BLUEPRINT_PATH" && non_debug_print "." +yq_read_keys PURGE_KEYS "purge" "$BLUEPRINT_PATH" +! $SILENT && non_debug_print "." for key in "${PURGE_KEYS[@]}"; do - yq_read_array PURGE "purge.$key" "$BLUEPRINT_PATH" && non_debug_print "." + yq_read_array PURGE "purge.$key" "$BLUEPRINT_PATH" + ! $SILENT && non_debug_print "." key="$(echo "$key" | tr [:lower:] [:upper:])" add_variable "PURGE_$key" "${PURGE[*]}" done @@ -69,7 +80,7 @@ for module in "${MODULES_TO_LOAD[@]}"; do fi done -non_debug_print " ${GREEN}done${RESET}\n" +! $SILENT && non_debug_print " ${GREEN}done${RESET}\n" export SCRIPT_VARS From df5a732da886f15a731832d3f53c5d6ad2e0461d Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Mon, 19 Apr 2021 03:34:04 +0300 Subject: [PATCH 04/58] Update up.sh Sync after scripts have been run --- commands/up.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/commands/up.sh b/commands/up.sh index 4a9bc9b..a124ab8 100755 --- a/commands/up.sh +++ b/commands/up.sh @@ -185,6 +185,8 @@ if [[ $status > 0 ]]; then exit $status fi -if ! $MODE_SCRIPTS_ONLY && $MODE_SYNC; then - bash $ENTRYPOINT sync --no-chown --skip-user +# Sync again, because new files could have been created by scripts + +if ! $MODE_NO_SCRIPTS && $MODE_SYNC; then + bash $ENTRYPOINT sync ${SYNC_ARGS[@]} --skip-user fi From f07db756cc7348938caa1a96919524790c0b7a5a Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Mon, 19 Apr 2021 17:28:57 +0300 Subject: [PATCH 05/58] Update version.sh Add ability to switch version --- commands/version.sh | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/commands/version.sh b/commands/version.sh index c0b416a..5a93209 100755 --- a/commands/version.sh +++ b/commands/version.sh @@ -4,20 +4,36 @@ shift case $1 in -h | --help) - printf "${CMD_COL}version${RESET}\t\t\tGet current version\n" + printf "${CMD_COL}version${RESET} [change ${ARG_COL}${RESET}]" + printf "\tGet current version or switch version to \n" exit - + ;; +change) + NEW_VERSION="$2" + + if [[ -z "$NEW_VERSION" ]]; then + printf "${RED}ERROR${RESET}: pathspec must not be empty\n" + bash $ENTRYPOINT version -h + exit 1 + fi ;; esac -if ! $AS_FUNCTION; then - printf "Current version: " -fi - PREVIOUS_DIR=$PWD cd $ROOT_DIR +if [[ -n "$NEW_VERSION" ]]; then + git checkout "$NEW_VERSION" + if [[ $? > 0 ]]; then + exit 1 + fi +fi + +if ! $AS_FUNCTION; then + printf "Current version: " +fi + printf "$(git describe --match "v*" --abbrev=0 --tags)" printf " ($(git rev-parse --short HEAD))" From 236ba9dfe50ef0c1a97bf113ebdcc21694012594 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Mon, 19 Apr 2021 17:40:11 +0300 Subject: [PATCH 06/58] Update process.sh Update help text --- commands/process.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/process.sh b/commands/process.sh index a263d31..1ae036e 100755 --- a/commands/process.sh +++ b/commands/process.sh @@ -54,7 +54,7 @@ fi while [[ "$#" -gt 0 ]]; do case $1 in -h | --help) - printf "${CMD_COL}process${RESET} [${FLG_COL}options${RESET}] ${ARG_COL}${RESET}" + printf "${CMD_COL}process${RESET} ${ARG_COL}${RESET} [${FLG_COL}options${RESET}]" printf "\t" printf "Preprocess dockerfile template from the blueprint\n" From 133bc013042b0be67650f56d40fb055abbc1b19c Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Mon, 19 Apr 2021 17:40:11 +0300 Subject: [PATCH 07/58] Update process.sh Update help text --- commands/process.sh | 2 +- commands/version.sh | 28 ++++++---------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/commands/process.sh b/commands/process.sh index a263d31..1ae036e 100755 --- a/commands/process.sh +++ b/commands/process.sh @@ -54,7 +54,7 @@ fi while [[ "$#" -gt 0 ]]; do case $1 in -h | --help) - printf "${CMD_COL}process${RESET} [${FLG_COL}options${RESET}] ${ARG_COL}${RESET}" + printf "${CMD_COL}process${RESET} ${ARG_COL}${RESET} [${FLG_COL}options${RESET}]" printf "\t" printf "Preprocess dockerfile template from the blueprint\n" diff --git a/commands/version.sh b/commands/version.sh index 5a93209..c0b416a 100755 --- a/commands/version.sh +++ b/commands/version.sh @@ -4,36 +4,20 @@ shift case $1 in -h | --help) - printf "${CMD_COL}version${RESET} [change ${ARG_COL}${RESET}]" - printf "\tGet current version or switch version to \n" + printf "${CMD_COL}version${RESET}\t\t\tGet current version\n" exit - ;; -change) - NEW_VERSION="$2" - - if [[ -z "$NEW_VERSION" ]]; then - printf "${RED}ERROR${RESET}: pathspec must not be empty\n" - bash $ENTRYPOINT version -h - exit 1 - fi + ;; esac -PREVIOUS_DIR=$PWD - -cd $ROOT_DIR - -if [[ -n "$NEW_VERSION" ]]; then - git checkout "$NEW_VERSION" - if [[ $? > 0 ]]; then - exit 1 - fi -fi - if ! $AS_FUNCTION; then printf "Current version: " fi +PREVIOUS_DIR=$PWD + +cd $ROOT_DIR + printf "$(git describe --match "v*" --abbrev=0 --tags)" printf " ($(git rev-parse --short HEAD))" From c973bb69ae717a4b820ae22d7faacd613d611bb9 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 05:20:28 +0300 Subject: [PATCH 08/58] Add .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b03b8a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tmp/ +cache/ From d8f86fb15d6ca491edc980868ccfc119b46d8e15 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 05:21:25 +0300 Subject: [PATCH 09/58] Update entrypoint.sh --- entrypoint.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index be5f34e..0cbbf9a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,16 +1,16 @@ #!/bin/bash # MIT License -# +# # Copyright (c) 2020-2021 Aleksei Ivanov -# +# # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. From c48a1331e410722ed3789d2e299975c25129f239 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 05:54:08 +0300 Subject: [PATCH 10/58] Fix empty blueprint hash on compile --- includes/blueprint/compile.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/blueprint/compile.sh b/includes/blueprint/compile.sh index d8dc845..74c7ba3 100755 --- a/includes/blueprint/compile.sh +++ b/includes/blueprint/compile.sh @@ -135,13 +135,14 @@ fi cd $BLUEPRINT_DIR -hash=$(git rev-parse HEAD) 2>/dev/null && \ - ! $SILENT && non_debug_print "." +hash=$(git rev-parse HEAD) 2>/dev/null if [[ $? > 0 ]]; then unset hash fi +! $SILENT && non_debug_print "." + cd $PROJECT_DIR # ... and store it for the version lock From 45a504b69aca67a1edcebd77037bf86c82358d3b Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 05:54:24 +0300 Subject: [PATCH 11/58] Make initial compilation silent --- commands/new.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/new.sh b/commands/new.sh index d091f65..133246a 100755 --- a/commands/new.sh +++ b/commands/new.sh @@ -130,7 +130,7 @@ fi if ! [[ -f "$PWD/$PROJECT_BLUEPRINT_FILE" ]]; then # export BLUEPRINT_PATH - SILENT=false source "$ROOT_DIR/includes/blueprint/compile.sh" "$BLUEPRINT" + SILENT=true source "$ROOT_DIR/includes/blueprint/compile.sh" "$BLUEPRINT" debug_switch_context "NEW" # Populate project blueprint From 3ca64761a6db940ff324a5356efde0782ea6bb71 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 05:54:37 +0300 Subject: [PATCH 12/58] Update temporary file lifetime --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0cbbf9a..3304205 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,9 +26,9 @@ export TEMP_DIR="$LOCAL_DIR/tmp" export ENTRYPOINT="$ROOT_DIR/entrypoint.sh" export PROJECT_BLUEPRINT_FILE=docker-blueprint.yml -# Delete temporary files older than 5 minutes +# Delete temporary files older than 30 minutes mkdir -p "$TEMP_DIR" -find "$TEMP_DIR" -mindepth 1 -type f -mmin +5 -delete +find "$TEMP_DIR" -mindepth 1 -type f -mmin +30 -delete mkdir -p $LOCAL_DIR source "$ROOT_DIR/includes/update-gitignore.sh" From 92b0d9a663a818dcb7d7297c8397a0823f41a71f Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 06:01:46 +0300 Subject: [PATCH 13/58] Revert "Update temporary file lifetime" This reverts commit 3ca64761a6db940ff324a5356efde0782ea6bb71. --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3304205..0cbbf9a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -26,9 +26,9 @@ export TEMP_DIR="$LOCAL_DIR/tmp" export ENTRYPOINT="$ROOT_DIR/entrypoint.sh" export PROJECT_BLUEPRINT_FILE=docker-blueprint.yml -# Delete temporary files older than 30 minutes +# Delete temporary files older than 5 minutes mkdir -p "$TEMP_DIR" -find "$TEMP_DIR" -mindepth 1 -type f -mmin +30 -delete +find "$TEMP_DIR" -mindepth 1 -type f -mmin +5 -delete mkdir -p $LOCAL_DIR source "$ROOT_DIR/includes/update-gitignore.sh" From 5bc1d854d0f0975d776b6fa84522b4aaafcfe26f Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 06:03:01 +0300 Subject: [PATCH 14/58] Do not remove temporary blueprint This file is used by `get-script-vars.sh` later during `up` stage --- commands/new.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/commands/new.sh b/commands/new.sh index 133246a..7c45280 100755 --- a/commands/new.sh +++ b/commands/new.sh @@ -195,8 +195,6 @@ if ! [[ -f "$PWD/$PROJECT_BLUEPRINT_FILE" ]]; then fi done - rm -f "$BLUEPRINT_PATH" - fi if $FORCE_GENERATE; then From 459642853ea8d63d19164407241e255570149dbb Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 06:14:06 +0300 Subject: [PATCH 15/58] Update run.sh --- commands/run.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands/run.sh b/commands/run.sh index 661ade7..28cb31c 100755 --- a/commands/run.sh +++ b/commands/run.sh @@ -140,6 +140,8 @@ elif [[ -n "$PROJECT_CONTEXT" ]]; then debug_print "Using DEFAULT context: $PROJECT_CONTEXT" fi +debug_print "Program to run:\n%s\n" "$PROGRAM" + # Escape backslashes first PROGRAM="$(echo "$PROGRAM" | sed -E 's/\\/\\\\/g')" # Escape variable sign ($) to execute it inside runtime @@ -149,10 +151,9 @@ PROGRAM="$(echo "$PROGRAM" | sed -E 's/"/\\"/g')" command="env ${ENV_PREFIX[*]} $RUNTIME \"$PROGRAM\"" -debug_print "Program to run:\n$PROGRAM" debug_print "Running..." -bash $ENTRYPOINT ${ENTRYPOINT_ARGS[*]} -- $SERVICE $COMMAND_VERB "$command" +bash $ENTRYPOINT ${ENTRYPOINT_ARGS[*]} $SERVICE $COMMAND_VERB "$command" for key in "${ENVIRONMENT_KEYS[@]}"; do unset $key From 81a5693b4bc708b5a5aa60c038ea2a1815757bcf Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 19:21:34 +0300 Subject: [PATCH 16/58] Add upgrade command --- commands/upgrade.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 commands/upgrade.sh diff --git a/commands/upgrade.sh b/commands/upgrade.sh new file mode 100755 index 0000000..3e60835 --- /dev/null +++ b/commands/upgrade.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +debug_switch_context "UPGRADE" + +debug_print "Running the command..." + +shift + +MODE_FORCE=false +MODE_NO_BUILD=false + +while [[ "$#" -gt 0 ]]; do + case $1 in + -h | --help) + printf "${CMD_COL}upgrade${RESET}" + printf "\t\t\tUpgrade the blueprint version to the latest version\n" + exit + ;; + -f | --force) + MODE_FORCE=true + ;; + --no-build) + MODE_NO_BUILD=true + ;; + esac + + shift +done + +yq_read_value BLUEPRINT 'from' +yq_read_value PREVIOUS_VERSION 'version' + +debug_print "Current version: $PREVIOUS_VERSION" + +source "$ROOT_DIR/includes/blueprint/populate_env.sh" "" + +cd "$BLUEPRINT_DIR" + +CHECKPOINT="$(git rev-parse HEAD)" +if [[ $? -eq 0 ]]; then + if [[ "$CHECKPOINT" != "$PREVIOUS_VERSION" ]]; then + printf "Latest version: ${CYAN}$CHECKPOINT${RESET}\n" + else + printf "Already using latest version\n" + exit + fi +else + printf "${RED}ERROR${RESET}: Unable to checkout version $CHECKPOINT\n" + exit 1 +fi + +cd "$PROJECT_DIR" + +debug_print "Writing current version: $CHECKPOINT" + +yq_write_value "version" "$CHECKPOINT" + +if ! $MODE_NO_BUILD; then + if ! $MODE_FORCE; then + printf "Do you want to rebuild the project? (run with ${FLG_COL}--force${RESET} to always build)\n" + printf "${YELLOW}WARNING${RESET}: This will ${RED}overwrite${RESET} existing docker files [y/N] " + read -n 1 -r + echo "" + if [[ $REPLY =~ ^[Yy]$ ]]; then + bash $ENTRYPOINT build --force + fi + else + bash $ENTRYPOINT build --force + fi +fi From cdfc45440dd9d6fa2ce9e6d6c51ff0404edb9795 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 20:18:45 +0300 Subject: [PATCH 17/58] Update install.sh Make empty path check more robust --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index a5d135d..37433b0 100755 --- a/install.sh +++ b/install.sh @@ -7,7 +7,7 @@ REQUIREMENTS=( ) for PROGRAM in "${REQUIREMENTS[@]}"; do - if [[ -z $(which $PROGRAM) ]]; then + if [[ -z "$(which $PROGRAM)" ]]; then echo "Error: '$PROGRAM' is not installed. Please install '$PROGRAM' first." exit 1 fi From 5c8d945c3d826778e86929e71cb5c3c878cbb6b9 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 20:19:04 +0300 Subject: [PATCH 18/58] Update installer Try to automatically install yq --- install.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/install.sh b/install.sh index 37433b0..fd72eee 100755 --- a/install.sh +++ b/install.sh @@ -13,6 +13,19 @@ for PROGRAM in "${REQUIREMENTS[@]}"; do fi done +if [[ -z "$(which yq)" ]]; then + printf "You do not appear to have 'yq' installed (https://github.com/mikefarah/yq)\n" + printf "For the best experience it is recommended to install a standalone version of 'yq'\n" + printf "\n" + printf "Do you want to attempt to automatically install 'yq'? [Y/n] " + read -n 1 -r + echo "" + if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Trying to install using webi..." + curl -sS https://webinstall.dev/yq@4 | bash + fi +fi + PROJECT_DIR=~/.docker-blueprint ENTRYPOINT="$PROJECT_DIR/entrypoint.sh" From fe92c49e04d55b01b20396b6343840f4af35199b Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 21:11:59 +0300 Subject: [PATCH 19/58] Refactor out yq install script --- install.sh | 16 ++++------------ installer/yq.sh | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 installer/yq.sh diff --git a/install.sh b/install.sh index fd72eee..5a71000 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,8 @@ #!/bin/bash +HIGHLIGHT="\033[1;33m" +RESET="\033[0;0m" + REQUIREMENTS=( git docker @@ -13,18 +16,7 @@ for PROGRAM in "${REQUIREMENTS[@]}"; do fi done -if [[ -z "$(which yq)" ]]; then - printf "You do not appear to have 'yq' installed (https://github.com/mikefarah/yq)\n" - printf "For the best experience it is recommended to install a standalone version of 'yq'\n" - printf "\n" - printf "Do you want to attempt to automatically install 'yq'? [Y/n] " - read -n 1 -r - echo "" - if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then - echo "Trying to install using webi..." - curl -sS https://webinstall.dev/yq@4 | bash - fi -fi +source "$(dirname "$BASH_SOURCE")/installer/yq.sh" PROJECT_DIR=~/.docker-blueprint ENTRYPOINT="$PROJECT_DIR/entrypoint.sh" diff --git a/installer/yq.sh b/installer/yq.sh new file mode 100644 index 0000000..8c156df --- /dev/null +++ b/installer/yq.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [[ -z "$(which yq)" ]]; then + printf "You do not appear to have 'yq' installed (${HIGHLIGHT}https://github.com/mikefarah/yq${RESET})\n" + printf "For the best experience it is recommended to install a standalone version of 'yq'\n" + printf "\n" + printf "Do you want to attempt to automatically install 'yq'? [Y/n] " + read -n 1 -r + echo "" + if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Trying to install using webi..." + curl -sS https://webinstall.dev/yq@4 | bash + fi +fi From 1ce93e814ceb0401f46f4227c110298af47b5e9d Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 21:18:44 +0300 Subject: [PATCH 20/58] Add docker install script --- install.sh | 8 ++++++++ installer/docker.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 installer/docker.sh diff --git a/install.sh b/install.sh index 5a71000..d9f6c7f 100755 --- a/install.sh +++ b/install.sh @@ -9,6 +9,14 @@ REQUIREMENTS=( docker-compose ) +is_wsl=false + +if grep -qEi "(Microsoft|WSL)" /proc/version &>/dev/null; then + is_wsl=true +fi + +source "$(dirname "$BASH_SOURCE")/installer/docker.sh" + for PROGRAM in "${REQUIREMENTS[@]}"; do if [[ -z "$(which $PROGRAM)" ]]; then echo "Error: '$PROGRAM' is not installed. Please install '$PROGRAM' first." diff --git a/installer/docker.sh b/installer/docker.sh new file mode 100644 index 0000000..ed0a0d8 --- /dev/null +++ b/installer/docker.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +if [[ -z "$(which docker)" ]]; then + printf "You do not appear to have 'docker' installed (${HIGHLIGHT}https://docker.com${RESET})\n" + + if $is_wsl; then + printf "We detected that you are running this installer under WSL and\n" + printf "that 'docker' is not installed. Please install Docker for Desktop\n" + printf "for the best experience: ${HIGHLIGHT}https://www.docker.com/products/docker-desktop${RESET}\n" + printf "\n" + printf "Do you want to continue installing? [y/N] " + read -n 1 -r + echo "" + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi + else + printf "Since docker-blueprint is designed to work with docker, you will not be able to use it without docker\n" + printf "We can attempt to automatically install docker using convinience script:\n" + printf "${HIGHLIGHT}https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script${RESET}\n" + printf "\n" + printf "Do you want to automatically install docker? [Y/n] " + read -n 1 -r + echo "" + if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Trying to install docker..." + curl -fsSL https://get.docker.com | sh + if [[ $? > 0 ]]; then + printf "Unable to install docker, skipping..." + fi + fi + fi +fi From f057b0076050e6bc845b2c02fa5b5c282e3f59a7 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 21:25:57 +0300 Subject: [PATCH 21/58] Add docker-compose installer --- install.sh | 1 + installer/docker-compose.sh | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 installer/docker-compose.sh diff --git a/install.sh b/install.sh index d9f6c7f..d169587 100755 --- a/install.sh +++ b/install.sh @@ -16,6 +16,7 @@ if grep -qEi "(Microsoft|WSL)" /proc/version &>/dev/null; then fi source "$(dirname "$BASH_SOURCE")/installer/docker.sh" +source "$(dirname "$BASH_SOURCE")/installer/docker-compose.sh" for PROGRAM in "${REQUIREMENTS[@]}"; do if [[ -z "$(which $PROGRAM)" ]]; then diff --git a/installer/docker-compose.sh b/installer/docker-compose.sh new file mode 100644 index 0000000..e97e198 --- /dev/null +++ b/installer/docker-compose.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if [[ -z "$(which docker-compose)" ]]; then + printf "You do not appear to have 'docker-compose' installed (${HIGHLIGHT}https://docs.docker.com/compose/install${RESET})\n" + + printf "Since docker-blueprint is designed to work with docker-compose, you will not be able to use it without docker-compose\n" + printf "We can attempt to automatically install docker-compose using curl:\n" + printf "${HIGHLIGHT}https://docs.docker.com/compose/install/#install-compose-on-linux-systems${RESET}\n" + printf "\n" + printf "Do you want to automatically install docker-compose? [Y/n] " + read -n 1 -r + echo "" + if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Trying to install docker-compose..." + sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + if [[ $? > 0 ]]; then + printf "Unable to install docker-compose, skipping..." + fi + sudo chmod +x /usr/local/bin/docker-compose + fi +fi From 3fa1dedfcc3f6570a2445d02f7397c791518d1a0 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 21:28:33 +0300 Subject: [PATCH 22/58] Embed install scripts into install.sh --- install.sh | 78 +++++++++++++++++++++++++++++++++++-- installer/docker-compose.sh | 21 ---------- installer/docker.sh | 33 ---------------- installer/yq.sh | 14 ------- 4 files changed, 75 insertions(+), 71 deletions(-) delete mode 100644 installer/docker-compose.sh delete mode 100644 installer/docker.sh delete mode 100644 installer/yq.sh diff --git a/install.sh b/install.sh index d169587..448c011 100755 --- a/install.sh +++ b/install.sh @@ -15,8 +15,65 @@ if grep -qEi "(Microsoft|WSL)" /proc/version &>/dev/null; then is_wsl=true fi -source "$(dirname "$BASH_SOURCE")/installer/docker.sh" -source "$(dirname "$BASH_SOURCE")/installer/docker-compose.sh" +# +# docker installer +# + +if [[ -z "$(which docker)" ]]; then + printf "You do not appear to have 'docker' installed (${HIGHLIGHT}https://docker.com${RESET})\n" + + if $is_wsl; then + printf "We detected that you are running this installer under WSL and\n" + printf "that 'docker' is not installed. Please install Docker for Desktop\n" + printf "for the best experience: ${HIGHLIGHT}https://www.docker.com/products/docker-desktop${RESET}\n" + printf "\n" + printf "Do you want to continue installing? [y/N] " + read -n 1 -r + echo "" + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi + else + printf "Since docker-blueprint is designed to work with docker, you will not be able to use it without docker\n" + printf "We can attempt to automatically install docker using convinience script:\n" + printf "${HIGHLIGHT}https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script${RESET}\n" + printf "\n" + printf "Do you want to automatically install docker? [Y/n] " + read -n 1 -r + echo "" + if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Trying to install docker..." + curl -fsSL https://get.docker.com | sh + if [[ $? > 0 ]]; then + printf "Unable to install docker, skipping..." + fi + fi + fi +fi + +# +# docker-compose installer +# + +if [[ -z "$(which docker-compose)" ]]; then + printf "You do not appear to have 'docker-compose' installed (${HIGHLIGHT}https://docs.docker.com/compose/install${RESET})\n" + + printf "Since docker-blueprint is designed to work with docker-compose, you will not be able to use it without docker-compose\n" + printf "We can attempt to automatically install docker-compose using curl:\n" + printf "${HIGHLIGHT}https://docs.docker.com/compose/install/#install-compose-on-linux-systems${RESET}\n" + printf "\n" + printf "Do you want to automatically install docker-compose? [Y/n] " + read -n 1 -r + echo "" + if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Trying to install docker-compose..." + sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + if [[ $? > 0 ]]; then + printf "Unable to install docker-compose, skipping..." + fi + sudo chmod +x /usr/local/bin/docker-compose + fi +fi for PROGRAM in "${REQUIREMENTS[@]}"; do if [[ -z "$(which $PROGRAM)" ]]; then @@ -25,7 +82,22 @@ for PROGRAM in "${REQUIREMENTS[@]}"; do fi done -source "$(dirname "$BASH_SOURCE")/installer/yq.sh" +# +# yq installer +# + +if [[ -z "$(which yq)" ]]; then + printf "You do not appear to have 'yq' installed (${HIGHLIGHT}https://github.com/mikefarah/yq${RESET})\n" + printf "For the best experience it is recommended to install a standalone version of 'yq'\n" + printf "\n" + printf "Do you want to attempt to automatically install 'yq'? [Y/n] " + read -n 1 -r + echo "" + if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Trying to install using webi..." + curl -sS https://webinstall.dev/yq@4 | bash + fi +fi PROJECT_DIR=~/.docker-blueprint ENTRYPOINT="$PROJECT_DIR/entrypoint.sh" diff --git a/installer/docker-compose.sh b/installer/docker-compose.sh deleted file mode 100644 index e97e198..0000000 --- a/installer/docker-compose.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -if [[ -z "$(which docker-compose)" ]]; then - printf "You do not appear to have 'docker-compose' installed (${HIGHLIGHT}https://docs.docker.com/compose/install${RESET})\n" - - printf "Since docker-blueprint is designed to work with docker-compose, you will not be able to use it without docker-compose\n" - printf "We can attempt to automatically install docker-compose using curl:\n" - printf "${HIGHLIGHT}https://docs.docker.com/compose/install/#install-compose-on-linux-systems${RESET}\n" - printf "\n" - printf "Do you want to automatically install docker-compose? [Y/n] " - read -n 1 -r - echo "" - if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then - echo "Trying to install docker-compose..." - sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - if [[ $? > 0 ]]; then - printf "Unable to install docker-compose, skipping..." - fi - sudo chmod +x /usr/local/bin/docker-compose - fi -fi diff --git a/installer/docker.sh b/installer/docker.sh deleted file mode 100644 index ed0a0d8..0000000 --- a/installer/docker.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -if [[ -z "$(which docker)" ]]; then - printf "You do not appear to have 'docker' installed (${HIGHLIGHT}https://docker.com${RESET})\n" - - if $is_wsl; then - printf "We detected that you are running this installer under WSL and\n" - printf "that 'docker' is not installed. Please install Docker for Desktop\n" - printf "for the best experience: ${HIGHLIGHT}https://www.docker.com/products/docker-desktop${RESET}\n" - printf "\n" - printf "Do you want to continue installing? [y/N] " - read -n 1 -r - echo "" - if [[ ! $REPLY =~ ^[Yy]$ ]]; then - exit 1 - fi - else - printf "Since docker-blueprint is designed to work with docker, you will not be able to use it without docker\n" - printf "We can attempt to automatically install docker using convinience script:\n" - printf "${HIGHLIGHT}https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script${RESET}\n" - printf "\n" - printf "Do you want to automatically install docker? [Y/n] " - read -n 1 -r - echo "" - if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then - echo "Trying to install docker..." - curl -fsSL https://get.docker.com | sh - if [[ $? > 0 ]]; then - printf "Unable to install docker, skipping..." - fi - fi - fi -fi diff --git a/installer/yq.sh b/installer/yq.sh deleted file mode 100644 index 8c156df..0000000 --- a/installer/yq.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -if [[ -z "$(which yq)" ]]; then - printf "You do not appear to have 'yq' installed (${HIGHLIGHT}https://github.com/mikefarah/yq${RESET})\n" - printf "For the best experience it is recommended to install a standalone version of 'yq'\n" - printf "\n" - printf "Do you want to attempt to automatically install 'yq'? [Y/n] " - read -n 1 -r - echo "" - if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then - echo "Trying to install using webi..." - curl -sS https://webinstall.dev/yq@4 | bash - fi -fi From 9d005dc6ff3d367c21a56f65e422ecde55f95009 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 21:34:26 +0300 Subject: [PATCH 23/58] Update install.sh Export PATH after installing yq --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index 448c011..8713857 100755 --- a/install.sh +++ b/install.sh @@ -96,6 +96,7 @@ if [[ -z "$(which yq)" ]]; then if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then echo "Trying to install using webi..." curl -sS https://webinstall.dev/yq@4 | bash + export PATH="$HOME/.local/bin:$PATH" fi fi From 695849b4ef1f841af0912a85f762f6621b29881a Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 21:37:00 +0300 Subject: [PATCH 24/58] Revert "Update install.sh" This reverts commit 9d005dc6ff3d367c21a56f65e422ecde55f95009. --- install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/install.sh b/install.sh index 8713857..448c011 100755 --- a/install.sh +++ b/install.sh @@ -96,7 +96,6 @@ if [[ -z "$(which yq)" ]]; then if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then echo "Trying to install using webi..." curl -sS https://webinstall.dev/yq@4 | bash - export PATH="$HOME/.local/bin:$PATH" fi fi From 2ed1dbb9c990823eab2dae5e1d96fbac83ea202e Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 21:38:00 +0300 Subject: [PATCH 25/58] Update install.sh Add notice after installing yq --- install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/install.sh b/install.sh index 448c011..9cdeea6 100755 --- a/install.sh +++ b/install.sh @@ -96,6 +96,9 @@ if [[ -z "$(which yq)" ]]; then if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then echo "Trying to install using webi..." curl -sS https://webinstall.dev/yq@4 | bash + printf "\n" + printf " ${HIGHLIGHT}Please restart your shell in order for the changes to take effect${RESET}\n" + printf "\n" fi fi From c3a351a4afdf66b5a280a9f46e451128a7633d05 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 21:38:41 +0300 Subject: [PATCH 26/58] Update install.sh Update requirements --- install.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/install.sh b/install.sh index 9cdeea6..f364fab 100755 --- a/install.sh +++ b/install.sh @@ -5,10 +5,15 @@ RESET="\033[0;0m" REQUIREMENTS=( git - docker - docker-compose ) +for PROGRAM in "${REQUIREMENTS[@]}"; do + if [[ -z "$(which $PROGRAM)" ]]; then + echo "Error: '$PROGRAM' is not installed. Please install '$PROGRAM' first." + exit 1 + fi +done + is_wsl=false if grep -qEi "(Microsoft|WSL)" /proc/version &>/dev/null; then @@ -75,13 +80,6 @@ if [[ -z "$(which docker-compose)" ]]; then fi fi -for PROGRAM in "${REQUIREMENTS[@]}"; do - if [[ -z "$(which $PROGRAM)" ]]; then - echo "Error: '$PROGRAM' is not installed. Please install '$PROGRAM' first." - exit 1 - fi -done - # # yq installer # From 89c491185e1132327b1fc9c709d49b10660dc603 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 22:01:25 +0300 Subject: [PATCH 27/58] Update install.sh Cosmetic text changes --- install.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/install.sh b/install.sh index f364fab..04ee758 100755 --- a/install.sh +++ b/install.sh @@ -28,9 +28,9 @@ if [[ -z "$(which docker)" ]]; then printf "You do not appear to have 'docker' installed (${HIGHLIGHT}https://docker.com${RESET})\n" if $is_wsl; then - printf "We detected that you are running this installer under WSL and\n" - printf "that 'docker' is not installed. Please install Docker for Desktop\n" - printf "for the best experience: ${HIGHLIGHT}https://www.docker.com/products/docker-desktop${RESET}\n" + printf "We detected that you are running this installer under WSL.\n" + printf "Please install Docker for Desktop for the best experience:\n" + printf "${HIGHLIGHT}https://www.docker.com/products/docker-desktop${RESET}\n" printf "\n" printf "Do you want to continue installing? [y/N] " read -n 1 -r @@ -39,21 +39,21 @@ if [[ -z "$(which docker)" ]]; then exit 1 fi else - printf "Since docker-blueprint is designed to work with docker, you will not be able to use it without docker\n" - printf "We can attempt to automatically install docker using convinience script:\n" + printf "We can attempt to automatically install 'docker' using convinience script:\n" printf "${HIGHLIGHT}https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script${RESET}\n" printf "\n" - printf "Do you want to automatically install docker? [Y/n] " + printf "Do you want to automatically install 'docker'? [Y/n] " read -n 1 -r echo "" if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then - echo "Trying to install docker..." + echo "Trying to install 'docker'..." curl -fsSL https://get.docker.com | sh if [[ $? > 0 ]]; then - printf "Unable to install docker, skipping..." + echo "Unable to install 'docker', skipping..." fi fi fi + echo "" fi # @@ -63,21 +63,22 @@ fi if [[ -z "$(which docker-compose)" ]]; then printf "You do not appear to have 'docker-compose' installed (${HIGHLIGHT}https://docs.docker.com/compose/install${RESET})\n" - printf "Since docker-blueprint is designed to work with docker-compose, you will not be able to use it without docker-compose\n" - printf "We can attempt to automatically install docker-compose using curl:\n" + printf "We can attempt to automatically install 'docker-compose' using curl:\n" printf "${HIGHLIGHT}https://docs.docker.com/compose/install/#install-compose-on-linux-systems${RESET}\n" printf "\n" - printf "Do you want to automatically install docker-compose? [Y/n] " + printf "Do you want to automatically install 'docker-compose'? [Y/n] " read -n 1 -r echo "" if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then - echo "Trying to install docker-compose..." + echo "Trying to install 'docker-compose'..." sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose if [[ $? > 0 ]]; then - printf "Unable to install docker-compose, skipping..." + echo "Unable to install 'docker-compose', skipping..." + else + sudo chmod +x /usr/local/bin/docker-compose fi - sudo chmod +x /usr/local/bin/docker-compose fi + echo "" fi # @@ -95,7 +96,7 @@ if [[ -z "$(which yq)" ]]; then echo "Trying to install using webi..." curl -sS https://webinstall.dev/yq@4 | bash printf "\n" - printf " ${HIGHLIGHT}Please restart your shell in order for the changes to take effect${RESET}\n" + printf "${HIGHLIGHT}Please restart your shell in order for the changes to take effect${RESET}\n" printf "\n" fi fi From 74320345ca54bae0d74000c9cc5ace5e6462ae56 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 22:34:11 +0300 Subject: [PATCH 28/58] Explicitly specify REPLY on read --- commands/environment.sh | 2 +- commands/lock.sh | 2 +- commands/modules.sh | 2 +- commands/upgrade.sh | 2 +- install.sh | 17 ++++------------- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/commands/environment.sh b/commands/environment.sh index 7383668..e7d7381 100755 --- a/commands/environment.sh +++ b/commands/environment.sh @@ -64,7 +64,7 @@ if ! $MODE_QUIET; then if ! $MODE_FORCE; then printf "Do you want to rebuild the project? (run with ${FLG_COL}--force${RESET} to always build)\n" printf "${YELLOW}WARNING${RESET}: This will ${RED}overwrite${RESET} existing docker files [y/N] " - read -n 1 -r + read -n 1 -r REPLY if [[ $REPLY =~ ^[Yy]$ ]]; then echo "" bash $ENTRYPOINT build --force diff --git a/commands/lock.sh b/commands/lock.sh index ed09ef8..bae2ae3 100755 --- a/commands/lock.sh +++ b/commands/lock.sh @@ -60,7 +60,7 @@ if ! $MODE_NO_BUILD; then if ! $MODE_FORCE; then printf "Do you want to rebuild the project? (run with ${FLG_COL}--force${RESET} to always build)\n" printf "${YELLOW}WARNING${RESET}: This will ${RED}overwrite${RESET} existing docker files [y/N] " - read -n 1 -r + read -n 1 -r REPLY echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then bash $ENTRYPOINT build --force diff --git a/commands/modules.sh b/commands/modules.sh index 411143f..6586fd9 100755 --- a/commands/modules.sh +++ b/commands/modules.sh @@ -275,7 +275,7 @@ if ! $MODE_QUIET && ! $MODE_NO_BUILD && $needs_rebuild; then if ! $MODE_FORCE; then printf "Do you want to rebuild the project? (run with ${FLG_COL}--force${RESET} to always build)\n" printf "${YELLOW}WARNING${RESET}: This will ${RED}overwrite${RESET} existing docker files [y/N] " - read -n 1 -r + read -n 1 -r REPLY echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then bash $ENTRYPOINT up --force ${UP_ARGS[@]} diff --git a/commands/upgrade.sh b/commands/upgrade.sh index 3e60835..83cb0bb 100755 --- a/commands/upgrade.sh +++ b/commands/upgrade.sh @@ -59,7 +59,7 @@ if ! $MODE_NO_BUILD; then if ! $MODE_FORCE; then printf "Do you want to rebuild the project? (run with ${FLG_COL}--force${RESET} to always build)\n" printf "${YELLOW}WARNING${RESET}: This will ${RED}overwrite${RESET} existing docker files [y/N] " - read -n 1 -r + read -n 1 -r REPLY echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then bash $ENTRYPOINT build --force diff --git a/install.sh b/install.sh index 04ee758..e9a3fc6 100755 --- a/install.sh +++ b/install.sh @@ -33,7 +33,7 @@ if [[ -z "$(which docker)" ]]; then printf "${HIGHLIGHT}https://www.docker.com/products/docker-desktop${RESET}\n" printf "\n" printf "Do you want to continue installing? [y/N] " - read -n 1 -r + read -n 1 -r REPLY echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1 @@ -43,16 +43,7 @@ if [[ -z "$(which docker)" ]]; then printf "${HIGHLIGHT}https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script${RESET}\n" printf "\n" printf "Do you want to automatically install 'docker'? [Y/n] " - read -n 1 -r - echo "" - if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then - echo "Trying to install 'docker'..." - curl -fsSL https://get.docker.com | sh - if [[ $? > 0 ]]; then - echo "Unable to install 'docker', skipping..." - fi - fi - fi + read -n 1 -r REPLY echo "" fi @@ -67,7 +58,7 @@ if [[ -z "$(which docker-compose)" ]]; then printf "${HIGHLIGHT}https://docs.docker.com/compose/install/#install-compose-on-linux-systems${RESET}\n" printf "\n" printf "Do you want to automatically install 'docker-compose'? [Y/n] " - read -n 1 -r + read -n 1 -r REPLY echo "" if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then echo "Trying to install 'docker-compose'..." @@ -90,7 +81,7 @@ if [[ -z "$(which yq)" ]]; then printf "For the best experience it is recommended to install a standalone version of 'yq'\n" printf "\n" printf "Do you want to attempt to automatically install 'yq'? [Y/n] " - read -n 1 -r + read -n 1 -r REPLY echo "" if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then echo "Trying to install using webi..." From f102af37556059fb2caed8e90be8442644b4c0e4 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 22:34:33 +0300 Subject: [PATCH 29/58] Update install.sh Add can_install_docker check --- install.sh | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index e9a3fc6..0273ae0 100755 --- a/install.sh +++ b/install.sh @@ -20,6 +20,14 @@ if grep -qEi "(Microsoft|WSL)" /proc/version &>/dev/null; then is_wsl=true fi +can_install_docker=false + +is_ubuntu=false +if lsb_release -si | grep -qEi "Ubuntu"; then + is_ubuntu=true + can_install_docker=true +fi + # # docker installer # @@ -39,11 +47,22 @@ if [[ -z "$(which docker)" ]]; then exit 1 fi else - printf "We can attempt to automatically install 'docker' using convinience script:\n" - printf "${HIGHLIGHT}https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script${RESET}\n" - printf "\n" - printf "Do you want to automatically install 'docker'? [Y/n] " - read -n 1 -r REPLY + if can_install_docker; then + printf "We can attempt to automatically install 'docker' using convinience script:\n" + printf "${HIGHLIGHT}https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script${RESET}\n" + printf "\n" + printf "Do you want to automatically install 'docker'? [Y/n] " + read -n 1 -r REPLY + echo "" + if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Trying to install 'docker'..." + curl -fsSL https://get.docker.com | sh + if [[ $? > 0 ]]; then + echo "Unable to install 'docker', skipping..." + fi + fi + fi + fi echo "" fi From f164331e3b21139c4eddc4c328e25b74432f2caa Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 22:35:07 +0300 Subject: [PATCH 30/58] Make docker rootless on Ubuntu --- install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/install.sh b/install.sh index 0273ae0..1511cb1 100755 --- a/install.sh +++ b/install.sh @@ -60,6 +60,10 @@ if [[ -z "$(which docker)" ]]; then if [[ $? > 0 ]]; then echo "Unable to install 'docker', skipping..." fi + + if is_ubuntu; then + curl -fsSL https://get.docker.com/rootless | sh + fi fi fi fi From 11751892add96110a05558df725e5f85cc620a59 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 22:36:16 +0300 Subject: [PATCH 31/58] Fix installer checks --- install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 1511cb1..988dd0b 100755 --- a/install.sh +++ b/install.sh @@ -47,7 +47,7 @@ if [[ -z "$(which docker)" ]]; then exit 1 fi else - if can_install_docker; then + if $can_install_docker; then printf "We can attempt to automatically install 'docker' using convinience script:\n" printf "${HIGHLIGHT}https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script${RESET}\n" printf "\n" @@ -61,7 +61,7 @@ if [[ -z "$(which docker)" ]]; then echo "Unable to install 'docker', skipping..." fi - if is_ubuntu; then + if $is_ubuntu; then curl -fsSL https://get.docker.com/rootless | sh fi fi From 96d4def98c21c72cd7369c7fb4c625bcf9b1693b Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 22:43:51 +0300 Subject: [PATCH 32/58] Update install.sh Install uidmap Source: https://docs.docker.com/engine/security/rootless/#prerequisites --- install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install.sh b/install.sh index 988dd0b..ba1005f 100755 --- a/install.sh +++ b/install.sh @@ -62,6 +62,7 @@ if [[ -z "$(which docker)" ]]; then fi if $is_ubuntu; then + sudo apt-get install -y uidmap curl -fsSL https://get.docker.com/rootless | sh fi fi From c68cfe66056837739a3c5887db626fa2c6bd3c24 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 23:02:30 +0300 Subject: [PATCH 33/58] Update install.sh Prevent crash on missing lsb_release --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index ba1005f..a83dde7 100755 --- a/install.sh +++ b/install.sh @@ -23,7 +23,7 @@ fi can_install_docker=false is_ubuntu=false -if lsb_release -si | grep -qEi "Ubuntu"; then +if lsb_release -si &>/dev/null | grep -qEi "Ubuntu"; then is_ubuntu=true can_install_docker=true fi From ebdae540a9660465074bca41f69c79382cb6961f Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 23:08:04 +0300 Subject: [PATCH 34/58] Update install.sh Don't attempt to install docker --- install.sh | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/install.sh b/install.sh index a83dde7..4e8bed5 100755 --- a/install.sh +++ b/install.sh @@ -47,26 +47,7 @@ if [[ -z "$(which docker)" ]]; then exit 1 fi else - if $can_install_docker; then - printf "We can attempt to automatically install 'docker' using convinience script:\n" - printf "${HIGHLIGHT}https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script${RESET}\n" - printf "\n" - printf "Do you want to automatically install 'docker'? [Y/n] " - read -n 1 -r REPLY - echo "" - if [[ -z "$REPLY" ]] || [[ $REPLY =~ ^[Yy]$ ]]; then - echo "Trying to install 'docker'..." - curl -fsSL https://get.docker.com | sh - if [[ $? > 0 ]]; then - echo "Unable to install 'docker', skipping..." - fi - - if $is_ubuntu; then - sudo apt-get install -y uidmap - curl -fsSL https://get.docker.com/rootless | sh - fi - fi - fi + echo "Error: 'docker' is not installed. Please install 'docker' first." fi echo "" fi From 43c144b99f705ac6e5209d9eeac0883b86e79641 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 23:10:13 +0300 Subject: [PATCH 35/58] Update install.sh Update docker install notice --- install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 4e8bed5..878073b 100755 --- a/install.sh +++ b/install.sh @@ -47,7 +47,9 @@ if [[ -z "$(which docker)" ]]; then exit 1 fi else - echo "Error: 'docker' is not installed. Please install 'docker' first." + printf "You can install docker using convinience script:\n" + printf "${HIGHLIGHT}https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script${RESET}\n" + exit 1 fi echo "" fi From 839047b620a159015eb70af959cf49d4ad8ebd09 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 20 Apr 2021 23:13:01 +0300 Subject: [PATCH 36/58] Update install.sh --- install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 878073b..e954dc6 100755 --- a/install.sh +++ b/install.sh @@ -32,7 +32,7 @@ fi # docker installer # -if [[ -z "$(which docker)" ]]; then +if ! which docker &>/dev/null; then printf "You do not appear to have 'docker' installed (${HIGHLIGHT}https://docker.com${RESET})\n" if $is_wsl; then @@ -58,7 +58,7 @@ fi # docker-compose installer # -if [[ -z "$(which docker-compose)" ]]; then +if ! which docker-compose &>/dev/null; then printf "You do not appear to have 'docker-compose' installed (${HIGHLIGHT}https://docs.docker.com/compose/install${RESET})\n" printf "We can attempt to automatically install 'docker-compose' using curl:\n" @@ -83,7 +83,7 @@ fi # yq installer # -if [[ -z "$(which yq)" ]]; then +if ! which yq &>/dev/null; then printf "You do not appear to have 'yq' installed (${HIGHLIGHT}https://github.com/mikefarah/yq${RESET})\n" printf "For the best experience it is recommended to install a standalone version of 'yq'\n" printf "\n" From 97e746d4dbad8c30470af21922f3d17e93f9bac2 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Wed, 21 Apr 2021 18:59:27 +0300 Subject: [PATCH 37/58] Update project rebuilding Use up command instead of build to refresh containers after building --- commands/environment.sh | 4 ++-- commands/lock.sh | 4 ++-- commands/upgrade.sh | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/commands/environment.sh b/commands/environment.sh index e7d7381..34959f6 100755 --- a/commands/environment.sh +++ b/commands/environment.sh @@ -67,9 +67,9 @@ if ! $MODE_QUIET; then read -n 1 -r REPLY if [[ $REPLY =~ ^[Yy]$ ]]; then echo "" - bash $ENTRYPOINT build --force + bash $ENTRYPOINT up --force fi else - bash $ENTRYPOINT build --force + bash $ENTRYPOINT up --force fi fi diff --git a/commands/lock.sh b/commands/lock.sh index bae2ae3..2b6f108 100755 --- a/commands/lock.sh +++ b/commands/lock.sh @@ -63,9 +63,9 @@ if ! $MODE_NO_BUILD; then read -n 1 -r REPLY echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then - bash $ENTRYPOINT build --force + bash $ENTRYPOINT up --force fi else - bash $ENTRYPOINT build --force + bash $ENTRYPOINT up --force fi fi diff --git a/commands/upgrade.sh b/commands/upgrade.sh index 83cb0bb..f6a1e5f 100755 --- a/commands/upgrade.sh +++ b/commands/upgrade.sh @@ -62,9 +62,9 @@ if ! $MODE_NO_BUILD; then read -n 1 -r REPLY echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then - bash $ENTRYPOINT build --force + bash $ENTRYPOINT up --force fi else - bash $ENTRYPOINT build --force + bash $ENTRYPOINT up --force fi fi From f4f92d17d698b978aec6c6ae2e6dbdd7ef09347b Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Wed, 21 Apr 2021 20:12:34 +0300 Subject: [PATCH 38/58] Update get-script-vars.sh Fix build args - remove BLUEPRINT_ prefix --- includes/get-script-vars.sh | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/includes/get-script-vars.sh b/includes/get-script-vars.sh index 949fc49..e7d0f96 100644 --- a/includes/get-script-vars.sh +++ b/includes/get-script-vars.sh @@ -17,10 +17,14 @@ yq_read_keys BUILD_ARGS_KEYS "build_args" "$BLUEPRINT_PATH" ! $SILENT && non_debug_print "." SCRIPT_VARS=() +SCRIPT_VARS_ENV=() +SCRIPT_VARS_BUILD_ARGS=() add_variable() { debug_print "Added variable $1='$2'" SCRIPT_VARS+=("BLUEPRINT_$1=$2") + SCRIPT_VARS_ENV+=("-e BLUEPRINT_$1='$2'") + SCRIPT_VARS_BUILD_ARGS+=("--build-arg $1='$2'") } add_variable "BLUEPRINT_DIR" "${BLUEPRINT_DIR#"$PWD/"}" @@ -83,23 +87,5 @@ done ! $SILENT && non_debug_print " ${GREEN}done${RESET}\n" export SCRIPT_VARS - -SCRIPT_VARS_BUILD_ARGS=() - -for var in "${SCRIPT_VARS[@]}"; do - name="$(echo "$var" | cut -d'=' -f1)" - value="$(echo "$var" | cut -d'=' -f2)" - SCRIPT_VARS_BUILD_ARGS+=("--build-arg $name='$value'") -done - -export SCRIPT_VARS_BUILD_ARGS - -SCRIPT_VARS_ENV=() - -for var in "${SCRIPT_VARS[@]}"; do - name="$(echo "$var" | cut -d'=' -f1)" - value="$(echo "$var" | cut -d'=' -f2)" - SCRIPT_VARS_ENV+=("-e $name='$value'") -done - export SCRIPT_VARS_ENV +export SCRIPT_VARS_BUILD_ARGS From eff8165e45921ba9e344db14d578770f027dc5b1 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Wed, 21 Apr 2021 22:05:45 +0300 Subject: [PATCH 39/58] Update install.sh Add package installer notice for requirements --- install.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index e954dc6..bd2cd92 100755 --- a/install.sh +++ b/install.sh @@ -7,13 +7,6 @@ REQUIREMENTS=( git ) -for PROGRAM in "${REQUIREMENTS[@]}"; do - if [[ -z "$(which $PROGRAM)" ]]; then - echo "Error: '$PROGRAM' is not installed. Please install '$PROGRAM' first." - exit 1 - fi -done - is_wsl=false if grep -qEi "(Microsoft|WSL)" /proc/version &>/dev/null; then @@ -28,6 +21,16 @@ if lsb_release -si &>/dev/null | grep -qEi "Ubuntu"; then can_install_docker=true fi +for PROGRAM in "${REQUIREMENTS[@]}"; do + if [[ -z "$(which $PROGRAM)" ]]; then + echo "Error: '$PROGRAM' is not installed. Please install '$PROGRAM' first." + if which apt-get &>/dev/null; then + echo "You can try install it by running 'sudo apt-get install $PROGRAM'" + fi + exit 1 + fi +done + # # docker installer # From 9391fc26516e4677d35d61f2f8c0b9876323e12f Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 22 Apr 2021 02:32:29 +0300 Subject: [PATCH 40/58] Update pull command Exit on empty blueprint --- commands/pull.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/commands/pull.sh b/commands/pull.sh index 6899a8a..1752ae8 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -49,14 +49,8 @@ while [[ "$#" -gt 0 ]]; do MODE_GET_QUALIFIED=true ;; *) - if [[ -z "$1" ]]; then - printf "Usage: " - bash $ENTRYPOINT pull --help - exit 1 - fi - if [[ -z $BLUEPRINT ]]; then - BLUEPRINT=$1 + BLUEPRINT="$1" fi ;; esac @@ -64,6 +58,11 @@ while [[ "$#" -gt 0 ]]; do shift done +if [[ -z $BLUEPRINT ]]; then + bash $ENTRYPOINT pull --help + exit 1 +fi + # # Parse blueprint name and branch # From f59cd8c4e20a98a0d0ae11836f3b9a5387294d89 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 22 Apr 2021 03:32:52 +0300 Subject: [PATCH 41/58] Update upgrade.sh Fix checkpoint not using remote Point checkpoint to the remote ref instead of local --- commands/upgrade.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commands/upgrade.sh b/commands/upgrade.sh index f6a1e5f..6ae6675 100755 --- a/commands/upgrade.sh +++ b/commands/upgrade.sh @@ -36,7 +36,9 @@ source "$ROOT_DIR/includes/blueprint/populate_env.sh" "" cd "$BLUEPRINT_DIR" -CHECKPOINT="$(git rev-parse HEAD)" +target_branch="$(echo "$BLUEPRINT_QUALIFIED_NAME" | cut -d: -f2)" + +CHECKPOINT="$(git rev-parse origin/$target_branch)" if [[ $? -eq 0 ]]; then if [[ "$CHECKPOINT" != "$PREVIOUS_VERSION" ]]; then printf "Latest version: ${CYAN}$CHECKPOINT${RESET}\n" From ac728dab7f1dd8b5f7a5d8355d5c2d3f2a5d8e5a Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 22 Apr 2021 03:36:21 +0300 Subject: [PATCH 42/58] Update upgrade.sh Update version only when agreed to build --- commands/upgrade.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/upgrade.sh b/commands/upgrade.sh index 6ae6675..bc08722 100755 --- a/commands/upgrade.sh +++ b/commands/upgrade.sh @@ -41,7 +41,7 @@ target_branch="$(echo "$BLUEPRINT_QUALIFIED_NAME" | cut -d: -f2)" CHECKPOINT="$(git rev-parse origin/$target_branch)" if [[ $? -eq 0 ]]; then if [[ "$CHECKPOINT" != "$PREVIOUS_VERSION" ]]; then - printf "Latest version: ${CYAN}$CHECKPOINT${RESET}\n" + printf "New version available: ${CYAN}$CHECKPOINT${RESET}\n" else printf "Already using latest version\n" exit @@ -53,9 +53,7 @@ fi cd "$PROJECT_DIR" -debug_print "Writing current version: $CHECKPOINT" - -yq_write_value "version" "$CHECKPOINT" +debug_print "New version: $CHECKPOINT" if ! $MODE_NO_BUILD; then if ! $MODE_FORCE; then @@ -64,9 +62,11 @@ if ! $MODE_NO_BUILD; then read -n 1 -r REPLY echo "" if [[ $REPLY =~ ^[Yy]$ ]]; then + yq_write_value "version" "$CHECKPOINT" bash $ENTRYPOINT up --force fi else + yq_write_value "version" "$CHECKPOINT" bash $ENTRYPOINT up --force fi fi From 0d2ee51b05773a5650cdea327f9f337f8e1a5602 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Tue, 27 Apr 2021 22:17:52 +0300 Subject: [PATCH 43/58] Fix sync command Only take docker-compose files for current project context --- commands/sync.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/commands/sync.sh b/commands/sync.sh index b3304be..89d4e25 100755 --- a/commands/sync.sh +++ b/commands/sync.sh @@ -68,8 +68,19 @@ if [[ -f .env ]]; then debug_print "Found .env file in the project directory" debug_print "Looking for docker-compose files..." + files=( + docker-compose.$PROJECT_CONTEXT.y*ml + docker-compose.y*ml + ) + temp_file="$TEMP_DIR/docker-compose.env" - for file in docker-compose*; do + touch "$temp_file" + + for file in ${files[@]}; do + if [[ ! -f "$file" ]]; then + continue + fi + debug_print "Found file: $file" if [[ ! -f "$temp_file" ]]; then From 756c5ad6693cb7056cde325243200fa85c814214 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 29 Apr 2021 19:30:12 +0300 Subject: [PATCH 44/58] Update pull.sh Set debug context --- commands/pull.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/pull.sh b/commands/pull.sh index 1752ae8..ff6e91a 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -17,6 +17,8 @@ # Function mode allows to use this command in conjunction # with others (i.e. create). +debug_switch_context "PULL" + # # Read arguments # From 173cc7a9e179aac50c5fc19cb7d46c983aec6a63 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 29 Apr 2021 19:35:42 +0300 Subject: [PATCH 45/58] Update pull.sh Try to resolve blueprint from docker-blueprint.yml --- commands/pull.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/commands/pull.sh b/commands/pull.sh index ff6e91a..4918cd1 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -60,9 +60,23 @@ while [[ "$#" -gt 0 ]]; do shift done -if [[ -z $BLUEPRINT ]]; then - bash $ENTRYPOINT pull --help - exit 1 +if [[ -z "$BLUEPRINT" ]]; then + debug_print "No blueprint name provided - trying to resolve from $PROJECT_BLUEPRINT_FILE..." + + # Try to read blueprint name from docker-blueprint.yml + if [[ -f "$PROJECT_BLUEPRINT_FILE" ]]; then + yq_read_value BLUEPRINT 'from' + if [[ -z "$BLUEPRINT" ]]; then + printf "${RED}ERROR${RESET}: Unable to resolve blueprint from project blueprint file.\n\n" + bash $ENTRYPOINT pull --help + exit 1 + else + debug_print "Found blueprint '$BLUEPRINT' in project blueprint file" + fi + else + bash $ENTRYPOINT pull --help + exit 1 + fi fi # From d5d656de1306442c747c9d29c280eb4af5867f73 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 29 Apr 2021 19:38:55 +0300 Subject: [PATCH 46/58] Update pull.sh Update help text --- commands/pull.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/pull.sh b/commands/pull.sh index 4918cd1..6f314ed 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -32,8 +32,8 @@ MODE_GET_QUALIFIED=false while [[ "$#" -gt 0 ]]; do case $1 in -h | --help) - printf "${CMD_COL}pull${RESET} ${ARG_COL}${RESET} [${FLG_COL}options${RESET}]" - printf "\tDownload the latest version of blueprint\n" + printf "${CMD_COL}pull${RESET} [${ARG_COL}${RESET}] [${FLG_COL}options${RESET}]" + printf "\tDownload the latest version of a blueprint\n" printf " ${FLG_COL}--clean${RESET}" printf "\t\t\tRemove already existing copy of a blueprint and install fresh download\n" From 19c9f35c19c231ed86802b971f8a110c7d007a47 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 29 Apr 2021 19:52:13 +0300 Subject: [PATCH 47/58] Update pull.sh Silence output when ran as function --- commands/pull.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/pull.sh b/commands/pull.sh index 6f314ed..8d85343 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -61,17 +61,17 @@ while [[ "$#" -gt 0 ]]; do done if [[ -z "$BLUEPRINT" ]]; then - debug_print "No blueprint name provided - trying to resolve from $PROJECT_BLUEPRINT_FILE..." + ! $AS_FUNCTION && debug_print "No blueprint name provided - trying to resolve from $PROJECT_BLUEPRINT_FILE..." # Try to read blueprint name from docker-blueprint.yml if [[ -f "$PROJECT_BLUEPRINT_FILE" ]]; then yq_read_value BLUEPRINT 'from' if [[ -z "$BLUEPRINT" ]]; then - printf "${RED}ERROR${RESET}: Unable to resolve blueprint from project blueprint file.\n\n" + ! $AS_FUNCTION && printf "${RED}ERROR${RESET}: Unable to resolve blueprint from project blueprint file.\n\n" bash $ENTRYPOINT pull --help exit 1 else - debug_print "Found blueprint '$BLUEPRINT' in project blueprint file" + ! $AS_FUNCTION && debug_print "Found blueprint '$BLUEPRINT' in project blueprint file" fi else bash $ENTRYPOINT pull --help From 8fb67605ccb28304393ad4a1061b692068a044d4 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 29 Apr 2021 19:53:20 +0300 Subject: [PATCH 48/58] Update pull.sh Checkout locked version if present --- commands/pull.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/commands/pull.sh b/commands/pull.sh index 8d85343..3d5f15d 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -237,6 +237,17 @@ if ! $MODE_DRY_RUN; then fi fi + yq_read_value CHECKPOINT 'version' + + # Set the blueprint repository to the version specified. + # This allows to always safely reproduce previous versions of the blueprint. + if [[ -n "$CHECKPOINT" ]]; then + ! $AS_FUNCTION && printf "${BLUE}INFO${RESET}: Version lock applied: ${CYAN}$CHECKPOINT${RESET}\n" + git checkout $CHECKPOINT 2>/dev/null + else + ! $AS_FUNCTION && printf "${BLUE}INFO${RESET}: No version lock found - using latest version.\n" + fi + cd $PREVIOUS_DIR fi From 668c3e4353e564f09e1b962fe9ae35bd59f0bb7b Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 29 Apr 2021 19:54:10 +0300 Subject: [PATCH 49/58] Update pull.sh Actually pull respository instead of just fetching it --- commands/pull.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/pull.sh b/commands/pull.sh index 3d5f15d..98903f5 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -189,7 +189,7 @@ else else PREVIOUS_DIR="$PWD" cd "$BLUEPRINT_DIR" - git fetch >/dev/null + git pull >/dev/null cd "$PREVIOUS_DIR" fi fi From 54523fadc2bd93a357ab3ea8b61724ee19a5d196 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 29 Apr 2021 19:54:58 +0300 Subject: [PATCH 50/58] Update yq.sh Use absolute file path by default --- includes/yq.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/yq.sh b/includes/yq.sh index 21c29ef..d009814 100755 --- a/includes/yq.sh +++ b/includes/yq.sh @@ -40,7 +40,7 @@ yq_merge() { yq_read_value() { if [[ -z "$3" ]]; then - FILE="$PROJECT_BLUEPRINT_FILE" + FILE="$PROJECT_DIR/$PROJECT_BLUEPRINT_FILE" else FILE="$3" fi @@ -50,7 +50,7 @@ yq_read_value() { yq_write_value() { if [[ -z "$3" ]]; then - FILE="$PROJECT_BLUEPRINT_FILE" + FILE="$PROJECT_DIR/$PROJECT_BLUEPRINT_FILE" else FILE="$3" fi @@ -60,7 +60,7 @@ yq_write_value() { yq_read_array() { if [[ -z "$3" ]]; then - FILE="$PROJECT_BLUEPRINT_FILE" + FILE="$PROJECT_DIR/$PROJECT_BLUEPRINT_FILE" else FILE="$3" fi @@ -70,7 +70,7 @@ yq_read_array() { yq_read_keys() { if [[ -z "$3" ]]; then - FILE="$PROJECT_BLUEPRINT_FILE" + FILE="$PROJECT_DIR/$PROJECT_BLUEPRINT_FILE" else FILE="$3" fi From e5aeb7434decd938fc414289c4f042d128707a67 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 29 Apr 2021 20:09:31 +0300 Subject: [PATCH 51/58] Update pull.sh Always checkout before pulling --- commands/pull.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/pull.sh b/commands/pull.sh index 98903f5..0c9dbef 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -189,6 +189,7 @@ else else PREVIOUS_DIR="$PWD" cd "$BLUEPRINT_DIR" + git checkout master &>/dev/null git pull >/dev/null cd "$PREVIOUS_DIR" fi From daaf9eaf5192c6361ef37e9d97d10b7413e7d9e6 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Thu, 29 Apr 2021 20:09:31 +0300 Subject: [PATCH 52/58] Update pull.sh Always checkout before pulling --- commands/pull.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/pull.sh b/commands/pull.sh index 98903f5..0c9dbef 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -189,6 +189,7 @@ else else PREVIOUS_DIR="$PWD" cd "$BLUEPRINT_DIR" + git checkout master &>/dev/null git pull >/dev/null cd "$PREVIOUS_DIR" fi From 893c7b0bf8b3d41ffc43d6240a6498f806ae1780 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Mon, 10 May 2021 02:15:20 +0300 Subject: [PATCH 53/58] Update pull.sh Fix broken pull command output when checkpoint exists --- commands/pull.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/commands/pull.sh b/commands/pull.sh index 0c9dbef..88a0373 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -243,8 +243,12 @@ if ! $MODE_DRY_RUN; then # Set the blueprint repository to the version specified. # This allows to always safely reproduce previous versions of the blueprint. if [[ -n "$CHECKPOINT" ]]; then - ! $AS_FUNCTION && printf "${BLUE}INFO${RESET}: Version lock applied: ${CYAN}$CHECKPOINT${RESET}\n" - git checkout $CHECKPOINT 2>/dev/null + if ! $AS_FUNCTION; then + printf "${BLUE}INFO${RESET}: Version lock applied: ${CYAN}$CHECKPOINT${RESET}\n" + git checkout $CHECKPOINT 2>/dev/null + else + git checkout $CHECKPOINT &>/dev/null + fi else ! $AS_FUNCTION && printf "${BLUE}INFO${RESET}: No version lock found - using latest version.\n" fi From 2252f687384fb215c55b78db1f6926ff923c622a Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Mon, 10 May 2021 03:07:17 +0300 Subject: [PATCH 54/58] Update upgrade.sh Always update version in project blueprint file --- commands/upgrade.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/commands/upgrade.sh b/commands/upgrade.sh index bc08722..b1d278c 100755 --- a/commands/upgrade.sh +++ b/commands/upgrade.sh @@ -69,4 +69,9 @@ if ! $MODE_NO_BUILD; then yq_write_value "version" "$CHECKPOINT" bash $ENTRYPOINT up --force fi +else + yq_write_value "version" "$CHECKPOINT" + printf "Updated version to the latest without rebuilding\n" + printf "You can build manually later with 'docker-blueprint build --force'\n" + printf "\n" fi From e74668334549261d926e24617891ae80661e76e0 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Sun, 16 May 2021 05:37:39 +0300 Subject: [PATCH 55/58] Update up.sh Add --skip-user and --skip-env flags --- commands/up.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/commands/up.sh b/commands/up.sh index a124ab8..7039a35 100755 --- a/commands/up.sh +++ b/commands/up.sh @@ -31,9 +31,6 @@ while [[ "$#" -gt 0 ]]; do printf " ${FLG_COL}--no-sync${RESET}" printf "\t\t\tDon't attempt to sync service container with the local environment\n" - printf " ${FLG_COL}--no-chown${RESET}" - printf "\t\t\tPass --no-chown to 'sync' command\n" - printf " ${FLG_COL}--no-build${RESET}" printf "\t\t\tDon't attempt to build the blueprint\n" @@ -51,6 +48,15 @@ while [[ "$#" -gt 0 ]]; do printf "\t\t\t\tThis will force to regenerate new docker files\n" printf "\t\t\t\tpotentially overwriting current ones\n" + printf " ${FLG_COL}--no-chown${RESET}" + printf "\t\t\tPass --no-chown to 'sync' command\n" + + printf " ${FLG_COL}--skip-user${RESET}" + printf "\t\t\tPass --skip-user to 'sync' command\n" + + printf " ${FLG_COL}--skip-env${RESET}" + printf "\t\t\tPass --skip-env to 'sync' command\n" + exit ;; -f | --force) @@ -71,6 +77,12 @@ while [[ "$#" -gt 0 ]]; do --no-chown) SYNC_ARGS+=('--no-chown') ;; + --skip-user) + SYNC_ARGS+=('--skip-user') + ;; + --skip-env) + SYNC_ARGS+=('--skip-env') + ;; --no-sync) MODE_SYNC=false ;; From c9008fde7b500c9f39ef73e36955ca010b53a44c Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Sun, 16 May 2021 05:37:51 +0300 Subject: [PATCH 56/58] Update up.sh Update help text --- commands/up.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/commands/up.sh b/commands/up.sh index 7039a35..242b90c 100755 --- a/commands/up.sh +++ b/commands/up.sh @@ -57,6 +57,12 @@ while [[ "$#" -gt 0 ]]; do printf " ${FLG_COL}--skip-env${RESET}" printf "\t\t\tPass --skip-env to 'sync' command\n" + printf " ${FLG_COL}--skip-compose${RESET}" + printf "\t\tDon't generate docker-compose files\n" + + printf " ${FLG_COL}--skip-dockerfile${RESET}" + printf "\t\tDon't generate dockerfiles\n" + exit ;; -f | --force) From 9f625c8ef53994ae662c932fdfe9550bfbff912d Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Sun, 16 May 2021 05:38:43 +0300 Subject: [PATCH 57/58] Update pull.sh Prevent git pull output Print error when there are local changes --- commands/pull.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/commands/pull.sh b/commands/pull.sh index 88a0373..e545a95 100755 --- a/commands/pull.sh +++ b/commands/pull.sh @@ -32,6 +32,7 @@ MODE_GET_QUALIFIED=false while [[ "$#" -gt 0 ]]; do case $1 in -h | --help) + if [[ "$WITH_USAGE" -eq 1 ]]; then printf "Usage:\n"; fi printf "${CMD_COL}pull${RESET} [${ARG_COL}${RESET}] [${FLG_COL}options${RESET}]" printf "\tDownload the latest version of a blueprint\n" @@ -68,7 +69,7 @@ if [[ -z "$BLUEPRINT" ]]; then yq_read_value BLUEPRINT 'from' if [[ -z "$BLUEPRINT" ]]; then ! $AS_FUNCTION && printf "${RED}ERROR${RESET}: Unable to resolve blueprint from project blueprint file.\n\n" - bash $ENTRYPOINT pull --help + WITH_USAGE=1 bash $ENTRYPOINT pull --help exit 1 else ! $AS_FUNCTION && debug_print "Found blueprint '$BLUEPRINT' in project blueprint file" @@ -190,7 +191,13 @@ else PREVIOUS_DIR="$PWD" cd "$BLUEPRINT_DIR" git checkout master &>/dev/null - git pull >/dev/null + git pull &>/dev/null + if [[ $? -gt 0 ]]; then + cd "$PREVIOUS_DIR" + printf "${RED}ERROR${RESET}: Blueprint directory has local changes\n" + printf "You can clear local changes with 'docker-blueprint pull --clean'\n" + exit 1 + fi cd "$PREVIOUS_DIR" fi fi From c539703104516db2d751a5389f3c9859440fd308 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Sun, 16 May 2021 05:39:03 +0300 Subject: [PATCH 58/58] Update sync.sh Add --skip-env option --- commands/sync.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/commands/sync.sh b/commands/sync.sh index 89d4e25..6bee836 100755 --- a/commands/sync.sh +++ b/commands/sync.sh @@ -12,6 +12,7 @@ shift MODE_NO_CHOWN=false MODE_SKIP_USER=false +MODE_SKIP_ENV=false while [[ "$#" -gt 0 ]]; do case $1 in @@ -28,11 +29,13 @@ while [[ "$#" -gt 0 ]]; do ;; --no-chown) MODE_NO_CHOWN=true - ;; --skip-user) MODE_SKIP_USER=true ;; + --skip-env) + MODE_SKIP_ENV=true + ;; esac shift @@ -64,7 +67,7 @@ if ! $MODE_SKIP_USER && [[ -n "$SYNC_USER" ]]; then fi fi -if [[ -f .env ]]; then +if ! $MODE_SKIP_ENV && [[ -f .env ]]; then debug_print "Found .env file in the project directory" debug_print "Looking for docker-compose files..."