diff --git a/.build_env.template b/.build_env.template new file mode 100644 index 0000000..3739fbe --- /dev/null +++ b/.build_env.template @@ -0,0 +1,14 @@ +# shellcheck disable=SC2034,SC2148 +# ### +# Do not use quotes for these variables! +# +# These variables will be loaded during the building process +# This can be useful if you need to provide special variables for NodeJS or other applications +# Make sure you export variables which are used for external scripts, else they will not be seen! +# ### + +# Configure NodeJS Virtual Memory Allocation +# NODE_OPTIONS=--max-old-space-size=4096 +# export NODE_OPTIONS + +# vim: syntax=sh filetype=sh diff --git a/.env.template b/.env.template index e0b41cc..981520a 100644 --- a/.env.template +++ b/.env.template @@ -12,4 +12,4 @@ # GPG_SIGNING_USER=user@domain.tld # GPG_SIGNING_USER=MY_LONG_UNIQUE_GPG_KEY_IDENTIFIER -# vim: syntax=ini +# vim: syntax=sh filetype=sh diff --git a/.gitignore b/.gitignore index 39aac1d..c015c05 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ web-vault/ # Other .env +.build_env .vscode # Release files diff --git a/Dockerfile b/Dockerfile index c14b107..4427ed9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,8 @@ WORKDIR /bw_web_builds COPY patches ./patches COPY resources ./resources COPY scripts ./scripts +# Use a glob pattern here so builds will continue even if the `.build_env` does not exists +COPY .build_env* ./ RUN ./scripts/checkout_web_vault.sh RUN ./scripts/patch_web_vault.sh diff --git a/scripts/.script_env b/scripts/.script_env index e9b9628..5d91e94 100644 --- a/scripts/.script_env +++ b/scripts/.script_env @@ -1,6 +1,7 @@ #!/usr/bin/env bash # shellcheck disable=SC2034 set -o pipefail -o errexit +ENV_BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")"; pwd)/$(basename "${SP}")") VAULT_FOLDER=${VAULT_FOLDER:=web-vault} CHECKOUT_TAGS=${CHECKOUT_TAGS:=true} @@ -17,3 +18,11 @@ function get_web_vault_version { # The extracted tag could start with either `web-`, `desktop-`, `cli-` or `browser-` echo "${VAULT_VERSION#*-}" } + +# Load build environment variables if it exists +if [ -f "${ENV_BASEDIR}/../.build_env" ]; then + # shellcheck source=../.build_env + . "${ENV_BASEDIR}/../.build_env" +fi + +unset ENV_BASEDIR diff --git a/scripts/apply_patches.sh b/scripts/apply_patches.sh index 1ee001a..9eb22c1 100755 --- a/scripts/apply_patches.sh +++ b/scripts/apply_patches.sh @@ -2,15 +2,15 @@ set -o pipefail -o errexit function replace_embedded_svg_icon() { -if [ ! -f $1 ]; then echo "$1 does not exist"; exit -1; fi -if [ ! -f $2 ]; then echo "$2 does not exist"; exit -1; fi +if [ ! -f "$1" ]; then echo "$1 does not exist"; exit 255; fi +if [ ! -f "$2" ]; then echo "$2 does not exist"; exit 255; fi echo "'$1' -> '$2'" first='`$' last='^`' sed -i "/$first/,/$last/{ /$first/{p; r $1 -}; /$last/p; d }" $2 +}; /$last/p; d }" "$2" } # If a patch was not provided, try to choose one @@ -28,7 +28,7 @@ if [[ -z ${PATCH_NAME} ]]; then else echo "No exact patch file not found, using latest" # If not, use the latest one - PATCH_NAME="$(find ../patches/ -type f -print0 | xargs -0 basename -a | sort -V | tail -n1)" + PATCH_NAME="$(find ../patches/ -type f -name '*.patch' -print0 | xargs -0 basename -a | sort -V | tail -n1)" fi fi diff --git a/scripts/package_web_vault.sh b/scripts/package_web_vault.sh index aefeb1c..1a1f3c6 100755 --- a/scripts/package_web_vault.sh +++ b/scripts/package_web_vault.sh @@ -2,6 +2,7 @@ set -o pipefail -o errexit BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")"; pwd)/$(basename "${SP}")") +# Error handling handle_error() { read -n1 -r -p "FAILED: line $1, exit code $2. Press any key to exit..." _ exit 1