Files
opencode-container/build.sh
T
2026-10-05 23:38:19 +02:00

74 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
UBUNTU_VERSION="${UBUNTU_VERSION:-26.04}"
NODE_VERSION="${NODE_VERSION:-24.21.0}"
OPENCODE_VERSION="${OPENCODE_VERSION:-2.0.22}"
IMAGE="${IMAGE_REPO:-localhost/opencode-dev}"
usage() {
echo 'Usage: $0 [--no-cache] [--update] [--dry-run] [--remove] [--prune] [--apt-packages="pack1 pack2"]'
exit "${1:-0}"
}
BUILD_OPTS=()
DRY_RUN=0
REMOVE=0
PRUNE=0
EXTRA_APT_PACKAGES=()
while (($#)); do
case "$1" in
--no-cache) BUILD_OPTS+=(--no-cache) ;;
--update) BUILD_OPTS+=(--no-cache --pull=newer) ;;
--dry-run) DRY_RUN=1 ;;
--remove) REMOVE=1 ;;
--prune) PRUNE=1 ;;
--apt-packages=*)
read -ra _pkgs <<< "${1#*=}"
EXTRA_APT_PACKAGES="${_pkgs[@]}" ;;
-h|--help) usage ;;
*) echo "Unknown option: $1" >&2; usage 2 ;;
esac
shift
done
if [[ -n "${EXTRA_APT_PACKAGES[@]}" ]]; then
echo "--> Apt extra pkg: ${EXTRA_APT_PACKAGES[*]}"
fi
if ((REMOVE || PRUNE)); then
if ((REMOVE)); then
podman image rm "${IMAGE}" 2>/dev/null
fi
if ((PRUNE)); then
podman image prune -f 2>/dev/null
fi
exit 0
fi
CMD=(
podman build
"${BUILD_OPTS[@]}"
--build-arg "UBUNTU_VERSION=${UBUNTU_VERSION}"
--build-arg "NODE_VERSION=${NODE_VERSION}"
--build-arg "OPENCODE_VERSION=${OPENCODE_VERSION}"
--build-arg "EXTRA_APT_PACKAGES=${EXTRA_APT_PACKAGES[*]}"
--build-arg "DEV_UID=$(id -u)"
--build-arg "DEV_GID=$(id -g)"
-t "$IMAGE"
.
)
if ((DRY_RUN)); then
printf 'running:'; printf ' %q' "${CMD[@]}"; echo
exit 0
fi
"${CMD[@]}"
echo
echo "Built: $IMAGE"