#!/usr/bin/env bash set -euo pipefail # Usage: ./build.sh [poller|web|all] [commit message] # web — build/push ONLY the web image (use this for web iterations so the # poller image is never rebuilt/repushed) # poller— build/push ONLY the poller image (touch deliberately) # all — both (default) # # Deploy pins images by SHA (compose.*.yml ship :latest as a convenience only). REG="docker.adamksmith.xyz" cd "$(dirname "$0")" TARGET="${1:-all}" case "$TARGET" in poller) TARGETS="poller" ;; web) TARGETS="web" ;; all) TARGETS="poller web" ;; *) echo "usage: $0 [poller|web|all] [message]" >&2; exit 1 ;; esac MSG="${2:-Build and push images}" # Stage and commit all changes git add -A if git diff --cached --quiet; then echo "No changes to commit, using HEAD" else git commit -m "${MSG}" fi SHA=$(git rev-parse --short HEAD) for target in ${TARGETS}; do img="${REG}/jbod-${target}" echo "Building ${img}:${SHA}" docker build --target "${target}" -t "${img}:${SHA}" -t "${img}:latest" . echo "Pushing ${img}:${SHA}" docker push "${img}:${SHA}" docker push "${img}:latest" done echo "Done (${TARGET}): ${REG}/jbod-{${TARGETS// /,}}:${SHA}"