mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 10:13:58 +00:00
87 lines
2.1 KiB
Bash
Executable File
87 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# etc/build_db.sh
|
|
# Purpose: Build knoe-db image, supporting multi-platform (amd64, arm64)
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
|
|
# shellcheck disable=SC1090
|
|
source "$SCRIPT_DIR/knoe_cfg.sh"
|
|
|
|
TAG="latest"
|
|
PUSH=false
|
|
PLATFORMS="linux/amd64,linux/arm64"
|
|
|
|
log() { echo "==> $*"; }
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--tag)
|
|
TAG="$2"
|
|
shift 2
|
|
;;
|
|
--push)
|
|
PUSH=true
|
|
shift
|
|
;;
|
|
--platform)
|
|
PLATFORMS="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Ensure we are in the right directory
|
|
cd "$PROJECT_ROOT/knoe-db"
|
|
|
|
if docker buildx version >/dev/null 2>&1; then
|
|
log "Building multi-platform image: knoe-db:$TAG for $PLATFORMS"
|
|
|
|
# Check if a builder exists that supports multi-platform
|
|
if ! docker buildx inspect knoe-builder >/dev/null 2>&1; then
|
|
log "Creating new buildx builder: knoe-builder"
|
|
docker buildx create --name knoe-builder --use || true
|
|
else
|
|
docker buildx use knoe-builder
|
|
fi
|
|
|
|
BUILD_ARGS=(--platform "$PLATFORMS")
|
|
if [[ "$TAG" == */* ]]; then
|
|
BUILD_ARGS+=(-t "$TAG")
|
|
else
|
|
BUILD_ARGS+=(-t "knoe-db:$TAG")
|
|
fi
|
|
|
|
if [[ "$PUSH" == "true" ]]; then
|
|
log "Pushing to registry..."
|
|
BUILD_ARGS+=(--push)
|
|
# Also tag as knoe-db:latest for local convenience if it's a remote tag
|
|
if [[ "$TAG" == */* ]]; then
|
|
BUILD_ARGS+=(-t "knoe-db:latest")
|
|
fi
|
|
else
|
|
# If not pushing, we build only for local platform to allow --load
|
|
LOCAL_PLATFORM=$(docker info --format '{{.OSType}}/{{.Architecture}}' 2>/dev/null || echo "linux/arm64")
|
|
log "Push disabled; building for local platform: $LOCAL_PLATFORM"
|
|
|
|
# Re-evaluate BUILD_ARGS for single platform + load
|
|
BUILD_ARGS=(--platform "$LOCAL_PLATFORM")
|
|
if [[ "$TAG" == */* ]]; then
|
|
BUILD_ARGS+=(-t "$TAG")
|
|
else
|
|
BUILD_ARGS+=(-t "knoe-db:$TAG")
|
|
fi
|
|
BUILD_ARGS+=(--load)
|
|
fi
|
|
|
|
docker buildx build --progress=plain "${BUILD_ARGS[@]}" .
|
|
else
|
|
log "docker buildx not found; building for local platform only"
|
|
docker build --progress=plain -t "knoe-db:$TAG" .
|
|
fi
|