#!/usr/bin/env bash
# Custom install-steps hook for custom-html-tiny (Phase 1d DG5).
#
# custom-html-tiny is a static-web-server that serves from an (otherwise EMPTY) `content` volume, so
# the GENERIC install legitimately fails 404 with zero config — that is the correct, reported
# graceful-generic outcome (a recipe needing a step fails the generic, you fix it by adding a step).
# This hook is that step: it pre-seeds an index.html into the app's content volume BEFORE deploy, so
# the app actually serves. With this hook present the generic install passes; remove it and the
# generic install fails again — demonstrating the hook + the graceful-generic rule both real.
#
# Runs on cc-ci (root) after `abra app new` + env, before `abra app deploy`. Env: CCCI_APP_DOMAIN,
# CCCI_RECIPE, CCCI_APP_ENV. Writes straight to the swarm volume's mountpoint (no container/image
# pull). The volume is created here so it exists when the stack deploys (swarm reuses a named volume).
set -euo pipefail

stack="${CCCI_APP_DOMAIN//./_}"
vol="${stack}_content"

docker volume create "$vol" >/dev/null
mountpoint="$(docker volume inspect "$vol" --format '{{.Mountpoint}}')"
cat >"${mountpoint}/index.html" <<'HTML'
<!doctype html>
<html><body>
<h1>cc-ci custom-html-tiny</h1>
<p>content seeded by install_steps.sh (custom install-steps hook, DG5)</p>
</body></html>
HTML
echo "install_steps: seeded index.html into volume ${vol} (${mountpoint})"
