2018-03-07 23:09:25 +01:00
# 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`
2018-03-10 23:34:18 +01:00
version : '2'
2018-04-04 22:51:37 +02:00
vars :
docker_namespace : ansiblesemaphore
docker_image : semaphore
2020-02-09 13:25:06 +01:00
2018-03-10 23:34:18 +01:00
tasks :
all :
desc : Install, Compile, Test and Build Semaphore for local architecture
cmds :
2018-03-12 13:27:13 +01:00
- task : deps
- task : compile
- task : test
- task : build:local
2018-03-10 23:34:18 +01:00
deps :
2018-04-11 20:05:38 +02:00
desc : Install all dependencies (except dredd requirements)
2018-03-10 23:34:18 +01:00
cmds :
2018-03-11 15:22:50 +01:00
- task : deps:tools
2018-03-10 23:34:18 +01:00
- task : deps:be
2020-11-05 09:59:14 +01:00
- task : deps:fe2
2018-03-10 23:34:18 +01:00
deps:be :
2018-03-11 15:22:50 +01:00
desc : Vendor application dependencies
2018-03-10 23:34:18 +01:00
cmds :
2020-02-09 13:25:06 +01:00
- go mod vendor
2018-03-10 23:34:18 +01:00
2020-11-05 09:59:14 +01:00
deps:fe2 :
desc : Installs npm requirements for front end from package.json
dir : web2
cmds :
- npm install
- npm audit fix
2018-04-11 20:05:38 +02:00
deps:integration :
desc : Installs requirements for integration testing with dredd
2021-05-15 14:59:06 +02:00
dir : web2
2018-04-11 20:05:38 +02:00
cmds :
2020-10-02 23:41:45 +02:00
- npm install dredd@13.1.2
- npm audit fix
2020-09-30 12:22:32 +02:00
2018-03-11 15:22:50 +01:00
deps:tools :
desc : Installs tools needed
2021-05-15 14:59:06 +02:00
dir : web2
2018-03-20 23:40:54 +01:00
vars :
2021-06-25 10:53:50 +02:00
GORELEASER_VERSION : "0.159.0"
2020-09-30 13:15:13 +02:00
GOLINTER_VERSION : "1.31.0"
2020-02-09 13:25:06 +01:00
cmds :
2021-08-26 11:22:52 +02:00
- go install github.com/gobuffalo/packr/...@v1.10.4
- go install github.com/haya14busa/goverage@latest
- go install github.com/snikch/goodman/cmd/goodman@latest
- go install github.com/go-swagger/go-swagger/cmd/swagger@latest
2020-02-09 17:10:31 +01:00
- '{{ 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 }}'
2020-02-09 15:42:55 +01:00
- '{{ if ne OS "windows" }} chmod +x $(go env GOPATH)/bin/goreleaser{{ else }} {{ end }}'
2018-03-20 23:40:54 +01:00
- '{{ if eq OS "windows" }} echo "NOTICE: You must download goreleaser manually to build this application https://github.com/goreleaser/goreleaser/releases "{{ else }}:{{ end }}'
2020-02-09 17:10:31 +01:00
- '{{ 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 }}'
2020-02-09 13:25:06 +01:00
- '{{ 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 }}'
2018-03-27 22:12:47 +02:00
2018-03-10 23:34:18 +01:00
compile :
desc : Generates compiled frontend and backend resources (must be in this order)
cmds :
2020-11-05 09:59:14 +01:00
- task : compile:fe2
2018-03-10 23:34:18 +01:00
- task : compile:be
2020-11-05 09:59:14 +01:00
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
2018-03-10 23:34:18 +01:00
compile:be :
desc : Runs Packr for static assets
sources :
2020-11-05 09:59:14 +01:00
- web2/dist/*
2018-03-10 23:34:18 +01:00
- db/migrations/*
generates :
- db/db-packr.go
- api/api-packr.go
cmds :
2020-11-23 21:57:03 +01:00
- mkdir -p web2/dist
2018-03-08 00:42:11 +01:00
- 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}}
2020-09-30 13:40:29 +02:00
- packr
2018-03-08 00:42:11 +01:00
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 :
2018-04-04 22:51:37 +02:00
# We must exclude the package-lock file as npm install can change it!
2021-05-15 14:59:06 +02:00
sh : git diff --exit-code --stat -- . ':(exclude)web2/package-lock.json' ':(exclude)web2/package.json' || true
2018-03-08 00:42:11 +01:00
SHA :
sh : git log --pretty=format:'%h' -n 1
TIMESTAMP :
sh : date +%s
2018-03-10 23:34:18 +01:00
2018-04-11 20:05:38 +02:00
compile:api:hooks :
dir : ./.dredd/hooks
cmds :
2021-10-26 18:14:08 +02:00
- go build -o ../compiled_hooks{{ if eq OS "windows" }}.exe{{ end }}
2018-04-11 20:05:38 +02:00
2018-03-10 23:34:18 +01:00
build :
2018-03-13 21:57:55 +01:00
desc : Build a full set of release binaries and packages
2018-03-10 23:34:18 +01:00
cmds :
2018-03-14 20:26:52 +01:00
- task : release
2018-03-10 23:34:18 +01:00
build:local :
desc : Build a binary for the current architecture
dir : cli
cmds :
2018-05-16 13:41:52 +02:00
- go build -o ../bin/semaphore{{ if eq OS "windows" }}.exe{{ end }}
2018-03-10 23:34:18 +01:00
2018-03-14 20:26:52 +01:00
release :
2018-03-13 21:57:55 +01:00
desc : creates a release without performing validations or publishing artifacts
cmds :
- goreleaser --snapshot --rm-dist
2018-03-14 20:26:52 +01:00
release:prod :
2018-03-13 21:57:55 +01:00
cmds :
- goreleaser
2018-03-27 22:12:47 +02:00
lint :
cmds :
- task : lint:be
lint:be :
# --errors
cmds :
2020-02-09 14:48:24 +01:00
- golangci-lint run --skip-files "\w*(-packr.go)" --disable goconst --timeout 240s ./...
2018-03-27 22:12:47 +02:00
2018-03-10 23:34:18 +01:00
test :
2018-04-11 20:05:38 +02:00
cmds :
- task : test:be
test:be :
2018-03-10 23:34:18 +01:00
desc : Run go code tests
cmds :
- go vet ./...
2020-02-09 13:25:06 +01:00
- swagger validate ./api-docs.yml
2018-03-11 01:52:31 +01:00
# 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
2018-03-10 23:34:18 +01:00
2018-04-11 20:05:38 +02:00
test:api :
desc : test the api with dredd
cmds :
2021-05-15 14:59:06 +02:00
- ./web2/node_modules/.bin/dredd --config .dredd/dredd.yml
2018-04-11 20:05:38 +02:00
2018-03-10 23:34:18 +01:00
ci:artifacts :
cmds :
2018-03-13 21:57:55 +01:00
- rsync -a bin/ $CIRCLE_ARTIFACTS/
2018-03-12 01:35:24 +01:00
# 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 }}"
2018-10-22 05:45:35 +02:00
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
2018-03-12 01:35:24 +01:00
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 }}"
2018-04-04 22:51:37 +02:00
args : -t "{{ .docker_namespace }}/{{ .docker_image }}:{{ .tag }}" .
2018-03-12 01:35:24 +01:00
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
2018-04-04 22:51:37 +02:00
- docker rmi "{{ .docker_namespace }}/{{ .docker_image }}:{{ .context }}-test"
2018-03-12 01:35:24 +01:00
docker:goss :
dir : "deployment/docker/{{ .context}}"
deps : [ 'deps:docker' ]
cmds :
2018-04-04 22:51:37 +02:00
- GOSS_FILES_STRATEGY='cp' dgoss run -it "{{ .docker_namespace }}/{{ .docker_image }}:{{ .context }}-test"
2018-03-12 01:35:24 +01:00
docker:lint :
desc : hadolint a dockerfile. Ignores version pinning warning
dir : "deployment/docker/{{ .context}}"
cmds :
- hadolint Dockerfile --ignore DL3018
2018-04-04 22:51:37 +02:00
docker:push :
desc : push a docker image to a repo. Defaults to the official docker hub
cmds :
- docker push {{ .docker_namespace }}/{{ .docker_image }}:{{ .tag }}
2018-03-12 01:35:24 +01:00
# templated command to reduce code duplication
docker :
vars :
docker_root : deployment/docker/
cmds :
2018-10-22 05:45:35 +02:00
- 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 }}