87 lines
2.3 KiB
Bash
Executable file
87 lines
2.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# shellcheck source=scripts/_compose.sh
|
|
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)/_compose.sh"
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Usage: ./scripts/build.sh [options] [-- <extra docker compose build args>]
|
|
|
|
Build the GCoordinator Docker image using BuildKit and compose configuration.
|
|
|
|
Options:
|
|
--lan Use LAN compose override (default unless GCOORD_DEPLOY_MODE=cloudflare)
|
|
--cloudflare Use Cloudflare Tunnel compose configuration
|
|
--mode <lan|cloudflare> Explicitly select deployment mode
|
|
--no-cache Pass --no-cache to docker compose build
|
|
--pull Pass --pull to docker compose build
|
|
--typecheck Run `tsc --noEmit` inside Docker builder (uses more RAM)
|
|
--dry-run Print the compose command without executing it
|
|
-h, --help Show this help message
|
|
EOF
|
|
}
|
|
|
|
REQ_MODE=""
|
|
BUILD_FLAGS=()
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--lan)
|
|
REQ_MODE="lan"
|
|
shift
|
|
;;
|
|
--cloudflare)
|
|
REQ_MODE="cloudflare"
|
|
shift
|
|
;;
|
|
--mode)
|
|
[[ $# -ge 2 ]] || die "--mode requires an argument."
|
|
REQ_MODE="$2"
|
|
shift 2
|
|
;;
|
|
--mode=*)
|
|
REQ_MODE="${1#*=}"
|
|
shift
|
|
;;
|
|
--no-cache|--pull)
|
|
BUILD_FLAGS+=("$1")
|
|
shift
|
|
;;
|
|
--typecheck)
|
|
BUILD_FLAGS+=(--build-arg RUN_TYPECHECK=true)
|
|
shift
|
|
;;
|
|
--dry-run)
|
|
DRY_RUN=1
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
--)
|
|
shift
|
|
BUILD_FLAGS+=("$@")
|
|
break
|
|
;;
|
|
*)
|
|
die "Unknown option: $1 (pass extra compose build flags after '--', or run --help)"
|
|
;;
|
|
esac
|
|
done
|
|
|
|
MODE="$(resolve_mode "$REQ_MODE")"
|
|
|
|
if [[ -r /proc/meminfo ]]; then
|
|
mem_kb="$(awk '/^MemTotal:/ {print $2}' /proc/meminfo 2>/dev/null || echo 0)"
|
|
swap_kb="$(awk '/^SwapTotal:/ {print $2}' /proc/meminfo 2>/dev/null || echo 0)"
|
|
if [[ "$mem_kb" =~ ^[0-9]+$ && "$swap_kb" =~ ^[0-9]+$ ]] && [[ "$mem_kb" -lt 1500000 && "$swap_kb" -lt 1000000 ]]; then
|
|
log_warn "Low RAM (~$((mem_kb / 1024)) MB) and low swap (~$((swap_kb / 1024)) MB) detected; Docker image compilation may need >= 1-2 GB swap."
|
|
fi
|
|
fi
|
|
|
|
log_info "Building GCoordinator image (mode=$MODE)..."
|
|
export DOCKER_BUILDKIT=1
|
|
export COMPOSE_DOCKER_CLI_BUILD=1
|
|
run_compose "$MODE" build "${BUILD_FLAGS[@]}" gcoordinator
|