-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
260 lines (210 loc) · 8.72 KB
/
Copy pathjustfile
File metadata and controls
260 lines (210 loc) · 8.72 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
set shell := ["bash", "-euo", "pipefail", "-c"]
# Cert-Manager Porkbun Webhook - Justfile
# =============================================================================
# Configuration
# =============================================================================
# Registry and repository settings
github_user := "hoodnoah"
repo_name := "certmanager-porkbun-webhook"
registry := "ghcr.io"
repo := github_user + "/" + repo_name
image_name := "porkbun-webhook"
# Kubernetes settings
namespace := "cert-manager"
app_label := "porkbun-webhook"
# =============================================================================
# Development - Minikube
# =============================================================================
# Start minikube cluster
minikube-start:
minikube start
# Stop minikube cluster
minikube-stop:
minikube stop
# Delete minikube cluster
minikube-delete:
minikube delete
# Build image directly into minikube's Docker daemon
build-minikube:
#!/usr/bin/env bash
eval $(minikube docker-env --shell bash)
docker build -t {{ image_name }}:latest .
echo "Image built and available in minikube"
# =============================================================================
# Building & Releasing
# =============================================================================
# Build image locally
build:
docker build -t {{ image_name }}:latest .
# Build and push to GHCR (usage: just release 0.1.0)
release version:
echo "Building webhook image for linux/amd64..."
docker buildx build \
--platform linux/amd64 \
-f Dockerfile \
-t {{ registry }}/{{ repo }}:{{ version }} \
-t {{ registry }}/{{ repo }}:latest \
--push .
echo "Tagging release in git..."
git tag -a {{ version }} -m "Release {{ version }}"
git push origin {{ version }}
echo "Released {{ registry }}/{{ repo }}:{{ version }}"
# Build multi-arch and push to GHCR (usage: just release-multiarch 0.1.0)
release-multiarch version:
echo "Building webhook image for linux/amd64 and linux/arm64..."
docker buildx build \
--platform linux/amd64,linux/arm64 \
-f Dockerfile \
-t {{ registry }}/{{ repo }}:{{ version }} \
-t {{ registry }}/{{ repo }}:latest \
--push .
echo "Tagging release in git..."
git tag -a {{ version }} -m "Release {{ version }}"
git push origin {{ version }}
echo "Released {{ registry }}/{{ repo }}:{{ version }} (multi-arch)"
# =============================================================================
# Kubernetes Deployment
# =============================================================================
# Install cert-manager via Helm
install-cert-manager:
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install cert-manager jetstack/cert-manager \
--namespace {{ namespace }} \
--create-namespace \
--set crds.enabled=true
kubectl wait --for=condition=ready pod -l app.kubernetes.io/instance=cert-manager -n {{ namespace }} --timeout=120s
# Deploy all webhook manifests (for minikube with local image)
deploy-local: build-minikube
echo "Applying manifests..."
kubectl apply -f manifests/pki.yaml
kubectl wait --for=condition=ready certificate -n {{ namespace }} porkbun-webhook-ca porkbun-webhook-webhook-tls --timeout=60s
kubectl apply -f manifests/rbac.yaml
kubectl apply -f manifests/webhook-service.yaml
kubectl apply -f manifests/webhook-deployment.yaml
kubectl wait --for=condition=ready pod -l app={{ app_label }} -n {{ namespace }} --timeout=90s
kubectl apply -f manifests/apiservice.yaml
echo "Webhook deployed successfully"
# Deploy all webhook manifests (for remote cluster with registry image)
deploy:
echo "Applying manifests..."
kubectl apply -f manifests/pki.yaml
kubectl wait --for=condition=ready certificate -n {{ namespace }} porkbun-webhook-ca porkbun-webhook-webhook-tls --timeout=60s
kubectl apply -f manifests/rbac.yaml
kubectl apply -f manifests/webhook-service.yaml
kubectl apply -f manifests/webhook-deployment.yaml
kubectl wait --for=condition=ready pod -l app={{ app_label }} -n {{ namespace }} --timeout=90s
kubectl apply -f manifests/apiservice.yaml
echo "Webhook deployed successfully"
# Deploy ClusterIssuers
deploy-issuers:
kubectl apply -f manifests/clusterissuer-staging.yaml
kubectl apply -f manifests/clusterissuer.yaml
# Undeploy webhook (keeps cert-manager)
undeploy:
-kubectl delete -f manifests/apiservice.yaml
-kubectl delete -f manifests/webhook-deployment.yaml
-kubectl delete -f manifests/webhook-service.yaml
-kubectl delete -f manifests/rbac.yaml
-kubectl delete -f manifests/pki.yaml
# Redeploy webhook (rebuild and restart)
redeploy: undeploy deploy-local
# Apply Porkbun credentials secret
apply-secret:
kubectl apply -f secret/porkbun-credentials.yaml
# =============================================================================
# Testing
# =============================================================================
# Deploy test certificate (staging)
test-staging:
kubectl apply -f manifests/test-certificate.yaml
@echo "Watching certificate status..."
kubectl get certificate -n test-porkbun -w
# Clean up test certificate
test-cleanup:
-kubectl delete -f manifests/test-certificate.yaml
-kubectl delete namespace test-porkbun
# Run full end-to-end test
test-e2e: deploy-local apply-secret deploy-issuers test-staging
# =============================================================================
# Debugging & Logs
# =============================================================================
# Tail webhook logs
logs:
kubectl logs -n {{ namespace }} -l app={{ app_label }} -f
# Tail webhook logs (last 50 lines)
logs-tail:
kubectl logs -n {{ namespace }} -l app={{ app_label }} --tail=50
# Tail cert-manager controller logs
logs-cm:
kubectl logs -n {{ namespace }} -l app=cert-manager -f
# Describe webhook pod
describe:
kubectl describe pod -n {{ namespace }} -l app={{ app_label }}
# Get webhook pod status
status:
@echo "=== Webhook Pod ==="
kubectl get pods -n {{ namespace }} -l app={{ app_label }}
@echo ""
@echo "=== API Service ==="
kubectl get apiservices | grep acme
@echo ""
@echo "=== ClusterIssuers ==="
kubectl get clusterissuers
@echo ""
@echo "=== Certificates ==="
kubectl get certificates -A
# Test API endpoint
test-api:
kubectl get --raw "/apis/acme.noah-hood.io/v1alpha1"
# Get all challenges
challenges:
kubectl get challenges -A
@echo ""
@echo "For details: kubectl describe challenge <name> -n <namespace>"
# Get all orders
orders:
kubectl get orders -A
# Shell into webhook pod
shell:
kubectl exec -it -n {{ namespace }} $(kubectl get pods -n {{ namespace }} -l app={{ app_label }} -o jsonpath='{.items[0].metadata.name}') -- /bin/sh
# =============================================================================
# Utilities
# =============================================================================
# Check DNS propagation for a domain (usage: just check-dns test.noah-hood.io)
check-dns domain:
dig TXT _acme-challenge.{{ domain }} +short
# Restart webhook deployment
restart:
kubectl rollout restart deployment {{ app_label }} -n {{ namespace }}
# Get events in cert-manager namespace
events:
kubectl get events -n {{ namespace }} --sort-by='.lastTimestamp'
# Port-forward webhook for local debugging
port-forward:
kubectl port-forward -n {{ namespace }} svc/{{ app_label }} 8443:443
# =============================================================================
# Full Workflow Shortcuts
# =============================================================================
# Full setup: minikube + cert-manager + webhook + issuers
setup: minikube-start install-cert-manager apply-secret deploy-local deploy-issuers
@echo "Setup complete! Run 'just test-staging' to test certificate issuance."
# Clean everything and start fresh
reset: minikube-delete setup
# Show available commands
help:
@just --list
# Run the cert-manager DNS01 conformance suite (makes REAL Porkbun API calls;
# requires PORKBUN_API_KEY and PORKBUN_SECRET_KEY in the environment)
test-conformance:
#!/usr/bin/env bash
set -euo pipefail
: "${PORKBUN_API_KEY:?PORKBUN_API_KEY must be set}"
: "${PORKBUN_SECRET_KEY:?PORKBUN_SECRET_KEY must be set}"
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.23
BIN="$("$(go env GOPATH)/bin/setup-envtest" use 1.35.x -p path)"
export TEST_ASSET_ETCD="$BIN/etcd"
export TEST_ASSET_KUBE_APISERVER="$BIN/kube-apiserver"
export TEST_ASSET_KUBECTL="$BIN/kubectl"
export TEST_ZONE_NAME="noah-hood.io."
go test -v -tags conformance -timeout 15m ./...