Files
mtgc/scripts/sync-server-image.sh
2026-10-16 20:12:11 -05:00

65 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# sync-server-image.sh — build or push the mtgc sync server's container image.
#
# The image is tagged ${IMAGE_REPO}:${IMAGE_TAG}, by default the Docker Hub
# repository docker.io/glmdev/mtgc:latest.
#
# Usage:
# ./scripts/sync-server-image.sh build
# ./scripts/sync-server-image.sh push
#
# Or through npm: `npm run sync-server:build` / `npm run sync-server:push`.
#
# Environment:
# IMAGE_REPO repository to tag/push (default: docker.io/glmdev/mtgc)
# IMAGE_TAG tag to build/push (default: latest)
# CONTAINER_ENGINE docker or podman (default: docker if installed, else podman)
#
# `push` pushes what `build` produced; it doesn't rebuild. Log in to the
# registry first (`docker login docker.io`).
#
set -euo pipefail
usage() {
sed -n '3,21p' "$0" | sed 's/^# \{0,1\}//'
exit "${1:-0}"
}
[ $# -eq 1 ] || usage 1
case "$1" in
build | push) action="$1" ;;
-h | --help) usage ;;
*) usage 1 ;;
esac
engine="${CONTAINER_ENGINE:-}"
if [ -z "$engine" ]; then
if command -v docker >/dev/null 2>&1; then
engine=docker
elif command -v podman >/dev/null 2>&1; then
engine=podman
else
echo "sync-server-image: neither docker nor podman is installed" >&2
exit 1
fi
fi
image="${IMAGE_REPO:-docker.io/glmdev/mtgc}:${IMAGE_TAG:-latest}"
# The Dockerfile builds from the workspace root, so run from there whatever
# directory this was invoked in.
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
case "$action" in
build)
echo "==> building $image"
"$engine" build -f crates/mtgc-server/Dockerfile -t "$image" .
;;
push)
echo "==> pushing $image"
"$engine" push "$image"
;;
esac