-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (68 loc) · 2.69 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
SERVICE_NAME=agent
NAMESPACE=k8sdeploy
GIT_COMMIT=`git rev-parse --short HEAD`
-include .env
export
.PHONY: setup
setup: ## Get linting stuffs
go install github.com/golangci/golangci-lint/cmd/golangci-lint
go install golang.org/x/tools/cmd/goimports
go install google.golang.org/protobuf/cmd/protoc-gen-go
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
.PHONY: build-push-latest
build-push-latest:
nerdctl build --platform=amd64,arm64 --tag containers.chewed-k8s.net/${NAMESPACE}/${SERVICE_NAME}:latest --build-arg VERSION=0.1 --build-arg BUILD=${GIT_COMMIT} --build-arg SERVICE_NAME=${SERVICE_NAME} -f ./k8s/Containerfile .
nerdctl push containers.chewed-k8s.net/${NAMESPACE}/${SERVICE_NAME}:latest --all-platforms
.PHONY: build-deploy-latest
build-deploy-latest: build-push-latest deploy-latest
.PHONY: build-images
build-images: ## Build the images
nerdctl build --platform=amd64,arm64 --tag containers.chewed-k8s.net/${NAMESPACE}/${SERVICE_NAME}:${GIT_COMMIT} --build-arg VERSION=0.1 --build-arg BUILD=${GIT_COMMIT} --build-arg SERVICE_NAME=${SERVICE_NAME} -f ./k8s/Containerfile .
nerdctl tag containers.chewed-k8s.net/${NAMESPACE}/${SERVICE_NAME}:${GIT_COMMIT} containers.chewed-k8s.net/${NAMESPACE}/${SERVICE_NAME}:latest
.PHONY: publish-images
publish-images:
nerdctl push containers.chewed-k8s.net/${NAMESPACE}/${SERVICE_NAME}:${GIT_COMMIT} --all-platforms
nerdctl push containers.chewed-k8s.net/${NAMESPACE}/${SERVICE_NAME}:latest --all-platforms
.PHONY: build
build: build-images
.PHONY: deploy
deploy:
kubectl set image deployment/${SERVICE_NAME} ${SERVICE_NAME}=containers.chewed-k8s.net/${NAMESPACE}/${SERVICE_NAME}:${GIT_COMMIT} --namespace=${NAMESPACE}
.PHONY: deploy-latest
deploy-latest:
kubectl set image deployment/${SERVICE_NAME} ${SERVICE_NAME}=containers.chewed-k8s.net/${NAMESPACE}/${SERVICE_NAME}:latest --namespace=${NAMESPACE}
kubectl rollout restart deployment/${SERVICE_NAME} --namespace=${NAMESPACE}
.PHONY: build-deploy
build-deploy: build publish-images deploy
.PHONY: lint-build-deploy
lint-build-deploy: lint build publish-images deploy
.PHONY: test
test: ## Test the app
go test \
-v \
-race \
-bench=./... \
-benchmem \
-timeout=120s \
-cover \
-coverprofile=./test_coverage.txt \
-bench=./... ./...
.PHONY: mocks
mocks: ## Generate the mocks
go generate ./...
.PHONY: full
full: clean build fmt lint test ## Clean, build, make sure its formatted, linted, and test it
.PHONY: lint
lint: ## Lint
golangci-lint run --config ./k8s/golangci.yml
.PHONY: fmt
fmt: ## Formatting
gofmt -w -s .
goimports -w .
go clean ./...
.PHONY: pre-commit
pre-commit: fmt lint ## Do formatting and linting
.PHONY: clean
clean: ## Clean
go clean ./...
rm -rf bin/${SERVICE_NAME}