|
| 1 | +[env] |
| 2 | +CLUSTER_NAME = "ns-dev" |
| 3 | + |
| 4 | +[tasks."k3d:up"] |
| 5 | +description = "Spin up k3d cluster with envsubst" |
| 6 | +run = """ |
| 7 | +if k3d cluster list "$CLUSTER_NAME" > /dev/null 2>&1; then |
| 8 | + echo "Cluster $CLUSTER_NAME already exists, skipping creation." |
| 9 | +else |
| 10 | + TMP_FILE=$(mktemp) |
| 11 | + envsubst < k3d.yaml > "$TMP_FILE" |
| 12 | + k3d cluster create "$CLUSTER_NAME" -c "$TMP_FILE" |
| 13 | + rm "$TMP_FILE" |
| 14 | +fi |
| 15 | +""" |
| 16 | +env = { PROJECT_ROOT = "{{ config_root | dirname }}" } |
| 17 | + |
| 18 | +[tasks."k3d:down"] |
| 19 | +description = "Spin down k3d cluster" |
| 20 | +run = "k3d cluster delete $CLUSTER_NAME" |
| 21 | + |
| 22 | +[tasks."ensure:context"] |
| 23 | +description = "Switch kubectl context to k3d" |
| 24 | +run = "kubectl config use-context k3d-$CLUSTER_NAME" |
| 25 | + |
| 26 | +[tasks.import] |
| 27 | +description = "Build and import images into k3d" |
| 28 | +depends = ["build"] |
| 29 | +run = """ |
| 30 | +#!/usr/bin/env bash |
| 31 | +images=( |
| 32 | + ns-dashboard ns-sablier ns-auth-dev ns-builder |
| 33 | + ns-controller ns-gateway ns-gitea-integration |
| 34 | + ns-migrate ns-ssgen |
| 35 | +) |
| 36 | +k3d image import --cluster "$CLUSTER_NAME" $(printf "ghcr.io/traptitech/%s:main " "${images[@]}") |
| 37 | +""" |
| 38 | + |
| 39 | +[tasks.apply] |
| 40 | +description = "Apply manifests to k3d cluster (Helm enabled)" |
| 41 | +depends = ["ensure:context"] |
| 42 | +run = """ |
| 43 | +ls -d */ | tr -d '/' | grep -v -E 'coredns-patch|crd' | \ |
| 44 | +xargs -I{} sh -c 'kubectl create namespace {} --dry-run=client -o yaml | kubectl apply -f -' |
| 45 | +
|
| 46 | +kustomize build ./crd | kubectl apply -f - |
| 47 | +kustomize build --enable-helm --load-restrictor LoadRestrictionsNone . | kubectl apply -f - |
| 48 | +
|
| 49 | +kubectl rollout restart deployment/coredns -n kube-system |
| 50 | +""" |
| 51 | + |
| 52 | +# ---- All-in-one commands ---- |
| 53 | + |
| 54 | +[tasks.up] |
| 55 | +description = "Full setup: k3d-up -> import -> apply" |
| 56 | +run = [{ task = "k3d:up" }, { task = "import" }, { task = "apply" }] |
| 57 | + |
| 58 | +[tasks.down] |
| 59 | +description = "Full teardown" |
| 60 | +run = { task = "k3d:down" } |
0 commit comments