add build script for web container image

This commit is contained in:
Joseph Flinn 2023-09-28 08:40:20 -07:00
parent d0037bb257
commit 214d7b355a
No known key found for this signature in database
GPG Key ID: B7E429D4A0FBD2A0
1 changed files with 43 additions and 0 deletions

43
scripts/build-web Executable file
View File

@ -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 .