# The starter overlay's half of the dev loop. rig's ctrl/Tiltfile includes this once
# it has applied k8s/overlays/dev, so every path here is relative to THIS folder.
# Facts from rig, via os.getenv: RIG_CLUSTER RIG_CONTEXT RIG_HTTP_PORT RIG_HTTPS_PORT
#   RIG_TILT_PORT RIG_REGISTRY RIG_OVERLAY_DIR
# Notes: rig's docs/notes/overlay.md

CLUSTER = os.getenv('RIG_CLUSTER')
HTTP    = os.getenv('RIG_HTTP_PORT')

# ── Images ─────────────────────────────────────────────────────────────────
# (nothing yet — the examples run upstream images. Add docker_build calls here.)


# ── Resources ──────────────────────────────────────────────────────────────
# (nothing yet — add k8s_resource calls here to name and order what you deploy.)


# ═══════════════════════════════════════════════════════════════════════════
# Catalogue — paste what you need, delete the rest.
# Commented out so this file runs as-is.
# ═══════════════════════════════════════════════════════════════════════════
#
# ── build an image ─────────────────────────────────────────────────────────
# context= and dockerfile= are both relative to this folder, so every COPY in the
# Dockerfile is relative to the context you name here.
#
# docker_build(
#     CLUSTER + '-api',                  # must match `image:` in the manifest —
#     context='.',                       #   that string is the only thing
#     dockerfile='Dockerfile.api',       #   connecting the two
#     ignore=['.git', 'rig', '.venv', 'node_modules', '__pycache__'],
#     live_update=[sync('api', '/app/api')],
# )
#
# ── a shared base, built once ──────────────────────────────────────────────
# Components that share code build FROM one base image instead of each carrying
# a copy of it. Tilt builds the base first when a Dockerfile's FROM names it.
#
# docker_build(CLUSTER + '-base', context='repodir/base')
# docker_build(CLUSTER + '-api', context='repodir/api')   # its Dockerfile: FROM <cluster>-base
#
# ── name and order a resource ──────────────────────────────────────────────
# k8s_resource('api', resource_deps=['postgres'], labels=['app'])
# k8s_resource('gateway', resource_deps=['api', 'ui'], labels=['app'])
#
# ── reload the gateway when its config changes ─────────────────────────────
# A hash-less configMapGenerator ConfigMap never changes name, so edits do NOT
# roll the pod on their own.
#
# local_resource(
#     'gateway-reload',
#     cmd='kubectl --context %s -n <namespace> rollout restart deployment/gateway' % os.getenv('RIG_CONTEXT'),
#     deps=['k8s/base/Caddyfile'],
#     resource_deps=['gateway'],
#     auto_init=False,
# )
#
# ── manifests that need kustomize flags ────────────────────────────────────
# rig applies MANIFESTS_DIR without flags. If a secretGenerator reads above its
# kustomization root, set MANIFESTS_DIR=none in rig.env and apply them here instead;
# the flag loosens a safety check for the whole build.
#
# k8s_yaml(kustomize('k8s/overlays/dev', flags=['--load-restrictor=LoadRestrictionsNone']))
#
# ── reach a service directly, bypassing the gateway ────────────────────────
# Prefer the gateway; host ports are shared machine-wide. If you need one, take it
# from this environment's own port block.
#
# k8s_resource('postgres', port_forwards=[str(int(HTTP) + 5) + ':5432'])
