-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
203 lines (148 loc) · 5.54 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
default: dev
# Change these variables as necessary.
MAIN_PACKAGE_PATH := "cmd/server/main.go"
BINARY_NAME := tsdproxy
PACKAGE := github.com/almeidapaulopt/tsdproxy
BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT=$(shell git rev-parse HEAD)
GIT_TAG=$(shell if [ -z "`git status --porcelain`" ]; then git describe --exact-match --tags HEAD 2>/dev/null; fi)
GIT_TREE_STATE=$(shell if [ -z "`git status --porcelain`" ]; then echo "clean" ; else echo "dirty"; fi)
GIT_REMOTE_REPO=upstream
VERSION=$(shell if [ ! -z "${GIT_TAG}" ] ; then echo "${GIT_TAG}" | sed -e "s/^v//" ; else cat internal/core/version.txt ; fi)
GO_VERSION=$(shell go version | cut -d " " -f3)
# docker image publishing options
DOCKER_PUSH=false
IMAGE_TAG=latest
override LDFLAGS += \
-X ${PACKAGE}/internal/core.AppVersion=${VERSION} \
-X ${PACKAGE}/internal/core.BuildDate=${BUILD_DATE} \
-X ${PACKAGE}/internal/core.GitCommit=${GIT_COMMIT} \
-X ${PACKAGE}/internal/core.GitTreeState=${GIT_TREE_STATE} \
-X ${PACKAGE}/internal/core.GoVersion=${GO_VERSION}
ifneq (${GIT_TAG},)
IMAGE_TAG=${GIT_TAG}
override LDFLAGS += -X ${PACKAGE}/internal/core.GitTag=${GIT_TAG}
endif
# ==================================================================================== #
# HELPERS
# ==================================================================================== #
## help: print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
.PHONY: confirm
confirm:
@echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]
.PHONY: no-dirty
no-dirty:
git diff --exit-code
# ==================================================================================== #
# DEVELOPMENT
# ==================================================================================== #
## test: run all tests
.PHONY: test
test:
go test -v -race -buildvcs ./...
## test/cover: run all tests and display coverage
.PHONY: test/cover
test/cover:
go test -v -race -buildvcs -coverprofile=./tmp/coverage.out ./...
go tool cover -html=./tmp/coverage.out
## build: build the application
.PHONY: build
build:
@echo "GIT_TAG: ${GIT_TAG}"
go build -ldflags '$(LDFLAGS)' -o=./tmp/${BINARY_NAME} ${MAIN_PACKAGE_PATH}
## run: run the application
.PHONY: run
run: build/static build
./tmp/${BINARY_NAME}
## start: start dev server
.PHONE: start
start: dev
## dev: start dev server
.PHONY: dev
dev: docker_start server_start
## server_start: start the server
.PHONY: server_start
server_start:
# TSDPROXY_DataDir=./dev/data TSDPROXY_LOG_LEVEL=debug \
# TSDPROXY_AUTHKEYFILE=./dev/KEY_FILE \
# TSDPROXY_DASHBOARD_ENABLED=true \
# TSDPROXY_DASHBOARD_NAME=DASH1 \
# DOCKER_HOST=unix:///run/user/1000/docker.sock \
# wgo run -file=.go -file=.yaml -file=.env -file=.json -file=.toml ${MAIN_PACKAGE_PATH} -config nonefile.yaml
wgo run -file=.go -file=.env -file=.json ${MAIN_PACKAGE_PATH} -config ./dev/tsdproxy-local.yaml
## docker_start: start the docker containers
.PHONY: docker_start
docker_start:
cd dev && docker compose -f docker-compose-local.yaml up -d
## dev_docker: start the dev docker containers
.PHONY: dev_docker
dev_docker:
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f dev/docker-compose-dev.yaml up
## dev_docker_stop: stop the dev docker containers
.PHONY: dev_docker_stop
dev_docker_stop:
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose -f dev/docker-compose-dev.yaml down
## dev_image: generate docker development image
.PHONY: dev_image
dev_image:
docker build --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) -f dev/Dockerfile.dev -t devimage .
## docker_stop: stop the docker containers
.PHONY: docker_stop
docker_stop:
-cd dev && docker compose -f docker-compose-local.yaml down
## stop: stop the dev server
.PHONY: stop
stop: dev_kill docker_stop
## docker_image: Create docker image
.PHONY: docker_image
docker_image:
docker buildx build -t "tsdproxy:latest" .
## docs local server
.PHONY: docs
docs:
cd docs && hugo server --disableFastRender
## cd docs && hugo server --buildDrafts --disableFastRender
.PHONY: run_in_docker
run_in_docker:
wgo -file=.go -file=.templ -xfile=_templ.go templ generate :: go run ${MAIN_PACKAGE_PATH}
# templ generate --proxy="http://localhost:8080" --watch --cmd="echo reload" &
# wgo -file=.go -file=.templ -file=.yaml -xfile=_templ.go templ generate --notify-proxy :: go run ${MAIN_PACKAGE_PATH}
# ==================================================================================== #
# QUALITY CONTROL
# ==================================================================================== #
## tidy: format code and tidy modfile
.PHONY: tidy
tidy:
go get -u ./...
go fmt ./...
go mod tidy -v -e -x
## audit: run quality control checks
.PHONY: audit
audit:
go mod verify
golangci-lint run
go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./...
go vet ./...
deadcode ./...
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
go test -race -buildvcs -vet=off ./...
gosec -exclude-generated ./...
# ==================================================================================== #
# OPERATIONS
# ==================================================================================== #
## push: push changes to the remote Git repository
.PHONY: push
push: gen tidy audit no-dirty
git push
git push --tags
## info: print version info
.PHONY: info
info:
@echo "Version: ${VERSION}"
@echo "Git Tag: ${GIT_TAG}"
@echo "Git Commit: ${GIT_COMMIT}"
@echo "Git Tree State: ${GIT_TREE_STATE}"