| #!/usr/bin/env bash |
| set -euo pipefail |
|
|
| DBOPS_ROOT=${DBOPS_ROOT:-/data/adaptai/platform/dbops} |
| LOG_DIR="$DBOPS_ROOT/logs/weaviate" |
| mkdir -p "$LOG_DIR" "$DBOPS_ROOT/binaries/weaviate" "$DBOPS_ROOT/binaries/weaviate-src" |
|
|
| echo "[weaviate-build] starting" | tee -a "$LOG_DIR/build.log" |
|
|
| |
| GOROOT="$DBOPS_ROOT/binaries/go/go" |
| if [ ! -x "$GOROOT/bin/go" ]; then |
| echo "[weaviate-build] installing Go toolchain" | tee -a "$LOG_DIR/build.log" |
| mkdir -p "$DBOPS_ROOT/binaries/go" |
| curl -fsSL https://go.dev/dl/go1.22.5.linux-amd64.tar.gz -o "$LOG_DIR/go.tgz" |
| tar -C "$DBOPS_ROOT/binaries/go" -xzf "$LOG_DIR/go.tgz" |
| fi |
| export PATH="$GOROOT/bin:$PATH" |
|
|
| |
| SRC="$DBOPS_ROOT/binaries/weaviate-src" |
| if [ ! -d "$SRC/.git" ]; then |
| echo "[weaviate-build] cloning source" | tee -a "$LOG_DIR/build.log" |
| git clone --depth 1 https://github.com/weaviate/weaviate "$SRC" >> "$LOG_DIR/build.log" 2>&1 |
| else |
| echo "[weaviate-build] updating source" | tee -a "$LOG_DIR/build.log" |
| git -C "$SRC" pull --ff-only >> "$LOG_DIR/build.log" 2>&1 || true |
| fi |
|
|
| cd "$SRC" |
| echo "[weaviate-build] downloading modules" | tee -a "$LOG_DIR/build.log" |
| go mod download >> "$LOG_DIR/build.log" 2>&1 || true |
|
|
| OUT="$DBOPS_ROOT/binaries/weaviate/weaviate" |
| echo "[weaviate-build] building (static)" | tee -a "$LOG_DIR/build.log" |
| if CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "$OUT" ./cmd/weaviate >> "$LOG_DIR/build.log" 2>&1; then |
| echo "[weaviate-build] built static binary" | tee -a "$LOG_DIR/build.log" |
| else |
| echo "[weaviate-build] static build failed, retry with CGO" | tee -a "$LOG_DIR/build.log" |
| CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o "$OUT" ./cmd/weaviate >> "$LOG_DIR/build.log" 2>&1 |
| fi |
|
|
| chmod +x "$OUT" |
| echo "[weaviate-build] DONE -> $OUT" | tee -a "$LOG_DIR/build.log" |
| exit 0 |
|
|
|
|