Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
2.4 kB · 63 lines
Shell
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364#!/usr/bin/env bashset -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 namesimg() { 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' </dev/nulldone <<'TARGETS'web .svelte-kit web-svelte-kitcamo .wrangler camo-wrangleravatar .wrangler avatar-wranglerTARGETS
warm bobbin podman run --rm -v "$REPO_ROOT:/src" -w /src \ -v "${PROJECT}_bobbin-cargo:/cargo" -v "${PROJECT}_bobbin-target:/target" \ -e CARGO_HOME=/cargo -e CARGO_TARGET_DIR=/target \ --entrypoint sh "$(img bobbin)" \ -c 'cargo fetch --locked && cargo build --release --bin bobbin --package bobbin'
[ ${#failed[@]} -eq 0 ] || { printf 'these caches are still cold: %s\n' "${failed[*]}" >&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}