rig major updates
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# The dev loop. `make tilt` from the project root, or `cd ctrl && tilt up`.
|
||||
# Works unedited; replace the two EXAMPLES and add yours in the marked sections.
|
||||
# rig supplies this file but does not own it, and nothing here names this directory.
|
||||
# The dev loop, rig's half. `make tilt` from rig's folder, or from an overlay's forwarder.
|
||||
# rig owns this file: who we are, the context guard, the registry, the overlay's manifests.
|
||||
# The workload's half is the overlay's own Tiltfile, included at the end; edit that one.
|
||||
# Notes: docs/notes/Tiltfile.md
|
||||
|
||||
# ── who we are, and on which ports ─────────────────────────────────────────
|
||||
@@ -12,10 +12,9 @@ HTTP = _facts[2]
|
||||
HTTPS = _facts[3]
|
||||
TILT = _facts[4]
|
||||
REGISTRY = _facts[5]
|
||||
|
||||
# Where the manifests live (MANIFESTS_DIR, see k8s/README.md).
|
||||
# The value is REPO-ROOT relative and this file runs in ctrl/, so prefix '../'.
|
||||
MANIFESTS = '../' + _facts[6]
|
||||
# Absolute paths, or '-' when there is none.
|
||||
MANIFESTS = '' if _facts[6] == '-' else _facts[6]
|
||||
OVERLAY = '' if _facts[7] == '-' else _facts[7]
|
||||
|
||||
# ── refuse to deploy into the wrong cluster ────────────────────────────────
|
||||
# Tilt fixes the context before parsing this file, so it can only be refused here.
|
||||
@@ -25,73 +24,44 @@ if k8s_context() != CTX:
|
||||
fail("Wrong kubectl context: '%s'. This is %s — run: make tilt, or tilt up --context %s"
|
||||
% (k8s_context(), CLUSTER, CTX))
|
||||
|
||||
# The namespace has to exist before anything lands in it, and kustomize does not
|
||||
# guarantee ordering across resources. Creating it here is idempotent.
|
||||
local('kubectl --context %s create namespace %s --dry-run=client -o yaml | kubectl --context %s apply -f -'
|
||||
% (CTX, CLUSTER, CTX), quiet=True)
|
||||
|
||||
# ── images go to this environment's own registry ───────────────────────────
|
||||
# Fail closed: name the registry rather than let Tilt infer it, or a miss pushes
|
||||
# an unqualified image to docker.io.
|
||||
default_registry('localhost:' + REGISTRY)
|
||||
|
||||
k8s_yaml(kustomize(MANIFESTS))
|
||||
|
||||
# ── Images ─────────────────────────────────────────────────────────────────
|
||||
# (nothing yet — rig's examples run upstream images. Add docker_build calls here.)
|
||||
|
||||
|
||||
# ── Resources ──────────────────────────────────────────────────────────────
|
||||
# (nothing yet — add k8s_resource calls here to name and order what you deploy.)
|
||||
|
||||
|
||||
# Everything with no dev loop of its own, gathered so it does not clutter the UI.
|
||||
k8s_resource(
|
||||
objects=[CLUSTER + ':namespace'],
|
||||
new_name='infra',
|
||||
)
|
||||
# ── the overlay's manifests ────────────────────────────────────────────────
|
||||
# Every namespace they use must exist before anything lands in it, and kustomize
|
||||
# does not order resources, so create them here (idempotent). The Namespaces they
|
||||
# declare are grouped as 'infra', whatever they are named.
|
||||
if MANIFESTS:
|
||||
_yaml = kustomize(MANIFESTS)
|
||||
k8s_yaml(_yaml)
|
||||
_declared = []
|
||||
_namespaces = {}
|
||||
for _o in decode_yaml_stream(_yaml):
|
||||
if not _o:
|
||||
continue
|
||||
_md = _o.get('metadata') or {}
|
||||
if _o.get('kind') == 'Namespace':
|
||||
_declared.append(_md.get('name'))
|
||||
_namespaces[_md.get('name')] = True
|
||||
elif _md.get('namespace'):
|
||||
_namespaces[_md.get('namespace')] = True
|
||||
for _ns in sorted(_namespaces.keys()):
|
||||
local('kubectl --context %s create namespace %s --dry-run=client -o yaml | kubectl --context %s apply -f -'
|
||||
% (CTX, _ns, CTX), quiet=True)
|
||||
if _declared:
|
||||
k8s_resource(objects=[_n + ':namespace' for _n in _declared], new_name='infra')
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# Catalogue — paste what you need, delete the rest.
|
||||
# Commented out so this file runs as-is.
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
#
|
||||
# ── build an image ─────────────────────────────────────────────────────────
|
||||
# context= is the REPO ROOT ('..'); dockerfile= is relative to THIS file (ctrl/).
|
||||
# So every COPY is repo-root relative, even for files beside the Dockerfile.
|
||||
#
|
||||
# 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', 'def', '.venv', 'node_modules', '__pycache__'],
|
||||
# live_update=[sync('../api', '/app/api')],
|
||||
# )
|
||||
#
|
||||
# ── 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 %s rollout restart deployment/gateway' % (CTX, CLUSTER),
|
||||
# deps=['k8s/base/Caddyfile'],
|
||||
# resource_deps=['gateway'],
|
||||
# auto_init=False,
|
||||
# )
|
||||
#
|
||||
# ── an overlay whose secretGenerator reads outside its own directory ───────
|
||||
# kustomize refuses to read above the kustomization root unless told to. Only
|
||||
# add this if you actually have such a generator; it loosens a safety check.
|
||||
#
|
||||
# k8s_yaml(kustomize(MANIFESTS, 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'])
|
||||
# ── the workload's half: the overlay's Tiltfile ────────────────────────────
|
||||
# Included, so its relative paths resolve from the overlay's own folder. It reads
|
||||
# these facts with os.getenv and never needs a path back into rig.
|
||||
os.putenv('RIG_CLUSTER', CLUSTER)
|
||||
os.putenv('RIG_CONTEXT', CTX)
|
||||
os.putenv('RIG_HTTP_PORT', HTTP)
|
||||
os.putenv('RIG_HTTPS_PORT', HTTPS)
|
||||
os.putenv('RIG_TILT_PORT', TILT)
|
||||
os.putenv('RIG_REGISTRY', 'localhost:' + REGISTRY)
|
||||
os.putenv('RIG_OVERLAY_DIR', OVERLAY)
|
||||
if OVERLAY and os.path.exists(OVERLAY + '/Tiltfile'):
|
||||
include(OVERLAY + '/Tiltfile')
|
||||
|
||||
Reference in New Issue
Block a user