-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
214 lines (154 loc) · 7.18 KB
/
makefile
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
# Check to see if we can use ash, in Alpine images, or default to BASH.
SHELL_PATH = /bin/ash
SHELL = $(if $(wildcard $(SHELL_PATH)),/bin/ash,/bin/bash)
# RSA Keys
# To generate a private/public key PEM file.
# $ openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:2048
# $ openssl rsa -pubout -in private.pem -out public.pem
run:
go run apis/services/sales/main.go | go run apis/tooling/logfmt/main.go
help:
go run apis/services/sales/main.go --help
version:
go run apis/services/sales/main.go --version
curl-test:
curl -il -X GET http://localhost:3000/test
curl-live:
curl -il -X GET http://localhost:3000/liveness
curl-ready:
curl -il -X GET http://localhost:3000/readiness
curl-error:
curl -il -X GET http://localhost:3000/testerror
curl-panic:
curl -il -X GET http://localhost:3000/testpanic
admin:
go run apis/tooling/admin/main.go
# admin token
# export TOKEN=eyJhbGciOiJSUzI1NiIsImtpZCI6IjU0YmIyMTY1LTcxZTEtNDFhNi1hZjNlLTdkYTRhMGUxZTJjMSIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzZXJ2aWNlIHBy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2ebqQKa-fc3JAcJH44hgiiGsA
curl-auth:
curl -il \
-H "Authorization: Bearer ${TOKEN}" "http://localhost:3000/testauth"
token:
curl -il \
--user "[email protected]:gophers" http://localhost:6000/auth/token/54bb2165-71e1-41a6-af3e-7da4a0e1e2c1
users:
curl -il \
-H "Authorization: Bearer ${TOKEN}" "http://localhost:3000/users?page=1&rows=2"
curl-auth2:
curl -il \
-H "Authorization: Bearer ${TOKEN}" "http://localhost:6000/auth/authenticate"
# ==============================================================================
# Define dependencies
GOLANG := golang:1.22
ALPINE := alpine:3.19
KIND := kindest/node:v1.29.2
POSTGRES := postgres:16.2
GRAFANA := grafana/grafana:10.4.0
PROMETHEUS := prom/prometheus:v2.51.0
TEMPO := grafana/tempo:2.4.0
LOKI := grafana/loki:2.9.0
PROMTAIL := grafana/promtail:2.9.0
KIND_CLUSTER := ardan-starter-cluster
NAMESPACE := sales-system
SALES_APP := sales
AUTH_APP := auth
BASE_IMAGE_NAME := localhost/ardanlabs
VERSION := 0.0.1
SALES_IMAGE := $(BASE_IMAGE_NAME)/$(SALES_APP):$(VERSION)
METRICS_IMAGE := $(BASE_IMAGE_NAME)/metrics:$(VERSION)
AUTH_IMAGE := $(BASE_IMAGE_NAME)/$(AUTH_APP):$(VERSION)
# ==============================================================================
# Building containers
build: sales auth
sales:
docker build \
-f zarf/docker/dockerfile.sales \
-t $(SALES_IMAGE) \
--build-arg BUILD_REF=$(VERSION) \
--build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
.
auth:
docker build \
-f zarf/docker/dockerfile.auth \
-t $(AUTH_IMAGE) \
--build-arg BUILD_REF=$(VERSION) \
--build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
.
# ==============================================================================
# Running from within k8s/kind
dev-up:
kind create cluster \
--image $(KIND) \
--name $(KIND_CLUSTER) \
--config zarf/k8s/dev/kind-config.yaml
kubectl wait --timeout=120s --namespace=local-path-storage --for=condition=Available deployment/local-path-provisioner
kind load docker-image $(POSTGRES) --name $(KIND_CLUSTER)
dev-down:
kind delete cluster --name $(KIND_CLUSTER)
dev-status-all:
kubectl get nodes -o wide
kubectl get svc -o wide
kubectl get pods -o wide --watch --all-namespaces
dev-status:
watch -n 2 kubectl get pods -o wide --all-namespaces
# ------------------------------------------------------------------------------
dev-load-db:
kind load docker-image $(POSTGRES) --name $(KIND_CLUSTER)
dev-load:
kind load docker-image $(SALES_IMAGE) --name $(KIND_CLUSTER)
kind load docker-image $(AUTH_IMAGE) --name $(KIND_CLUSTER)
dev-apply:
kustomize build zarf/k8s/dev/database | kubectl apply -f -
kubectl rollout status --namespace=$(NAMESPACE) --watch --timeout=120s sts/database
kustomize build zarf/k8s/dev/auth | kubectl apply -f -
kubectl wait pods --namespace=$(NAMESPACE) --selector app=$(AUTH_APP) --timeout=120s --for=condition=Ready
kustomize build zarf/k8s/dev/sales | kubectl apply -f -
kubectl wait pods --namespace=$(NAMESPACE) --selector app=$(SALES_APP) --timeout=120s --for=condition=Ready
dev-restart:
kubectl rollout restart deployment $(AUTH_APP) --namespace=$(NAMESPACE)
kubectl rollout restart deployment $(SALES_APP) --namespace=$(NAMESPACE)
dev-update: build dev-load dev-restart
dev-update-apply: build dev-load dev-apply
dev-logs:
kubectl logs --namespace=$(NAMESPACE) -l app=$(SALES_APP) --all-containers=true -f --tail=100 --max-log-requests=6 | go run apis/tooling/logfmt/main.go -service=$(SALES_APP)
dev-logs-auth:
kubectl logs --namespace=$(NAMESPACE) -l app=$(AUTH_APP) --all-containers=true -f --tail=100 | go run apis/tooling/logfmt/main.go
dev-logs-init:
kubectl logs --namespace=$(NAMESPACE) -l app=$(SALES_APP) -f --tail=100 -c init-migrate-seed
# ------------------------------------------------------------------------------
dev-describe-deployment:
kubectl describe deployment --namespace=$(NAMESPACE) $(SALES_APP)
dev-describe-sales:
kubectl describe pod --namespace=$(NAMESPACE) -l app=$(SALES_APP)
dev-describe-auth:
kubectl describe pod --namespace=$(NAMESPACE) -l app=$(AUTH_APP)
# ==============================================================================
# Metrics and Tracing
metrics:
expvarmon -ports="localhost:3010" -vars="build,requests,goroutines,errors,panics,mem:memstats.HeapAlloc,mem:memstats.HeapSys,mem:memstats.Sys"
statsviz:
open -a "Google Chrome" http://localhost:3010/debug/statsviz
# ==============================================================================
# Administration
pgcli:
pgcli postgresql://postgres:postgres@localhost
# ==============================================================================
# Modules support
tidy:
go mod tidy
go mod vendor
# ==============================================================================
# Running tests within the local computer
test-r:
CGO_ENABLED=1 go test -race -count=1 ./...
test-only:
CGO_ENABLED=0 go test -count=1 ./...
lint:
CGO_ENABLED=0 go vet ./...
staticcheck -checks=all ./...
vuln-check:
govulncheck ./...
test: test-only lint vuln-check
test-race: test-r lint vuln-check