-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaskfile.yaml
185 lines (154 loc) · 3.99 KB
/
Taskfile.yaml
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
---
version: "3"
dotenv:
- defaults.env
- overrides.env
interval: 500ms
vars:
SERVICE_NAME: trueauth
MIGRATIONS_DIR: migrations
STUBS_DIR: rpc
PROTO_DIR: proto
STATIK_DIR: .
DOCS_SWAGGER: docs
tasks:
statik:
desc: generates binary code from static files
cmds:
- statik -src={{.DOCS_SWAGGER}} -dest={{.STATIK_DIR}}
proto:
desc: generates go code from proto
cmds:
- rm -rf {{.STUBS_DIR}}
- mkdir -p {{.STUBS_DIR}}
- rm -f {{.DOCS_SWAGGER}}/*.swagger.json
- rm -rf "{{.STATIK_DIR}}/statik"
- |
protoc \
--proto_path={{.PROTO_DIR}} \
--go_out={{.STUBS_DIR}} \
--go_opt=paths=source_relative \
--go-grpc_out={{.STUBS_DIR}} \
--go-grpc_opt=paths=source_relative \
--grpc-gateway_out={{.STUBS_DIR}} \
--grpc-gateway_opt=paths=source_relative \
--openapiv2_out={{.DOCS_SWAGGER}} \
--openapiv2_opt=disable_service_tags=true,logtostderr=true,allow_merge=true,merge_file_name={{.SERVICE_NAME}} \
{{.PROTO_DIR}}/*.proto
- task: statik
- task: sqlc
- task: tidy
sqlc:
desc: sqlc generates fully type-safe idiomatic Go code from SQL
cmds:
- rm -f db/db/*.sql_gen.go
- sqlc generate
- task: migration-build
release:
desc: goreleaser release
cmds:
- goreleaser --snapshot --clean
dbdocs:
desc: generate docs
cmd: dbdocs build db/db.dbml
dbschema:
desc: Generate schema
cmd: dbml2sql --postgres -o db/schema.sql db/db.dbml
swag:
desc: swag converts go annotations to swagger documentation
cmds:
- swag fmt
- swag init --outputTypes go,yaml
tidy:
desc: run go mod tidy
cmds:
- rm -f ./go.sum
- go mod tidy
# - go mod vendor
test:
desc: run go test
cmds:
- go clean -testcache
- go test -v -cover -short ./...
build:
desc: builds the binary
cmds:
- task: sqlc
- task: lint
- task: migration-build
- go build -o ./dist/main main.go
lint:
desc: lint the code
cmds:
- golint ./...
run:
desc: run the code
cmds:
- go run main.go
dev:
desc: run the code
cmds:
- go run main.go
migration-new:
desc: create new migration
summary: Use task new-migration -- "create table users"
cmd: migrate create -ext sql -dir {{.MIGRATIONS_DIR}} -seq {{.CLI_ARGS}}
migration-fix:
desc: run migrations fix
cmd: |
migrate \
-source file://{{.MIGRATIONS_DIR}} \
-database {{.POSTGRES_URL}} -verbose up
migration-drop:
desc: drop everything inside database
cmd: |
migrate \
-source file://{{.MIGRATIONS_DIR}} \
-database {{.POSTGRES_URL}} -verbose drop -f
migration-up:
desc: run migrations up
cmd: |
migrate \
-source file://{{.MIGRATIONS_DIR}} \
-database {{.POSTGRES_URL}} -verbose up
migration-down:
desc: run migrations down
cmd: |
migrate \
-source file://{{.MIGRATIONS_DIR}} \
-database {{.POSTGRES_URL}} -verbose down -all
migration-build:
desc: build migration files as binary code
cmd: cd {{.MIGRATIONS_DIR}} && go-bindata -pkg migrations .
up:
desc: run containers
preconditions:
- test -f docker-compose.yaml
cmd: docker compose up -d
down:
desc: stop containers
preconditions:
- test -f docker-compose.yaml
cmd: docker compose down
restart:
desc: run containers
cmds:
- task: down
- task: up
pull:
desc: pull latest images
cmd: docker compose pull
docker-remove:
desc: containers remove
cmd: docker compose rm -f
docker-build:
desc: build docker image
cmd: docker compose build
docker-image:
desc: build docker image
cmd: build --pull --rm -f "Dockerfile" -t {{.SERVICE_NAME}}:latest "."
mock:
desc: Mock for tests
cmds:
- mockgen -package mockdb -destination \
db/mock/store.go github.com/sirjager/{{.SERVICE_NAME}}/db/db Store