Skip to content

Commit 7f1dfde

Browse files
committed
Add build env's
Sometimes you want to set specific environment variables during build. For example, on some systems nodejs needs some extra options to be able to run correctly on low memory systems. To make sure this will be loaded and works on both scripts and Dockerfile, you can now create a `.build_env` file. This `.build_env` file should contain all the variables (including an export command) you want to expose during build time. The template file has a nodejs example. Closes #183 Signed-off-by: BlackDex <[email protected]>
1 parent bfa7310 commit 7f1dfde

7 files changed

+32
-5
lines changed

.build_env.template

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# shellcheck disable=SC2034,SC2148
2+
# ###
3+
# Do not use quotes for these variables!
4+
#
5+
# These variables will be loaded during the building process
6+
# This can be useful if you need to provide special variables for NodeJS or other applications
7+
# Make sure you export variables which are used for external scripts, else they will not be seen!
8+
# ###
9+
10+
# Configure NodeJS Virtual Memory Allocation
11+
# NODE_OPTIONS=--max-old-space-size=4096
12+
# export NODE_OPTIONS
13+
14+
# vim: syntax=sh filetype=sh

.env.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
1313
# GPG_SIGNING_USER=MY_LONG_UNIQUE_GPG_KEY_IDENTIFIER
1414

15-
# vim: syntax=ini
15+
# vim: syntax=sh filetype=sh

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ web-vault/
66

77
# Other
88
.env
9+
.build_env
910
.vscode
1011

1112
# Release files

Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ WORKDIR /bw_web_builds
3535
COPY patches ./patches
3636
COPY resources ./resources
3737
COPY scripts ./scripts
38+
# Use a glob pattern here so builds will continue even if the `.build_env` does not exists
39+
COPY .build_env* ./
3840

3941
RUN ./scripts/checkout_web_vault.sh
4042
RUN ./scripts/patch_web_vault.sh

scripts/.script_env

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22
# shellcheck disable=SC2034
33
set -o pipefail -o errexit
4+
ENV_BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")"; pwd)/$(basename "${SP}")")
45

56
VAULT_FOLDER=${VAULT_FOLDER:=web-vault}
67
CHECKOUT_TAGS=${CHECKOUT_TAGS:=true}
@@ -17,3 +18,11 @@ function get_web_vault_version {
1718
# The extracted tag could start with either `web-`, `desktop-`, `cli-` or `browser-`
1819
echo "${VAULT_VERSION#*-}"
1920
}
21+
22+
# Load build environment variables if it exists
23+
if [ -f "${ENV_BASEDIR}/../.build_env" ]; then
24+
# shellcheck source=../.build_env
25+
. "${ENV_BASEDIR}/../.build_env"
26+
fi
27+
28+
unset ENV_BASEDIR

scripts/apply_patches.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
set -o pipefail -o errexit
33

44
function replace_embedded_svg_icon() {
5-
if [ ! -f $1 ]; then echo "$1 does not exist"; exit -1; fi
6-
if [ ! -f $2 ]; then echo "$2 does not exist"; exit -1; fi
5+
if [ ! -f "$1" ]; then echo "$1 does not exist"; exit 255; fi
6+
if [ ! -f "$2" ]; then echo "$2 does not exist"; exit 255; fi
77

88
echo "'$1' -> '$2'"
99

1010
first='`$'
1111
last='^`'
1212
sed -i "/$first/,/$last/{ /$first/{p; r $1
13-
}; /$last/p; d }" $2
13+
}; /$last/p; d }" "$2"
1414
}
1515

1616
# If a patch was not provided, try to choose one
@@ -28,7 +28,7 @@ if [[ -z ${PATCH_NAME} ]]; then
2828
else
2929
echo "No exact patch file not found, using latest"
3030
# If not, use the latest one
31-
PATCH_NAME="$(find ../patches/ -type f -print0 | xargs -0 basename -a | sort -V | tail -n1)"
31+
PATCH_NAME="$(find ../patches/ -type f -name '*.patch' -print0 | xargs -0 basename -a | sort -V | tail -n1)"
3232
fi
3333
fi
3434

scripts/package_web_vault.sh

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -o pipefail -o errexit
33
BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")"; pwd)/$(basename "${SP}")")
44

5+
# Error handling
56
handle_error() {
67
read -n1 -r -p "FAILED: line $1, exit code $2. Press any key to exit..." _
78
exit 1

0 commit comments

Comments
 (0)