-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTiltfile
More file actions
114 lines (99 loc) · 3.81 KB
/
Copy pathTiltfile
File metadata and controls
114 lines (99 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Mini-Ledger Tiltfile - GitOps Bootstrap
load("ext://helm_remote", "helm_remote")
# Bootstrap: namespace, configmap, OCI source
k8s_yaml(kustomize("deploy/bootstrap"))
# Flux CD (minimal install)
helm_remote("flux2",
repo_url="https://fluxcd-community.github.io/helm-charts",
namespace="flux-system",
version="2.14.0",
set=[
"installCRDs=true",
"notificationController.create=false",
"imageReflectionController.create=false",
"imageAutomationController.create=false",
],
)
k8s_resource(
workload="source-controller",
new_name="flux2",
labels=["gitops"],
)
# Flux Kustomizations (define what gets deployed from OCI artifact)
k8s_yaml(kustomize("deploy/clusters/local"))
k8s_resource(new_name="flux-kustomizations",
objects=["platform-dependencies:kustomization", "platform:kustomization", "services:kustomization"],
resource_deps=["flux2"],
labels=["gitops"],
)
# Push deploy/ to OCI registry
local_resource("push-oci-artifact",
cmd="task flux:push",
deps=["deploy/clusters", "deploy/components"],
resource_deps=["flux2"],
labels=["gitops"],
)
# Build and push application image
local_resource("build-mini-ledger",
cmd="task docker:build docker:push REGISTRY=localhost:5050 TAG=latest",
deps=["cmd", "internal", "pkg", "go.mod", "go.sum", "Dockerfile", "migrations"],
resource_deps=["flux2"],
labels=["app"],
)
# Build and push e2e test image
local_resource("build-e2e-tests",
cmd="task docker:e2e:build docker:e2e:push REGISTRY=localhost:5050 TAG=latest",
deps=["test", "internal", "pkg", "go.mod", "go.sum", "Dockerfile.e2e"],
resource_deps=["flux2"],
labels=["test"],
)
# Wait for Kustomizations to reconcile
local_resource("wait-for-reconciliation",
cmd="""
echo "⏳ Waiting for Kustomizations to reconcile..."
# Wait for all Kustomizations to be ready
timeout=300
elapsed=0
while [ $elapsed -lt $timeout ]; do
# Count total Kustomizations
total=$(kubectl get kustomizations.kustomize.toolkit.fluxcd.io -n flux-system -o json | jq -r '.items | length')
# Count Kustomizations with Ready=True condition
ready=$(kubectl get kustomizations.kustomize.toolkit.fluxcd.io -n flux-system -o json | \
jq -r '[.items[] | select(.status.conditions[]? | select(.type=="Ready" and .status=="True"))] | length')
if [ "$ready" -eq "$total" ] && [ "$total" -gt "0" ]; then
echo "✅ All Kustomizations reconciled successfully! ($ready/$total)"
flux get kustomizations -A
exit 0
fi
# Show current status
echo "[$elapsed/$timeout s] Ready: $ready/$total"
flux get kustomizations -A 2>/dev/null || true
sleep 5
elapsed=$((elapsed + 5))
done
echo "❌ Timeout waiting for Kustomizations to reconcile"
flux get kustomizations -A
exit 1
""",
resource_deps=["flux-kustomizations", "push-oci-artifact", "build-mini-ledger"],
labels=["gitops"],
)
# Manual helpers
local_resource("flux-reconcile",
cmd="task flux:reconcile",
auto_init=False, trigger_mode=TRIGGER_MODE_MANUAL, labels=["helpers"],
)
local_resource("flux-status",
cmd="task flux:status",
auto_init=False, trigger_mode=TRIGGER_MODE_MANUAL, labels=["helpers"],
)
local_resource("cleanup-kustomizations",
cmd="kubectl get kustomizations.kustomize.toolkit.fluxcd.io -n flux-system -o name 2>/dev/null | xargs -I {} kubectl patch {} -n flux-system -p '{\"metadata\":{\"finalizers\":[]}}' --type=merge || true",
auto_init=False, trigger_mode=TRIGGER_MODE_MANUAL, labels=["helpers"],
)
# E2E test runner (runs automatically after Kustomizations are reconciled)
local_resource("run-e2e-tests",
cmd="task test:e2e:k8s",
resource_deps=["wait-for-reconciliation", "build-e2e-tests"],
labels=["test"],
)