-
Notifications
You must be signed in to change notification settings - Fork 7
/
Taskfile.yml
250 lines (218 loc) · 7.06 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
version: "3"
vars:
mode: '{{ ternary "cgo" "go" (eq OS "linux") }}'
arch: '{{ ternary "arm64" ARCH (eq ARCH "arm") }}'
buildDate:
sh: date -u +'%Y-%m-%dT%H:%M:%SZ'
version:
sh: git describe --tags
kubectlVersion: v1.29.3
kubectlLDFlags:
sh: |
buildDate="{{ .buildDate }}"
gitCommit="0000000000000000000000000000000000000000"
gitTreeState="archive"
gitVersion="{{ .kubectlVersion }}"
_strippedGitVersion="${gitVersion#[vV]}"
gitMajor="$(cut -d. -f1 <<< "$_strippedGitVersion")"
gitMinor="$(cut -d. -f2 <<< "$_strippedGitVersion")"
declare -a ldflags
function add_ldflag() {
local key=${1}
local val=${2}
ldflags+=(
"-X 'k8s.io/client-go/pkg/version.${key}=${val}'"
"-X 'k8s.io/component-base/version.${key}=${val}'"
)
}
for ldflag in buildDate gitCommit gitTreeState gitVersion gitMajor gitMinor; do
add_ldflag "${ldflag}" "${!ldflag}"
done
echo "${ldflags[*]-}"
cgoTags: "dfrunsecurity dfrunnetwork dfrunmount dfssh containers_image_openpgp osusergo exclude_graphdriver_devicemapper netgo no_devmapper static_build cni"
goTags: "dfrunsecurity dfrunnetwork dfrunmount dfssh containers_image_openpgp"
cgoDevLDFlags: "-linkmode external -extldflags=-static"
goDevLDFlags: ""
cgoReleaseLDFlags: "-linkmode external -extldflags=-static -s -w -X 'github.com/deckhouse/deckhouse-cli/cmd.Version={{ .version }}' -X github.com/werf/werf/pkg/werf.Version={{ .version }} {{ .kubectlLDFlags }}"
goReleaseLDFlags: "-s -w -X 'github.com/deckhouse/deckhouse-cli/cmd.Version={{ .version }}' -X github.com/werf/werf/pkg/werf.Version={{ .version }} {{ .kubectlLDFlags }}"
tasks:
_build:cgo:dev:
internal: true
cmds:
- go build -o "{{ .outputDir | default (printf "./build/%s-%s" .targetOS .targetArch) }}/bin/d8"
-compiler gc -ldflags="{{ .cgoDevLDFlags }}" -tags="{{ .cgoTags }}" {{ .CLI_ARGS }} main.go
env:
CGO_ENABLED: "1"
GOOS: "{{ .targetOS }}"
GOARCH: "{{ .targetArch }}"
_build:cgo:dist:
internal: true
cmds:
- go build -o "{{ .outputDir | default (printf "./dist/%s/%s-%s" .version .targetOS .targetArch) }}/bin/d8"
-compiler gc -ldflags="{{ .cgoReleaseLDFlags }}" -tags="{{ .cgoTags }}" {{ .CLI_ARGS }} main.go
env:
CGO_ENABLED: "1"
GOOS: "{{ .targetOS }}"
GOARCH: "{{ .targetArch }}"
_build:go:dev:
internal: true
cmds:
- go build -o "{{ .outputDir | default (printf "./build/%s-%s" .targetOS .targetArch) }}/bin/d8{{ if (eq .targetOS "windows") }}.exe{{ end }}"
-ldflags="{{ .goDevLDFlags }}" -tags="{{ .goTags }}" {{ .CLI_ARGS }} main.go
env:
CGO_ENABLED: "0"
GOOS: "{{ .targetOS }}"
GOARCH: "{{ .targetArch }}"
_build:go:dist:
internal: true
cmds:
- go build -o "{{ .outputDir | default (printf "./dist/%s/%s-%s" .version .targetOS .targetArch) }}/bin/d8{{ if (eq .targetOS "windows") }}.exe{{ end }}"
-ldflags="{{ .goReleaseLDFlags }}" -tags="{{ .goTags }}" {{ .CLI_ARGS }} main.go
env:
CGO_ENABLED: "0"
GOOS: "{{ .targetOS }}"
GOARCH: "{{ .targetArch }}"
_test:go:
internal: true
cmds:
- go test -tags="{{ .cgoTags }}" ./...
build:
desc: Build d8 binary for personal usage
run: once
cmds:
- task: build:dev:{{ OS }}:{{ .arch }}
vars:
outputDir: "."
build:dev:linux:amd64:
desc: Build d8 dev binary for linux/amd64
cmds:
- task: _build:cgo:dev
vars:
targetOS: "linux"
targetArch: "amd64"
outputDir: "{{ .outputDir }}"
build:dev:darwin:amd64:
desc: Build d8 dev binary for darwin/amd64
cmds:
- task: _build:go:dev
vars:
targetOS: "darwin"
targetArch: "amd64"
outputDir: "{{ .outputDir }}"
build:dev:darwin:arm64:
desc: Build d8 dev binary for darwin/arm64
cmds:
- task: _build:go:dev
vars:
targetOS: "darwin"
targetArch: "arm64"
outputDir: "{{ .outputDir }}"
build:dev:windows:amd64:
desc: Build d8 dev binary for windows/amd64
cmds:
- task: _build:go:dev
vars:
targetOS: "windows"
targetArch: "amd64"
outputDir: "{{.outputDir}}"
build:dist:all:
desc: Build all d8 release binaries in parallel
deps:
- build:dist:linux:amd64
- build:dist:darwin:amd64
- build:dist:darwin:arm64
- build:dist:windows:amd64
build:dist:linux:amd64:
desc: Build d8 release binary for linux/amd64
cmds:
- task: _build:cgo:dist
vars:
targetOS: "linux"
targetArch: "amd64"
outputDir: "{{ .outputDir }}"
build:dist:darwin:amd64:
desc: Build d8 release binary for darwin/amd64
cmds:
- task: _build:go:dist
vars:
targetOS: "darwin"
targetArch: "amd64"
outputDir: "{{ .outputDir }}"
build:dist:darwin:arm64:
desc: Build d8 release binary for darwin/arm64
cmds:
- task: _build:go:dist
vars:
targetOS: "darwin"
targetArch: "arm64"
outputDir: "{{ .outputDir }}"
build:dist:windows:amd64:
desc: Build d8 release binary for windows/amd64
cmds:
- task: _build:go:dist
vars:
targetOS: "windows"
targetArch: "amd64"
outputDir: "{{ .outputDir }}"
_package:dist:
dir: dist/{{ .version }}
cmds:
- cp ../../LICENSE ../../README.md {{ .target }}
- tar -zcf d8-{{ .version }}-{{ .target }}.tar.gz {{ .target }}
package:dist:all:
desc: Package all release assets in parallel
deps:
- package:dist:linux:amd64
- package:dist:darwin:amd64
- package:dist:darwin:arm64
- package:dist:windows:amd64
package:dist:linux:amd64:
desc: Package release asset for linux/amd64
dir: dist/{{ .version }}
cmds:
- task: _package:dist
vars:
target: "linux-amd64"
package:dist:darwin:amd64:
desc: Package release asset for darwin/amd64
dir: dist/{{ .version }}
cmds:
- task: _package:dist
vars:
target: "darwin-amd64"
package:dist:darwin:arm64:
desc: Package release asset for darwin/arm64
dir: dist/{{ .version }}
cmds:
- task: _package:dist
vars:
target: "darwin-arm64"
package:dist:windows:amd64:
desc: Package release asset for windows/amd64
dir: dist/{{ .version }}
cmds:
- task: _package:dist
vars:
target: "windows-amd64"
checksum:
desc: Calculate sha256 checksum for release assets
dir: dist/{{ .version }}
cmds:
- |
for asset in *.tar.gz; do
shasum -a 256 "${asset}" > "${asset}".sha256sum
done
build-and-package:
desc: Build and package all d8 binaries
cmds:
- task: build:dist:all
- task: package:dist:all
- task: checksum
test:
desc: Run go test for current project
cmds:
- task: _test:go
clean:
desc: Clean all binaries
cmds:
- rm -rf ./build ./dist ./d8