forked from megakoresh/semaphore
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Taskfile.yml
364 lines (320 loc) · 11.1 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# Semaphore Tasks
# These tasks should be used to build and develop Semaphore
#
# Tasks without a `desc:` field are intended mainly to be called
# internally by other tasks and therefore are not listed when running `task` or `task -l`
version: '2'
vars:
docker_namespace: ansiblesemaphore
docker_image: semaphore
tasks:
all:
desc: Install, Compile, Test and Build Semaphore for local architecture
cmds:
- task: deps
- task: compile
- task: test
- task: build:local
deps:
desc: Install all dependencies (except dredd requirements)
cmds:
- task: deps:tools
- task: deps:be
# - task: deps:fe
- task: deps:fe2
deps:be:
desc: Vendor application dependencies
cmds:
- go mod vendor
deps:fe:
desc: Installs npm requirements for front end from package.json
dir: web
cmds:
- npm install
- npm audit fix
deps:fe2:
desc: Installs npm requirements for front end from package.json
dir: web2
cmds:
- npm install
- npm audit fix
deps:integration:
desc: Installs requirements for integration testing with dredd
dir: web
cmds:
- npm install [email protected]
- npm audit fix
deps:tools:
desc: Installs tools needed
dir: web
vars:
GORELEASER_VERSION: "0.159.0"
GOLINTER_VERSION: "1.31.0"
cmds:
- go install github.com/cespare/reflex
- go install github.com/gobuffalo/packr/...
- go install github.com/haya14busa/goverage
- go install github.com/snikch/goodman/cmd/goodman
- go install github.com/go-swagger/go-swagger/cmd/swagger
- '{{ if ne OS "windows" }} sh -c "curl -L https://github.com/goreleaser/goreleaser/releases/download/v{{ .GORELEASER_VERSION }}/goreleaser_$(uname -s)_$(uname -m).tar.gz | tar -xz -C $(go env GOPATH)/bin goreleaser"{{ else }} {{ end }}'
- '{{ if ne OS "windows" }} chmod +x $(go env GOPATH)/bin/goreleaser{{ else }} {{ end }}'
- '{{ if eq OS "windows" }} echo "NOTICE: You must download goreleaser manually to build this application https://github.com/goreleaser/goreleaser/releases "{{ else }}:{{ end }}'
- '{{ if ne OS "windows" }} sh -c "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v{{ .GOLINTER_VERSION }}"{{ else }}{{ end }}'
- '{{ if eq OS "windows" }} echo "NOTICE: You need to install golangci-lint manually to build this application https://github.com/golangci/golangci-lint#install"{{ else }}{{ end }}'
compile:
desc: Generates compiled frontend and backend resources (must be in this order)
cmds:
# - task: compile:fe
- task: compile:fe2
- task: compile:be
compile:fe:
desc: Runs less, pug and node
dir: web
sources:
- resources/css/semaphore.less
- resources/html/*.pug
- resources/html/**/*.pug
generates:
- public/css/semaphore.css
- public/html/*.html
- public/html/**/*.html
- bundle.json
cmds:
- '{{ if eq OS "windows" }} .\\node_modules\\.bin\\lessc.cmd {{ else }} ./node_modules/.bin/lessc {{ end }} resources/less/semaphore.less > public/css/semaphore.css'
- '{{ if eq OS "windows" }} .\\node_modules\\.bin\\pug.cmd --pretty {{ else }} ./node_modules/.bin/pug {{ end }} resources/pug --out public/html'
- '{{ if eq OS "windows" }} xcopy node_modules\\font-awesome\\fonts public\\fonts /y {{ else }} cp node_modules/font-awesome/fonts/* public/fonts {{ end }}'
- node bundler.js
compile:fe2:
desc: Build vue.js project
dir: web2
sources:
- src/*.*
- src/**/*.*
- public/index.html
- public/favicon.ico
- package.json
- package-lock.json
- babel.config.js
- vue.config.js
generates:
- dist/css/*.css
- dist/js/*.js
- dist/index.html
- dist/favicon.ico
cmds:
- npm run build
compile:be:
desc: Runs Packr for static assets
sources:
- web2/dist/*
- web/public/*
- db/migrations/*
generates:
- db/db-packr.go
- api/api-packr.go
cmds:
- mkdir -p web2/dist
- go run util/version_gen/generator.go {{ if .TAG }}{{ .TAG }}{{ else }}{{ if .SEMAPHORE_VERSION }}{{ .SEMAPHORE_VERSION }}{{ else }}{{ .BRANCH }}-{{ .SHA }}-{{ .TIMESTAMP }}{{ if .DIRTY }}-dirty{{ end }}{{ end }}{{end}}
- packr
vars:
TAG:
sh: git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null | sed -n 's/^\([^^~]\{1,\}\)\(\^0\)\{0,1\}$/\1/p'
BRANCH:
sh: git rev-parse --abbrev-ref HEAD
DIRTY:
# We must exclude the package-lock file as npm install can change it!
sh: git diff --exit-code --stat -- . ':(exclude)web/package-lock.json' ':(exclude)web/package.json' || true
SHA:
sh: git log --pretty=format:'%h' -n 1
TIMESTAMP:
sh: date +%s
compile:api:hooks:
dir: ./.dredd/hooks
cmds:
- go build -o ../compiled_hooks
watch:
desc: Watch fe and be file changes and rebuild
dir: web/resources
cmds:
# - task: watch:fe
- task: watch:be
watch:be:
cmds:
- reflex -r '\.go$' -R '^.idea/' -R '^web/node_modules/' -s -d none -- sh -c 'go build -i -o /tmp/semaphore_bin cli/main.go && /tmp/semaphore_bin -config $(pwd)/config.json'
watch:fe:
dir: web
cmds:
- ./node_modules/.bin/nodemon -w js -i bundle.js -e js bundler.js &
- ./node_modules/.bin/nodemon -w css -e less --exec "lessc resources/less/semaphore.less > public/css/semaphore.css" &
- ./node_modules/.bin/pug -w -P --doctype html resources/pug --out public/html &
build:
desc: Build a full set of release binaries and packages
cmds:
- task: release
build:local:
desc: Build a binary for the current architecture
dir: cli
cmds:
- go build -o ../bin/semaphore{{ if eq OS "windows" }}.exe{{ end }}
release:
desc: creates a release without performing validations or publishing artifacts
cmds:
- goreleaser --snapshot --rm-dist
release:prod:
cmds:
- goreleaser
lint:
cmds:
- task: lint:be
lint:be:
# --errors
cmds:
- golangci-lint run --skip-files "\w*(-packr.go)" --disable goconst --timeout 240s ./...
test:
cmds:
- task: test:be
test:be:
desc: Run go code tests
cmds:
- go vet ./...
- swagger validate ./api-docs.yml
# 2> /dev/null makes goverage less noisy about pattern matching
# if no tests exist but will still print failing test results
- goverage -v -coverprofile=coverage.out ./... 2> /dev/null
test:api:
desc: test the api with dredd
cmds:
- ./web/node_modules/.bin/dredd --config .dredd/dredd.yml
ci:artifacts:
cmds:
- rsync -a bin/ $CIRCLE_ARTIFACTS/
# docker(-compose) commands
dc:dev:
desc: build and start a development stack using docker-compose
cmds:
- task: docker
vars:
context: dev
args: build semaphore_dev
compose: true
- task: dc:up
vars:
context: dev
# convenience function to build and start a production like stack
dc:prod:
desc: build and start a production like stack using docker-compose
cmds:
- task: docker
vars:
context: prod
args: build semaphore
compose: true
- task: dc:up
vars:
context: prod
dc:up:
desc: start a docker-compose instance, requires context
cmds:
- task: docker
vars:
compose: true
args: up --abort-on-container-exit
context: "{{ .context }}"
dc:build:
desc: build a set of docker-compose containers, requires context
cmds:
- task: docker
vars:
compose: true
args: build
context: "{{ .context }}"
dc:down:
desc: down a docker-compose instance, requires context
cmds:
- task: docker
vars:
compose: true
args: down
context: "{{ .context }}"
dc:stop:
desc: stop a docker-compose instance, requires context
cmds:
- task: docker
vars:
compose: true
args: stop
context: "{{ .context }}"
dc:build:dredd:
desc: build a dredd container to the local testing with docker-compose stack
cmds:
- task: docker
vars:
context: dev
compose: true
prefix: -dredd
args: build
dc:up:dredd:
desc: build a dredd container to the local testing with docker-compose stack
cmds:
- task: docker
vars:
context: dev
compose: true
prefix: -dredd
args: up
docker:build:
desc: Build an image for Semaphore, requires context
vars:
tag: "{{ if .tag }}{{ .tag }}{{ else }}latest{{ end }}"
cmds:
- task: docker
vars:
context: "{{ .context }}"
action: build
tag: "{{ .tag }}"
args: -t "{{ .docker_namespace }}/{{ .docker_image }}:{{ .tag }}" .
deps:docker:
desc: Install docker testing dependencies. These must be installed explicitly and are not included in the general deps task.
status:
- test -f /usr/local/bin/goss
- test -f /usr/local/bin/dgoss
- test -f /usr/local/bin/hadolint
cmds:
- sudo curl -L https://github.com/aelsabbahy/goss/releases/download/v0.3.5/goss-linux-amd64 -o /usr/local/bin/goss
- sudo chmod +rx /usr/local/bin/goss
- sudo curl -L https://raw.githubusercontent.com/aelsabbahy/goss/v0.3.5/extras/dgoss/dgoss -o /usr/local/bin/dgoss
- sudo chmod +rx /usr/local/bin/dgoss
- sudo curl -L https://github.com/hadolint/hadolint/releases/download/v1.5.0/hadolint-Linux-x86_64 -o /usr/local/bin/hadolint
- sudo chmod +rx /usr/local/bin/hadolint
docker:test:
desc: Test docker containers by building them, running tests and deleting
deps: ['deps:docker']
cmds:
- task: docker:lint
vars:
context: "{{ .context }}"
- task: docker:build
vars:
tag: "{{ .context }}-test"
- task: docker:goss
- docker rmi "{{ .docker_namespace }}/{{ .docker_image }}:{{ .context }}-test"
docker:goss:
dir: "deployment/docker/{{ .context}}"
deps: ['deps:docker']
cmds:
- GOSS_FILES_STRATEGY='cp' dgoss run -it "{{ .docker_namespace }}/{{ .docker_image }}:{{ .context }}-test"
docker:lint:
desc: hadolint a dockerfile. Ignores version pinning warning
dir: "deployment/docker/{{ .context}}"
cmds:
- hadolint Dockerfile --ignore DL3018
docker:push:
desc: push a docker image to a repo. Defaults to the official docker hub
cmds:
- docker push {{ .docker_namespace }}/{{ .docker_image }}:{{ .tag }}
# templated command to reduce code duplication
docker:
vars:
docker_root: deployment/docker/
cmds:
- docker{{ if .compose }}-compose{{ end }} {{ if .action }}{{ .action }}{{ end }} -f {{ .docker_root }}{{ .context }}/{{ if .compose }}docker-compose{{ if .prefix }}{{ .prefix }}{{ end }}.yml{{ else }}Dockerfile{{ if .prefix }}{{ .prefix }}{{ end }}{{ end }} {{if .args }}{{ .args }}{{ end }}