#!/usr/bin/env bash set -euo pipefail REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" RAW_PROJECT="${COMPOSE_PROJECT_NAME:-$(basename "$REPO_ROOT")}" PROJECT="$(printf '%s' "$RAW_PROJECT" | tr '[:upper:]' '[:lower:]' | tr -cd 'a-z0-9_-')" [ -n "$PROJECT" ] || { printf "compose can't use %s as a project name.\n" "$RAW_PROJECT" >&2 printf ' Set COMPOSE_PROJECT_NAME to something matching [a-z0-9_-] and run this again.\n' >&2 exit 1 } [ "$PROJECT" = "$RAW_PROJECT" ] || printf 'addressing volumes and images as %s, which is what compose normalizes %s to.\n' \ "$PROJECT" "$RAW_PROJECT" >&2 # podman-compose and docker-compose disagree on built-image names img() { local n for n in "${PROJECT}-$1:latest" "localhost/${PROJECT}_$1:latest"; do if podman image exists "$n"; then printf '%s' "$n"; return; fi done printf '%s-%s:latest' "$PROJECT" "$1" } failed=() warm() { local name="$1" shift "$@" || { printf 'warming %s failed.\n' "$name" >&2; failed+=("$name"); } } warm appview podman run --rm -v "$REPO_ROOT:/src" -w /src \ -v "${PROJECT}_go-cache:/go/cache" -v "${PROJECT}_go-mod-cache:/go/mod" \ -e CGO_ENABLED=1 -e GOCACHE=/go/cache -e GOMODCACHE=/go/mod \ --entrypoint sh "$(img appview)" \ -c 'go mod download && go build -o /dev/null ./cmd/appview' while read -r svc dir vol; do warm "$svc" podman run --rm -v "$REPO_ROOT/$svc:/src" -w /src \ -v "${PROJECT}_${svc}-node-modules:/src/node_modules" \ -v "${PROJECT}_${vol}:/src/${dir}" \ --entrypoint sh "$(img "$svc")" \ -c 'corepack pnpm install --frozen-lockfile --store-dir /src/node_modules/.pnpm-store' &2 printf ' Their containers fetch at start-up, and the tngl network is internal, so\n' >&2 printf ' "compose up" will loop on a registry or crates.io fetch until this succeeds.\n' >&2 exit 1 }