#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" UBUNTU_VERSION="${UBUNTU_VERSION:-26.04}" OPENCODE_VERSION=$(curl -fsSI https://github.com/anomalyco/opencode/releases/latest | sed -n 's/^location:.*\/tag\/v\{0,1\}\(.*\)\r$/\1/ip') NODE_VERSION=$(curl -fsSL https://nodejs.org/dist/index.json | sed -n 's/.*"version":"v\([^"]*\)".*"lts":".*".*/\1/p' | head -n 1) IMAGE_REPO="${IMAGE_REPO:-localhost/opencode-dev}" IMAGE_TAG="${IMAGE_TAG:-${OPENCODE_VERSION}}" IMAGE="${IMAGE_REPO}:${IMAGE_TAG}" NO_CACHE=() if [[ "${1:-}" == "--no-cache" ]]; then NO_CACHE+=(--no-cache) shift fi UPDATE=0 if [[ "${1:-}" == "--update" ]]; then UPDATE=1 shift fi DRY_RUN=false if [[ "${1:-}" == "--dry-run" ]]; then DRY_RUN=true shift fi if (($#)); then echo "Usage: $0 [--no-cache] [--update] [--dry-run]" >&2 exit 2 fi if ((UPDATE)); then echo "Update requested: rebuilding ${IMAGE} with current Ubuntu package metadata." podman rmi ${IMAGE_REPO} fi if [ DRY_RUN = false ]; then podman build \ "${NO_CACHE[@]}" \ --build-arg "UBUNTU_VERSION=${UBUNTU_VERSION}" \ --build-arg "OPENCODE_VERSION=${OPENCODE_VERSION}" \ --build-arg "NODE_VERSION=${NODE_VERSION}" \ -t "$IMAGE" \ . echo echo "Built: $IMAGE" else echo "running: podman build ${NO_CACHE[@]} --build-arg UBUNTU_VERSION=${UBUNTU_VERSION} --build-arg OPENCODE_VERSION=${OPENCODE_VERSION} --build-arg NODE_VERSION=${NODE_VERSION} -t $IMAGE" fi