-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
138 lines (100 loc) · 4.41 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
SHELL := /bin/bash
# ==============================================================================
# Testing running system
# For testing a simple query on the system. Don't forget to `make seed` first.
# curl --user "[email protected]:gophers" http://localhost:3000/v1/users/token
# export TOKEN="COPY TOKEN STRING FROM LAST CALL"
# curl -H "Authorization: Bearer ${TOKEN}" http://localhost:3000/v1/users/1/2
#
# For testing load on the service.
# go install github.com/rakyll/hey@latest
# hey -m GET -c 100 -n 10000 -H "Authorization: Bearer ${TOKEN}" http://localhost:3000/v1/users/1/2
# Launch zipkin.
# http://localhost:9411/zipkin/
# Access metrics directly (4000) or through the sidecar (3001)
# go install github.com/divan/expvarmon@latest
# expvarmon -ports=":4000" -vars="build,requests,goroutines,errors,panics,mem:memstats.Alloc"
# expvarmon -ports=":3001" -endpoint="/metrics" -vars="build,requests,goroutines,errors,panics,mem:memstats.Alloc"
# go install github.com/rakyll/hey@latest
# hey -m GET -c 100 -n 10000 http://localhost:3000/v1/test
# 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
# Testing Auth
# curl -il http://localhost:3000/v1/testauth
# curl -il -H "Authorization: Bearer ${TOKEN}" http://localhost:3000/v1/testauth
# Database Access
# terminal brew install danvergara/tools/dblab
# dblab --host 0.0.0.0 --user postgres --db postgres --pass postgres --ssl disable --port 5432 --driver postgres
# ==============================================================================
run:
go run app/services/sales-api/main.go | go run app/tooling/logfmt/main.go
admin:
go run app/tooling/admin/main.go
# ==============================================================================
# Running tests within the local computer
test:
go test ./... -count=1
staticcheck -checks=all ./...
# ==============================================================================
# Build containers
VERSION := 1.0
all: sales-api
sales-api:
docker build \
-f zarf/docker/dockerfile.sales-api \
-t sales-api-amd64:$(VERSION) \
--build-arg BUILD_REF=:$(VERSION) \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
.
# ==============================================================================
# Running from within k8s/kind
KIND_CLUSTER := ardan-starter-cluster
# Upgrade to latest Kind: brew upgrade kind
# For full Kind v0.14 release notes: https://github.com/kubernetes-sigs/kind/releases/tag/v0.14.0
# The image used below was copied by the above link and supports both amd64 and arm64.
kind-up:
kind create cluster \
--image kindest/node:v1.24.0@sha256:0866296e693efe1fed79d5e6c7af8df71fc73ae45e3679af05342239cdc5bc8e \
--name $(KIND_CLUSTER) \
--config zarf/k8s/kind/kind-config.yaml
kubectl config set-context --current --namespace=sales-system
kustomize build zarf/k8s/kind/sales-pod | kubectl apply -f -
kind-down:
kind delete cluster --name $(KIND_CLUSTER)
kind-load:
cd zarf/k8s/kind/sales-pod; kustomize edit set image sales-api-image=sales-api-amd64:$(VERSION)
kind load docker-image sales-api-amd64:$(VERSION) --name $(KIND_CLUSTER)
kind-apply:
kustomize build zarf/k8s/kind/database-pod | kubectl apply -f -
kubectl wait --namespace=database-system --timeout=120s --for=condition=Available deployment/database-pod
kustomize build zarf/k8s/kind/sales-pod | kubectl apply -f -
kind-status:
kubectl get nodes -o wide
kubectl get svc -o wide
kubectl get pods -o wide --watch --all-namespaces
kind-status-sales:
kubectl get pods -o wide --watch
kind-status-db:
kubectl get pods -o wide --watch --namespace=database-system
kind-logs:
kubectl logs -l app=sales --all-containers=true -f --tail=100 | go run app/tooling/logfmt/main.go
kind-logs-sales:
kubectl logs -l app=sales --all-containers=true -f --tail=100 | go run app/tooling/logfmt/main.go -service=SALES-API
kind-restart:
kubectl rollout restart deployment sales-pod
kind-update: all kind-load kind-restart
kind-update-apply: all kind-load kind-apply
kind-describe:
kubectl describe pod -l app=sales
kind-setup: all kind-up kind-load kind-apply
# ==============================================================================
# Modules support
tidy:
go mod tidy
go mod vendor
deps-upgrade:
# go get $(go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all)
go get -u -v ./...
go mod tidy
go mod vendor