-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
151 lines (105 loc) · 4.24 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
# ==============================================================================
# Define dependencies
GOLANG := golang:1.23
ALPINE := alpine:3.20
KIND := kindest/node:v1.31.0
POSTGRES := postgres:16.4
BASE_IMAGE_NAME := morgan/service
NAMESPACE := sales-system
APP := sales
SERVICE_NAME := sales-api
VERSION := 0.0.1
SERVICE_IMAGE := $(BASE_IMAGE_NAME)/$(SERVICE_NAME):$(VERSION)
KIND_CLUSTER := morgan-starter-cluster
all: service
run:
go run ./app/services/sales-api | go run ./app/tooling/logfmt
# ==============================================================================
# Building containers
service:
docker build \
-f zarf/docker/dockerfile.service \
-t $(SERVICE_IMAGE) \
--build-arg BUILD_REF=$(VERSION) \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
.
# ==============================================================================
# Development
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-load:
kind load docker-image $(SERVICE_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/sales | kubectl apply -f -
kubectl wait pods --namespace=$(NAMESPACE) --selector app=$(APP) --timeout=120s --for=condition=Ready
dev-restart:
kubectl rollout restart deployment $(APP) --namespace=$(NAMESPACE)
dev-update: all dev-load dev-restart
dev-update-apply: all dev-load dev-apply
# ==============================================================================
dev-logs:
kubectl logs --namespace=$(NAMESPACE) -l app=$(APP) --all-containers=true -f --tail=100 --max-log-requests=6 | go run app/tooling/logfmt/main.go -service=$(SERVICE_NAME)
dev-logs-init:
kubectl logs --namespace=$(NAMESPACE) -l app=$(APP) -f --tail=100 -c init-migrate
dev-status:
pgcli:
pgcli postgresql://postgres:postgres@localhost:5432
dev-status:
kubectl get nodes -o wide
kubectl get svc -o wide
kubectl get pods -o wide --watch --all-namespaces
dev-describe-sales:
kubectl describe pod --namespace=$(NAMESPACE) -l app=$(APP)
# ---------------------------------------------------------------------------
dev-logs-db:
kubectl logs --namespace=$(NAMESPACE) -l app=database --all-containers=true -f --tail=100
# ==============================================================================
# Modules support
tidy:
go mod tidy
go mod vendor
# ==============================================================================
# Metrics and Tracing
metrics-view-sc:
expvarmon -ports="localhost:4000" -vars="build,requests,goroutines,errors,panics,mem:memstats.Alloc"
# ==============================================================================
# Class Stuff
admin:
go run app/tooling/sales-admin/main.go
run:
go run app/services/sales-api/main.go | go run app/tooling/logfmt/main.go
run-help:
go run app/services/sales-api/main.go --help | go run app/tooling/logfmt/main.go
test:
go test ./... -v
curl:
curl -il http://localhost:3000/v1/hack
ready:
curl -il http://localhost:3000/v1/readiness
live:
curl -il http://localhost:3000/v1/liveness
curl-auth:
curl -il -H "Authorization: Bearer ${TOKEN}" http://localhost:3000/v1/hack/auth
curl-create:
curl -il -X POST -H 'Content-Type: application/json' -d '{"name":"bill","email":"a@gmail.com","roles":["USER"],"department":"IT","password":"123","passwordConfirm":"123"}' http://localhost:3000/v1/users
load:
hey -m GET -c 100 -n 100000 "http://localhost:3000/hack"
# ==============================================================================
# CLASS NOTES
#
# 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
#
.PHONY: list run dev-up dev-down