-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
302 lines (253 loc) · 8.96 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# https://taskfile.dev
#
# task --version
# Task version: v3.37.1
#
version: '3'
silent: true
vars:
GO_MODULE: github.com/pershin-daniil/ninja-chat-bank
GO_FILES:
sh: find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./internal/store/*" -not -path "*.gen.go" | tr "\n" " "
GOLANGCI_LINT_VERSION: v1.58.1
GOLANGCI_LINT_CACHE:
sh: echo "$HOME/.cache"
TOOLS_DIR:
sh: echo "`pwd`/bin/tools"
DEV_TOOLS: |
entgo.io/ent/cmd/[email protected]
github.com/daixiang0/[email protected]
github.com/deepmap/oapi-codegen/v2/cmd/[email protected]
github.com/kazhuravlev/options-gen/cmd/[email protected]
github.com/moznion/gonstructor/cmd/[email protected]
github.com/onsi/ginkgo/v2/[email protected]
github.com/quasilyte/go-ruleguard/cmd/[email protected]
golang.org/x/tools/cmd/[email protected]
go.uber.org/mock/[email protected]
mvdan.cc/[email protected]
TYPES: |
EventID
ChatID
FailedJobID
JobID
MessageID
ProblemID
RequestID
UserID
TYPES_PKG: types
TYPES_DST: ./internal/types/types.gen.go
DOCKER_COMPOSE_PATHS: |
./deploy/local/docker-compose.yml
./deploy/local/docker-compose.sentry.yml
./deploy/local/docker-compose.swagger-ui.yml
DOCKER_COMPOSE_CMD: docker compose -f {{ .DOCKER_COMPOSE_PATHS | trim | splitLines | join " -f " }}
ENT_SCHEMA: ./internal/store/schema
ENT_TEMPLATES: ./internal/store/templates
ENT_FEATURES: |
sql/execquery
sql/upsert
KEYCLOAK_REALM_PATH: ./deploy/local/bank-realm.json
CLIENT_V1_PKG: clientv1
CLIENT_V1_SRC: ./api/client.v1.swagger.yml
CLIENT_V1_DST: ./internal/server-client/v1/server.gen.go
CLIENT_EVENTS_PKG: clientevents
CLIENT_EVENTS_SRC: ./api/client.events.swagger.yml
CLIENT_EVENTS_DST: ./internal/server-client/events/events.gen.go
MANAGER_V1_PKG: managerv1
MANAGER_V1_SRC: ./api/manager.v1.swagger.yml
MANAGER_V1_DST: ./internal/server-manager/v1/server.gen.go
MANAGER_EVENTS_PKG: managerevents
MANAGER_EVENTS_SRC: ./api/manager.events.swagger.yml
MANAGER_EVENTS_DST: ./internal/server-manager/events/events.gen.go
### E2E tests ###
E2E_CLIENT_V1_DST: ./tests/e2e/api/client/v1/client.gen.go
E2E_CLIENT_V1_PKG: apiclientv1
E2E_CLIENT_EVENTS_DST: ./tests/e2e/api/client/events/events.gen.go
E2E_CLIENT_EVENTS_PKG: apiclientevents
E2E_MANAGER_V1_DST: ./tests/e2e/api/manager/v1/client.gen.go
E2E_MANAGER_V1_PKG: apimanagerv1
E2E_MANAGER_EVENTS_DST: ./tests/e2e/api/manager/events/events.gen.go
E2E_MANAGER_EVENTS_PKG: apimanagerevents
###
tasks:
default:
cmds:
- task: tidy
- task: fmt
- task: lint
- task: tests
- task: build
tidy:
- echo "- Tidy"
- go mod tidy
- task: vendor
vendor:
- echo "- Vendor"
- go mod vendor
fmt:
- echo "- Format"
- |
export PATH="${PATH}:{{.TOOLS_DIR}}"
gofumpt -w {{.GO_FILES}}
gci write {{.GO_FILES}} --custom-order -s standard -s default -s "prefix({{.GO_MODULE}})" 2> /dev/null
lint:
cmds:
- echo "- Lint"
- mkdir -p {{.GOLANGCI_LINT_CACHE}}
- task: lint:cmd
vars: { CLI_ARGS: "run -v --fix --timeout=5m ./..." }
lint:cmd:
cmds:
- |
docker run --rm \
-v "$(pwd):/app" -w /app \
-v "{{.GOLANGCI_LINT_CACHE}}:/root/.cache" \
golangci/golangci-lint:{{.GOLANGCI_LINT_VERSION}} \
golangci-lint {{.CLI_ARGS}}
tests:
cmds:
- echo "- Tests"
- go test -race ./...
tests:integration:
env:
TEST_LOG_LEVEL: info
TEST_KEYCLOAK_REALM: Bank
TEST_KEYCLOAK_CLIENT_ID: integration-testing
TEST_KEYCLOAK_CLIENT_SECRET: biq7WcbKHgVaalqZDlhqINEi1yGK6aOw
TEST_KEYCLOAK_TEST_USER: integration_testing
TEST_KEYCLOAK_TEST_PASSWORD: integration_testing
PSQL_PASSWORD: chat-service
PSQL_USER: chat-service
TEST_PSQL_DEBUG: true
cmds:
- echo "- Integration tests"
- go test -tags integration -count 1 -race ./...
tests:e2e:
env:
E2E_CLIENT_V1_API_ENDPOINT: http://localhost:8080/v1
E2E_CLIENT_WS_ENDPOINT: ws://localhost:8080/ws
E2E_CLIENT_WS_SEC_PROTOCOL: chat-service-protocol
E2E_CLIENT_WS_ORIGIN: http://localhost:3000 # Emulate client UI.
E2E_KEYCLOAK_BASE_PATH: http://localhost:3010
E2E_KEYCLOAK_REALM: Bank
E2E_KEYCLOAK_CLIENT_ID: e2e-testing
E2E_KEYCLOAK_CLIENT_SECRET: hD3CVXnQ1k3TTUmUA5eHeARIfTQFxM2U
E2E_KEYCLOAK_CLIENT_DEBUG: false
E2E_KEYCLOAK_CLIENTS: e2e_client_0,e2e_client_1,e2e_client_2
dir: "{{.TOOLS_DIR}}"
cmds:
- echo "- End-to-end tests..."
# NOTE: It's important to run tests serial (without `-p` flag) – for correct `clientsPool` sharing.
- ./ginkgo --fail-fast --timeout=1m --tags e2e {{.CLI_ARGS}} ../../tests/e2e
build:
cmds:
- echo "- Build"
- go build ./cmd/chat-service
dev-tools:install:
dir: "{{.TOOLS_DIR}}"
cmds:
- echo "- Install dev tools"
- |
export GOBIN="{{.TOOLS_DIR}}"
{{range $i, $tool := .DEV_TOOLS | trim | splitLines -}}
go install {{$tool}}
{{end}}
- ls -l "{{.TOOLS_DIR}}"
generate:
- echo "- Run go generate..."
- export PATH="${PATH}:{{.TOOLS_DIR}}" && go generate ./...
- task: gen:types
- task: ent:gen
- task: gen:api
- task: gen:e2e
gen:types:
cmds:
- echo "- Generate types..."
- go run ./cmd/gen-types {{.TYPES_PKG}} {{ .TYPES | trim | splitLines | join "," }} {{.TYPES_DST}}
ent:new:
dir: "{{.TOOLS_DIR}}"
cmds:
- ./ent new --target {{.ENT_SCHEMA}} {{$.CLI_ARGS}}
- task: tidy
ent:gen:
dir: "{{.TOOLS_DIR}}"
cmds:
- ./ent generate --template ../../{{.ENT_TEMPLATES}} --feature {{ .ENT_FEATURES | trim | splitLines | join "," }} ../../{{.ENT_SCHEMA}}
- task: tidy
gen:api:
cmds:
- task: gen:client
- task: gen:events
- task: gen:manager
- task: tidy
gen:client:
internal: true
dir: "{{.TOOLS_DIR}}"
cmds:
- echo "Generate client server..."
- ./oapi-codegen -old-config-style -generate skip-prune,types,server,spec -package {{.CLIENT_V1_PKG }} ../../{{.CLIENT_V1_SRC}} > ../../{{.CLIENT_V1_DST}}
gen:events:
internal: true
dir: "{{.TOOLS_DIR}}"
cmds:
- echo "Generate events..."
- ./oapi-codegen --old-config-style -generate skip-prune,types,spec -package {{.CLIENT_EVENTS_PKG}} ../../{{.CLIENT_EVENTS_SRC}} > ../../{{.CLIENT_EVENTS_DST}}
- ./oapi-codegen --old-config-style -generate skip-prune,types,spec -package {{.MANAGER_EVENTS_PKG}} ../../{{.MANAGER_EVENTS_SRC}} > ../../{{.MANAGER_EVENTS_DST}}
gen:manager:
internal: true
dir: "{{.TOOLS_DIR}}"
cmds:
- echo "Generate manager server..."
- ./oapi-codegen -old-config-style -generate skip-prune,types,server,spec -package {{.MANAGER_V1_PKG }} ../../{{.MANAGER_V1_SRC}} > ../../{{.MANAGER_V1_DST}}
gen:e2e:
dir: "{{.TOOLS_DIR}}"
cmds:
- echo "[E2E] Generate client API..."
- ./oapi-codegen --old-config-style -generate types,client -package {{.E2E_CLIENT_V1_PKG}} ../../{{.CLIENT_V1_SRC}} > ../../{{.E2E_CLIENT_V1_DST}}
- echo "[E2E] Generate client events..."
- ./oapi-codegen --old-config-style -generate skip-prune,types -package {{.E2E_CLIENT_EVENTS_PKG}} ../../{{.CLIENT_EVENTS_SRC}} > ../../{{.E2E_CLIENT_EVENTS_DST}}
- echo "[E2E] Generate manager API..."
- ./oapi-codegen --old-config-style -generate types,client -package {{.E2E_MANAGER_V1_PKG}} ../../{{.MANAGER_V1_SRC}} > ../../{{.E2E_MANAGER_V1_DST}}
- echo "[E2E] Generate client events..."
- ./oapi-codegen --old-config-style -generate skip-prune,types -package {{.E2E_MANAGER_EVENTS_PKG}} ../../{{.MANAGER_EVENTS_SRC}} > ../../{{.E2E_MANAGER_EVENTS_DST}}
- task: tidy
deps:
cmds:
- echo "- Run deps containers"
- "{{.DOCKER_COMPOSE_CMD}} rm -sfv keycloak" # To prevent using old config or config from other project.
- "{{.DOCKER_COMPOSE_CMD}} up -d {{.CLI_ARGS}}"
deps:cmd:
cmds:
- "{{.DOCKER_COMPOSE_CMD}} {{.CLI_ARGS}}"
deps:status:
cmds:
- "{{.DOCKER_COMPOSE_CMD}} ps"
deps:logs:
cmds:
- "{{.DOCKER_COMPOSE_CMD}} logs -f {{.CLI_ARGS}}"
deps:stop:
cmds:
- echo "- Stop deps containers"
- "{{.DOCKER_COMPOSE_CMD}} stop"
deps:reset-psql:
cmds:
- task: deps:reset
vars:
SERVICE: postgres
deps:reset-sentry:
cmds:
- task: deps:reset
vars:
SERVICE: sentry sentry-worker cron redis
deps:reset:
internal: true
cmds:
- "{{.DOCKER_COMPOSE_CMD}} rm -fsv {{.SERVICE}}"
- "{{.DOCKER_COMPOSE_CMD}} up -d {{.SERVICE}}"
kc:export:
cmds:
# https://www.keycloak.org/server/importExport
- echo "Dump Keycloak Bank realm..."
- docker exec -it keycloak /opt/keycloak/bin/kc.sh export --realm Bank --users realm_file --file /tmp/realm.json
- docker cp keycloak:/tmp/realm.json {{.KEYCLOAK_REALM_PATH}}
- echo "Exported in {{.KEYCLOAK_REALM_PATH}}"