-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTaskfile.yml
80 lines (72 loc) · 1.89 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
# https://taskfile.dev
version: "3"
vars:
PACKAGE: opsgin
PROJECT: github.com/opsgin/opsgin
BUILD_DEST: build/package
CI: '{{.CI | default ""}}'
GIT_COMMIT:
sh: git log -n 1 --format=%h
GIT_BRANCH:
sh: git rev-list --tags --max-count=1 | xargs git describe --tags
TIME:
sh: date +%s
VERSION: '{{if ne .CI ""}}{{.GIT_BRANCH}}-{{.GIT_COMMIT}}{{else}}{{.TIME}}{{end}}'
GOOS: '{{if ne .CI ""}}linux{{else}}{{.GOOS}}{{end}}'
tasks:
default:
deps: [build]
cmds:
- "{{.BUILD_DEST}}/usr/local/sbin/{{.PACKAGE}} {{.args}}"
build:
desc: Build cmd {{.PACKAGE}}
env:
GOOS: "{{.GOOS}}"
GOARCH: amd64
CGO_ENABLED: "0"
GO111MODULE: "on"
deps:
- task: cleanup-bin
cmds:
- cmd: >
go build -o {{.BUILD_DEST}}/usr/local/sbin/{{.PACKAGE}}
-ldflags "
-X {{.PROJECT}}/cmd.version={{.VERSION}}
" {{.PROJECT}}
sources:
- ./**/*.yaml
- ./**/*.go
docker:
desc: Build docker image with cmd {{.PACKAGE}}
deps:
- task: build
vars: { GOOS: "{{.GOOS}}" }
cmds:
- task: docker-base
vars: { name: server, image: opsgin/opsgin }
docker-base:
deps:
- task: cleanup-docker
vars: { image: "{{.image}}" }
cmds:
- cmd: >
docker build --rm
-f docker/Dockerfile.linux.amd64
-t {{.image}} .
- cmd: >
docker tag {{.image}} {{.image}}:{{.VERSION}}
- cmd: >
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
- cmd: >
docker push {{.image}}
- cmd: >
docker push {{.image}}:{{.VERSION}}
cleanup-bin:
cmds:
- cmd: rm -rf {{.BUILD_DEST}}/usr/local/sbin/{{.PACKAGE}}
cleanup-docker:
cmds:
- cmd: docker rmi -f {{.image}}
ignore_error: true
- cmd: docker rmi -f {{.image}}:{{.VERSION}}
ignore_error: true