forked from gmhafiz/go8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
264 lines (220 loc) · 6.51 KB
/
Taskfile.yml
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
version: '3'
dotenv: ['.env']
tasks:
default:
desc: Lists available commands
cmds:
- task -l
list:
desc: Lists available commands
cmds:
- task -l
migrate:create:
desc: Creates .sql migration files (Up and Down). Set name by appending with 'NAME=name_of_file'
cmds:
- goose -dir database/migrations postgres "user=$DB_USER password=$DB_PASS dbname=$DB_NAME host=$DB_HOST port=$DB_PORT sslmode=$DB_SSLMODE" create "{{.NAME}}" sql
migrate:
desc: Migrates UP the database
cmds:
- goose -dir database/migrations postgres "user=$DB_USER password=$DB_PASS dbname=$DB_NAME host=$DB_HOST port=$DB_PORT sslmode=$DB_SSLMODE" up
migrate:step:
desc: Migrates UP bt one step the database
cmds:
- goose -dir database/migrations $DB_DRIVER "user=$DB_USER password=$DB_PASS dbname=$DB_NAME host=$DB_HOST port=$DB_PORT sslmode=$DB_SSLMODE" up-by-one
migrate:rollback:
desc: Rollback the database by one step
cmds:
- goose -dir database/migrations postgres "user=$DB_USER password=$DB_PASS dbname=$DB_NAME host=$DB_HOST port=$DB_PORT sslmode=$DB_SSLMODE" down
run:
desc: Runs the app
cmds:
- task: swagger
- go run cmd/go8/main.go
silent: true
dev:
desc: Hot reload. Watch for file changes and rebuild binary.
cmds:
- air
silent: true
routes:
desc: List all registered routes.
silent: true
cmds:
- go run cmd/route/main.go
build:
desc: Creates a compiled binary and copy configuration files into ./bin
vars:
GIT_TAG:
sh: git describe --abbrev=0 --tags
GIT_COMMIT:
sh: git rev-list -1 HEAD
cmds:
- task: check
- go build -ldflags="-X main.Version={{.GIT_TAG}}-{{.GIT_COMMIT}} -s" -o go8 cmd/go8/main.go
- mkdir -p bin
- mv go8 bin/
- cp .env bin
silent: false
check:
desc: Checks integrity of program
cmds:
- task generate
- task swagger
- task fmt
- task vet
- task lint
- task vuln
- task test
silent: true
clean:
desc: Clears built files and tests
cmds:
- rm -rf ./bin/*
- rm -rf ./bin/.*
- task: test:clean:cache
tidy:
desc: Downloads dependencies and removes unused ones
cmds:
- go mod tidy
vet:
desc: Vets code
cmds:
- go vet ./...
lint:
desc: Uses golangci-lint
cmds:
- golangci-lint run
vuln:
desc: Run Go Vulnerability Check
cmds:
- govulncheck ./...
fmt:
desc: Reformat code
cmds:
- go fmt ./...
test:
desc: Test all code (unit and integration)
cmds:
- go test ./...
test:unit:
desc: Test only unit tests
cmds:
- go test -short ./...
test:integration:
desc: Test only integration tests
cmds:
- go test -run Integration ./...
test:verbose:
desc: Test all code with verbose mode
cmds:
- go test -v ./...
test:coverage:
desc: Perform test coverage
cmds:
- go test -cover ./...
test:slow:
desc: Find slow running tests
platforms: [ linux ]
cmds:
- go clean -testcache
- go test -v -json ./... | jq -r 'select(.Action == "pass" and .Test != null) | .Test + "," + (.Elapsed | tostring)' | sort -r -k2 -n -t, | head
test:e2e:
desc: Run e2e test
dir: e2e
cmds:
- task: test:e2e:down # Ensures all containers are shut down for clean data directories
- docker-compose -f e2e/docker-compose.yml up --build
silent: true
test:e2e:down:
desc: Stops e2e test and remove the containers
dir: e2e
cmds:
- docker-compose -f e2e/docker-compose.yml down -v
race:
desc: Check race condition
cmds:
- go test -race ./...
test:clean:
desc: Clear tests cache
cmds:
- go clean -testcache
generate:
desc: Runs all //go:generate commands embedded in .go files
cmds:
- go generate ./...
swagger:
desc: Generates Swagger page for API reference
cmds:
- swag init -o internal/server/docs -g cmd/go8/main.go
docker:build:
desc: Builds a Docker image a server container
cmds:
- cp .env env.prod
- docker build -t go8/server -f Dockerfile .
docker:run:
desc: Runs the app Docker image as a Docker container
cmds:
# - docker run -p 3080:3080 -e DB_DRIVER=${DB_DRIVER} -e DB_Host=${DB_HOST} -e DB_PORT=${DB_PORT} -e DB_NAME=${DB_NAME} -e DB_USER=${DB_USER} -e DB_PASS=${DB_PASS} --rm -it --name go8_container go8/server
- docker run --network=host --env-file ./.env --rm -it --name go8_container go8/server
docker-compose:start:
desc: Runs server using docker-compose
cmds:
- docker-compose -f docker-compose.yml up --build
docker-compose:stop:
desc: Stops server using docker-compose
cmds:
- docker-compose -f docker-compose.yml down
docker-compose:infra:start:
desc: Runs infrastructure using docker-compose
cmds:
- docker-compose -f docker-compose-infra.yml up --abort-on-container-exit
k8s:push:
desc: build and push
vars:
GIT_TAG:
sh: git describe --abbrev=0 --tags
GIT_COMMIT:
sh: git rev-list -1 HEAD
cmds:
- docker build . -t gmhafiz/go8:{{.GIT_TAG}}-{{.GIT_COMMIT}}
- docker push gmhafiz/go8:{{.GIT_TAG}}-{{.GIT_COMMIT}}
install:tools:
desc: Install all optional cli tools
dir: scripts
cmds:
- task: install:golangci
- task: install:swagger
- task: install:goose
- task: install:ent
- task: install:mirip
- task: install:air
- task: install:vuln
silent: true
install:golangci:
desc: Install golangci linter
cmds:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
install:swagger:
desc: Install swagger cli
cmds:
- go install github.com/swaggo/swag/cmd/swag@latest
install:mirip:
desc: Install mock generator
cmds:
- go install github.com/gmhafiz/mirip/cmd/mirip@latest
install:goose:
desc: Install golang migration tool
cmds:
- go install github.com/pressly/goose/v3/cmd/goose@latest
install:ent:
desc: Install ent database ORM tool
cmds:
- go install entgo.io/ent/cmd/ent@latest
install:air:
desc: Install a hot reloader. Watch for file changes and automatically rebuilds binary
cmds:
- go install github.com/air-verse/air@latest
install:vuln:
desc: Install Go Vulnerability Check
cmds:
- go install golang.org/x/vuln/cmd/govulncheck@latest