From 214d7b355a5b5709d79ad3f84927eaa30672f3fd Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Thu, 28 Sep 2023 08:40:20 -0700 Subject: [PATCH] add build script for web container image --- scripts/build-web | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 scripts/build-web diff --git a/scripts/build-web b/scripts/build-web new file mode 100755 index 0000000000..38388d4452 --- /dev/null +++ b/scripts/build-web @@ -0,0 +1,43 @@ +validateBuildEnv() { + local tool=$1 + local versionCommand=$2 + + $tool $versionCommand > /dev/null 2>&1 + if [[ $? -eq 1 ]]; then + echo "[!] script requires: $tool" + fi +} + +err() { + local msg=$1 + echo "[!] $1" + exit 1 +} + +IMAGE_BUILDER=nerdctl + +NODE_VERSION=$(validateBuildEnv node --version) +JQ_VERSION=$(validateBuildEnv jq --version) +DOCKER_VERSION=$(validateBuildEnv $IMAGE_BUILDER --version) + +if [[ "$(basename $PWD)" != "clients" ]]; then + err "script needs to be executed from the root directory of the project\n ./scripts/build-web" +fi + +REQUIRED_NODE_VERSION=$(cat .nvmrc) + +if [[ "$(node --version | grep $REQUIRED_NODE_VERSION | wc -l | xargs)" == "0" ]]; then + err "web requires node $REQUIRED_NODE_VERSION" +fi + +echo "[*] Build environment validated" + + +# Build web app +npm ci +cd apps/web +npm run dist:bit:selfhost + + +# Build container image +$IMAGE_BUILDER build -t bitwarden/web:latest .