-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskfile.yml
More file actions
197 lines (170 loc) · 5.33 KB
/
Taskfile.yml
File metadata and controls
197 lines (170 loc) · 5.33 KB
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
version: "3"
vars:
BINARIES: ["nrtm4client", "nrtm4serve"]
WEB_APP: "nrtm4serve"
WEB_DIR: "./web"
WEB_BUILD_DIR: "{{.WEB_DIR}}/dist"
TERN_DIR: "./third_party/tern"
RELEASE_REPO: docker.io/etchells
PGDUMP_CMD: pg_dump -h localhost -U postgres
DOCKER_CMD:
sh: command -v podman || command -v docker
REVISION:
sh: git rev-parse --short HEAD
silent: true
tasks:
default:
desc: List all tasks
cmds:
- task --list-all
migrate:
desc: Brings the database schema up to the latest version
deps: [generateschema]
cmds:
- tern status --config {{.TERN_DIR}}/tern.conf --migrations {{.TERN_DIR}}
build:
desc: Builds, then tests all binaries and the web client
deps: [buildgo, testgo, buildweb, testweb]
test:
desc: Runs all front and back end tests
deps: [testgo, testweb]
install:
desc: Builds all binaries and creates a local image
deps: [test, buildunixbinary, buildweb]
cmds:
- mkdir -p ./build/docker/imageroot/nrtm4-files >/dev/null 2>&1 || true
- mkdir -p ./build/docker/imageroot/srv/www >/dev/null 2>&1 || true
- rsync -a --delete {{.WEB_BUILD_DIR}}/ ./build/docker/imageroot/srv/www
- cd ./build/docker && {{.DOCKER_CMD}} build -t {{.WEB_APP}}-dev .
release:
desc: Pushes an image to the remote repository
deps: [migrate, install]
cmds:
- "{{.DOCKER_CMD}} tag {{.WEB_APP}}-dev {{.RELEASE_REPO}}/{{.WEB_APP}}:{{.REVISION}}"
- "{{.DOCKER_CMD}} tag {{.WEB_APP}}-dev {{.RELEASE_REPO}}/{{.WEB_APP}}:latest"
- "{{.DOCKER_CMD}} push {{.RELEASE_REPO}}/{{.WEB_APP}}:{{.REVISION}}"
- "{{.DOCKER_CMD}} push {{.RELEASE_REPO}}/{{.WEB_APP}}:latest"
clean:
desc: Removes all generated files except cached web modules
deps: [cleanbinaries]
cmds:
- rm -rf {{.WEB_BUILD_DIR}}
- rm -rf ./docs/_generated
- rm -rf ./build/docker/imageroot
- '{{.DOCKER_CMD}} rmi "{{.WEB_APP}}-dev" >/dev/null 2>&1 || true'
cleanall:
desc: Removes all generated files
deps: [clean]
cmds:
- rm -rf {{.WEB_DIR}}/node_modules
#
# Development utils
#
buildgo:
desc: Builds binaries
cmd:
for:
var: BINARIES
as: app
vars:
APP: "{{.app}}"
task: buildbinary
testgo:
desc: Runs all Go tests
deps: [migratetest]
cmds:
- go test ./internal/...
buildweb:
desc: Does a production build of the web client
deps: [installweb]
cmds:
- cd {{.WEB_DIR}} && npm run build
testweb:
desc: Runs web client tests
deps: [installweb]
cmds:
- cd {{.WEB_DIR}} && npx vitest run
coverage:
desc: Prints a coverage report of the Go code in ./docs/_generated
deps: [test]
cmds:
- sh ./scripts/coverage.sh
rewinddb:
desc: Rolls the database schema back one version
cmds:
- tern migrate --destination -1 --config {{.TERN_DIR}}/tern.conf --migrations {{.TERN_DIR}} >/dev/null
- tern status --config {{.TERN_DIR}}/tern.conf --migrations {{.TERN_DIR}}
migratetest:
desc: Brings the test database schema up to the latest version
deps: [testmigrations]
cmds:
- tern migrate --config {{.TERN_DIR}}/tern.test.conf --migrations {{.TERN_DIR}} >/dev/null
- tern status --config {{.TERN_DIR}}/tern.conf --migrations {{.TERN_DIR}}
emptytestdb:
desc: Rolls the database back to the initial state
cmds:
- tern migrate --destination 1 --config {{.TERN_DIR}}/tern.test.conf --migrations {{.TERN_DIR}} >/dev/null
- tern status --config {{.TERN_DIR}}/tern.conf --migrations {{.TERN_DIR}}
webdev:
desc: Runs the web client on localhost in dev mode
deps: [installweb]
cmds:
- cd {{.WEB_DIR}} && npm run dev
#
# Internal targets
#
installweb:
internal: true
cmds:
- cd {{.WEB_DIR}} && npm install
buildbinary:
internal: true
cmds:
- cd ./cmd/{{.APP}} && go build -race -o {{.APP}} -v
sources:
- ./cmd/{{.APP}}/main.go
- ./internal/**/*.go
generates:
- ./cmd/{{.APP}}/{{.APP}}
run: when_changed
buildunixbinary:
internal: true
cmd:
for:
var: BINARIES
as: app
vars:
APP: "{{.app}}"
DEST: build/docker/imageroot/usr/local/bin
task: unixbinary
unixbinary:
internal: true
cmds:
- test -d ./{{.DEST}} || mkdir -p ./{{.DEST}}
- cd ./cmd/{{.APP}} && env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ../../{{.DEST}}/{{.APP}} -v
cleanbinaries:
internal: true
cmd:
for:
var: BINARIES
as: app
cmd: cd ./cmd/{{.app}} && rm -rf {{.app}} __debug_bin*
testmigrations:
internal: true
cmds:
- tern migrate --config {{.TERN_DIR}}/tern.test.conf --migrations {{.TERN_DIR}} >/dev/null
- tern migrate --destination -1 --config {{.TERN_DIR}}/tern.test.conf --migrations {{.TERN_DIR}} >/dev/null
migratelatest:
internal: true
cmds:
- tern migrate --config {{.TERN_DIR}}/tern.conf --migrations {{.TERN_DIR}} >/dev/null
generateschema:
internal: true
deps: [migratelatest]
cmds:
- "{{.PGDUMP_CMD}} --schema-only --no-owner --no-privileges --no-comments --no-tablespaces nrtm4 > ./deployments/docker/initdb.d/nrtm4_schema.sql"
sources:
- "{{.TERN_DIR}}/*.sql"
generates:
- ./deployments/docker/initdb.d/nrtm4_schema.sql
run: when_changed