-
Notifications
You must be signed in to change notification settings - Fork 25
/
Taskfile.yml
357 lines (354 loc) · 14.4 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
# SPDX-FileCopyrightText: Copyright 2024 Prasad Tengse
# SPDX-License-Identifier: MIT
# yaml-language-server: $schema=https://taskfile.dev/schema.json
version: "3"
vars:
PROTONWIRE_IMAGE: "ghcr.io/tprasadtp/protonwire"
PROTONVPN_IMAGE: "ghcr.io/tprasadtp/protonvpn"
SHELLCHECK_VERSION: '{{ default .SHELLCHECK_VERSION "v0.10.0"}}'
tasks:
# -----------------------------------------------------------------
# Default Task. Shows List of available tasks.
#
# This intentionally lacks a desc field to hide it from help output.
# -----------------------------------------------------------------
default:
cmds:
- cmd: task --list
silent: true
# -----------------------------------------------------------------
# Creates a directory if not present.
# -----------------------------------------------------------------
internal:mkdir:
internal: true
label: mkdir
requires:
vars:
- DIRECTORY
status:
- >-
{{- if .DIRECTORY }}
test -d {{ .DIRECTORY|quote }}
{{- else }}
exit 0
{{- end }}
cmds:
# Do not use long form flag --parents as it is not supported on macOS.
- cmd: mkdir -p {{.DIRECTORY|quote}}
platforms:
- linux
- darwin
- freebsd
- netbsd
- dragonfly
- openbsd
- cmd: powershell.exe -NonInteractive -NoProfile -NoLogo -Command 'New-Item -ItemType Directory -Force -Path "{{.DIRECTORY}}"'
platforms:
- windows
# -----------------------------------------------------------------
# Removes files with PATTERN in the given DIRECTORY.
# -----------------------------------------------------------------
internal:rm-file-glob:
internal: true
label: "rm"
requires:
vars:
- DIRECTORY
- PATTERN
status:
- >-
{{- if .DIRECTORY }}
! test -d {{ .DIRECTORY|quote }}
{{- else }}
exit 0
{{- end }}
cmds:
# Do not use long form flag --parents as it is not supported on macOS.
- cmd: rm -f {{ joinPath (.DIRECTORY | quote) .PATTERN }}
platforms:
- linux
- darwin
- freebsd
- netbsd
- dragonfly
- openbsd
- cmd: powershell.exe -NonInteractive -NoProfile -NoLogo -Command 'Remove-Item -Force -Path "{{ joinPath .DIRECTORY .PATTERN }}"'
platforms:
- windows
# -----------------------------------------------------------------
# Removes an empty DIRECTORY.
# -----------------------------------------------------------------
internal:rmdir:
internal: true
label: "rmdir"
requires:
vars:
- DIRECTORY
status:
- >-
{{- if .DIRECTORY }}
! test -d {{ .DIRECTORY|quote }}
{{- else }}
exit 0
{{- end }}
cmds:
- cmd: rmdir {{ .DIRECTORY | quote }}
platforms:
- linux
- darwin
- freebsd
- netbsd
- dragonfly
- openbsd
- cmd: powershell.exe -NonInteractive -NoProfile -NoLogo -Command 'Remove-Item -Force -Path "{{ .DIRECTORY }}"'
platforms:
- windows
# -----------------------------------------------------------------
# Run shellcheck
# -----------------------------------------------------------------
shellcheck:
desc: "Run shellcheck on protonwire script"
cmds:
- cmd: >-
docker run
--rm
--userns=host
--workdir=/app/
--network=none
--mount type=bind,src={{.ROOT_DIR}}/protonwire,dst=/protonwire,readonly
koalaman/shellcheck:{{.SHELLCHECK_VERSION}}
--color=always
--extended-analysis=true
/protonwire
# -----------------------------------------------------------------
# Update README with help from script and docker compose file.
# -----------------------------------------------------------------
update-readme:
desc: "Update README.md"
cmds:
- cmd: sed -i '/<!--diana::dynamic:protonwire-help:begin-->/,/<!--diana::dynamic:protonwire-help:end-->/!b;//!d;/<!--diana::dynamic:protonwire-help:end-->/e echo "<pre>" && ./protonwire --help && echo "</pre>"' README.md
- cmd: sed -i '/<!--diana::dynamic:protonwire-sample-compose-file:begin-->/,/<!--diana::dynamic:protonwire-sample-compose-file:end-->/!b;//!d;/<!--diana::dynamic:protonwire-sample-compose-file:end-->/e echo "\\\`\\\`\\\`yaml" && cat docs/examples/docker/docker-compose.yml && echo "\\\`\\\`\\\`"' README.md
# -----------------------------------------------------------------
# Build Docker images
# -----------------------------------------------------------------
internal:build-script:
internal: true
requires:
vars:
- "GIT_COMMIT"
- "VERSION"
cmds:
- task: internal:mkdir
vars:
DIRECTORY: "dist"
- cmd: ./scripts/build-script build -o=dist/protonwire main.commit={{.GIT_COMMIT}} main.version={{.VERSION}}
internal:build-image:
internal: true
requires:
vars:
- "PLATFORM"
- "GIT_COMMIT"
- "GIT_COMMIT_TIMESTAMP"
- "GIT_STATUS_PORCELAIN"
vars:
IMAGE_LABEL_FLAGS: >-
{{- printf `--label "%s=%s"` "org.opencontainers.image.revision" .GIT_COMMIT }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.created" .GIT_COMMIT_TIMESTAMP }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.vendor" "Prasad Tengse <tprasadtp@users.noreply.github.com>" }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.source" "https://github.com/tprasadtp/protonvpn-docker" }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.title" "protonwire" }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.description" "ProtonVPN Wireguard Client" }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.licenses" "GPLv3" }}
{{- printf ` --label "%s=%s"` "org.opencontainers.image.documentation" "https://github.com/tprasadtp/protonvpn-docker" }}
{{- printf ` --label "%s=%s"` "io.artifacthub.package.readme-url" "https://raw.githubusercontent.com/tprasadtp/go-autotune/master/README.md" }}
IMAGE_TAG: >-
{{- if .GIT_STATUS_PORCELAIN }}
{{- printf "%s-%s-dirty" .GIT_COMMIT (.PLATFORM | replace "/" "-") }}
{{- else }}
{{- printf "%s-%s" .GIT_COMMIT (.PLATFORM | replace "/" "-") }}
{{- end }}
IMAGE_TARBALL: '{{ printf "%s.tar" (joinPath "build" (.PLATFORM | replace "/" "-")) }}'
env:
DOCKER_BUILDKIT: "1"
cmds:
- cmd: cp Dockerfile dist/Dockerfile
- docker build {{.IMAGE_LABEL_FLAGS}} --tag={{.PROTONWIRE_IMAGE}}:{{.IMAGE_TAG}} --tag={{.PROTONVPN_IMAGE}}:{{.IMAGE_TAG}} --platform={{.PLATFORM}} dist/
build-images:
desc: "Build Docker Images"
aliases:
- "images-build"
vars:
GIT_COMMIT:
sh: git -c log.showSignature=false show --format=%H --quiet HEAD
GIT_TREE_STATE:
sh: git -c log.showSignature=false status --porcelain
GIT_COMMIT_TIMESTAMP:
sh: git -c log.showSignature=false show --format=%cI --quiet HEAD
GIT_STATUS_PORCELAIN:
sh: git -c log.showSignature=false status --porcelain
GIT_DESCRIBE:
sh: git -c log.showSignature=false describe HEAD
cmds:
- task: internal:build-script
vars:
DIST: "{{.DIST_DIR}}"
GIT_COMMIT: "{{.GIT_COMMIT}}"
VERSION: >-
{{- if .GIT_STATUS_PORCELAIN }}
{{- printf "%s-dirty" .GIT_DESCRIBE }}
{{- else }}
{{- printf "%s" .GIT_DESCRIBE }}
{{- end }}
- for: ["linux/amd64", "linux/arm64"]
task: internal:build-image
vars:
PLATFORM: "{{.ITEM}}"
DIST_DIR: "dist"
GIT_COMMIT: "{{.GIT_COMMIT}}"
GIT_COMMIT_TIMESTAMP: "{{.GIT_COMMIT_TIMESTAMP}}"
GIT_STATUS_PORCELAIN: "{{.GIT_STATUS_PORCELAIN}}"
push-images:
desc: "Push docker images"
vars:
IMAGE_REPOS: "{{.PROTONWIRE_IMAGE}},{{.PROTONVPN_IMAGE}}"
GIT_COMMIT:
sh: git -c log.showSignature=false show --format=%H --quiet HEAD
GIT_STATUS_PORCELAIN:
sh: git -c log.showSignature=false status --porcelain
GIT_DIRTY_SUFFIX: >-
{{- if .GIT_STATUS_PORCELAIN }}
{{- printf "-dirty" }}
{{- end }}
cmds:
- for: ["linux/amd64", "linux/arm64"]
cmd: docker push {{.PROTONWIRE_IMAGE}}:{{.GIT_COMMIT}}-{{ .ITEM | replace "/" "-" }}{{.GIT_DIRTY_SUFFIX}}
- for: ["linux/amd64", "linux/arm64"]
cmd: docker push {{.PROTONVPN_IMAGE}}:{{.GIT_COMMIT}}-{{ .ITEM | replace "/" "-" }}{{.GIT_DIRTY_SUFFIX}}
push-manifests:
# We cannot push images and manifests in single step as digest
# cannot be computed locally by docker.
# - https://github.com/distribution/distribution/issues/1662
desc: "Push docker image manifests/index"
vars:
IMAGE_REPOS: "{{.PROTONWIRE_IMAGE}},{{.PROTONVPN_IMAGE}}"
GIT_COMMIT:
sh: git -c log.showSignature=false show --format=%H --quiet HEAD
GIT_COMMIT_SHORT:
sh: git -c log.showSignature=false show --format=%h --quiet HEAD
GIT_TAG_POINTS_AT_HEAD:
sh: git -c log.showSignature=false tag --points-at HEAD --sort=-version:refname
GIT_DESCRIBE:
sh: git -c log.showSignature=false describe HEAD
GIT_STATUS_PORCELAIN:
sh: git -c log.showSignature=false status --porcelain
GIT_TAG: >-
{{- if .GIT_TAG }}
{{- printf "%s" .GIT_TAG }}
{{- else if .GIT_TAG_POINTS_AT_HEAD }}
{{- printf "%s" (index (splitLines .GIT_TAG_POINTS_AT_HEAD) 0) | trim }}
{{- else }}
{{- printf "%s" .GIT_DESCRIBE | trim }}
{{- end }}
VERSION:
sh: go run internal/tasks/main.go semver version {{.GIT_TAG}}
V_MAJOR:
sh: go run internal/tasks/main.go semver major {{.GIT_TAG}}
V_MINOR:
sh: go run internal/tasks/main.go semver minor {{.GIT_TAG}}
V_IS_PRE_RELEASE:
sh: go run internal/tasks/main.go semver is-pre-release {{.GIT_TAG}}
V_UNSTABLE_SUFFIX: >-
{{- if eq (.V_IS_PRE_RELEASE|trim) "true" }}
{{- printf "%s" "-unstable" }}
{{- end }}
V_DIRTY_SUFFIX: >-
{{- if .GIT_STATUS_PORCELAIN }}
{{- printf "-dirty" }}
{{- end }}
V_UNSTABLE_OR_LATEST: >-
{{- if eq .V_IS_PRE_RELEASE "true" }}
{{- printf "%s" "unstable" }}
{{- else }}
{{- printf "%s" "latest" }}
{{- end }}
IMAGE_AMD64_DIGEST:
sh: crane digest {{.PROTONWIRE_IMAGE}}:{{.GIT_COMMIT}}-linux-amd64{{.V_DIRTY_SUFFIX}}
IMAGE_ARM64_DIGEST:
sh: crane digest {{.PROTONWIRE_IMAGE}}:{{.GIT_COMMIT}}-linux-arm64{{.V_DIRTY_SUFFIX}}
cmds:
# <IMAGE>:commit
- for: { var: IMAGE_REPOS, split: ',', as: IMAGE_REPO }
cmd: crane index append --tag {{.IMAGE_REPO}}:{{.GIT_COMMIT}}{{.V_DIRTY_SUFFIX}} -m {{.IMAGE_REPO}}@{{.IMAGE_AMD64_DIGEST}} -m {{.IMAGE_REPO}}@{{.IMAGE_ARM64_DIGEST}}
# <IMAGE>:commit-short
- for: { var: IMAGE_REPOS, split: ',', as: IMAGE_REPO }
cmd: crane index append --tag {{.IMAGE_REPO}}:{{.GIT_COMMIT_SHORT}}{{.V_DIRTY_SUFFIX}} -m {{.IMAGE_REPO}}@{{.IMAGE_AMD64_DIGEST}} -m {{.IMAGE_REPO}}@{{.IMAGE_ARM64_DIGEST}}
# <IMAGE>:git-tag
- for: { var: IMAGE_REPOS, split: ',', as: IMAGE_REPO }
cmd: crane index append --tag {{.IMAGE_REPO}}:{{.GIT_TAG}}{{.V_DIRTY_SUFFIX}} -m {{.IMAGE_REPO}}@{{.IMAGE_AMD64_DIGEST}} -m {{.IMAGE_REPO}}@{{.IMAGE_ARM64_DIGEST}}
# <IMAGE>:version, skipped if same as git tag i,e without prefix v.
- for: { var: IMAGE_REPOS, split: ',', as: IMAGE_REPO }
cmd: >-
{{- if eq .VERSION .GIT_TAG }}
echo "version and git tag are same ({{.VERSION }}) for image {{.IMAGE_REPO}}"
{{- else }}
crane index append --tag {{.IMAGE_REPO}}:{{.VERSION}}{{.V_DIRTY_SUFFIX}} -m {{.IMAGE_REPO}}@{{.IMAGE_AMD64_DIGEST}} -m {{.IMAGE_REPO}}@{{.IMAGE_ARM64_DIGEST}}
{{- end }}
# <IMAGE>:major.minor
- for: { var: IMAGE_REPOS, split: ',', as: IMAGE_REPO }
cmd: crane index append --tag {{.IMAGE_REPO}}:{{.V_MAJOR}}.{{.V_MINOR}}{{.V_UNSTABLE_SUFFIX}}{{.V_DIRTY_SUFFIX}} -m {{.IMAGE_REPO}}@{{.IMAGE_AMD64_DIGEST}} -m {{.IMAGE_REPO}}@{{.IMAGE_ARM64_DIGEST}}
# <IMAGE>:major
- for: { var: IMAGE_REPOS, split: ',', as: IMAGE_REPO }
cmd: crane index append --tag {{.IMAGE_REPO}}:{{.V_MAJOR}}{{.V_UNSTABLE_SUFFIX}}{{.V_DIRTY_SUFFIX}} -m {{.IMAGE_REPO}}@{{.IMAGE_AMD64_DIGEST}} -m {{.IMAGE_REPO}}@{{.IMAGE_ARM64_DIGEST}}
# <IMAGE>:latest or unstable
- for: { var: IMAGE_REPOS, split: ',', as: IMAGE_REPO }
cmd: crane index append --tag {{.IMAGE_REPO}}:{{.V_UNSTABLE_OR_LATEST}}{{.V_DIRTY_SUFFIX}} -m {{.IMAGE_REPO}}@{{.IMAGE_AMD64_DIGEST}} -m {{.IMAGE_REPO}}@{{.IMAGE_ARM64_DIGEST}}
# -----------------------------------------------------------------
# Cleanup generated data, cache and build artifacts
# -----------------------------------------------------------------
clean:
desc: "Clean cache, build artifacts etc."
aliases:
- "go:clean"
cmds:
- task: internal:rm-file-glob
vars:
DIRECTORY: '{{ joinPath .ROOT_DIR "dist" }}'
PATTERN: "{{.ITEM}}"
for:
- "*.json"
- "*.yml"
- "*.yaml"
- task: internal:rm-file-glob
vars:
DIRECTORY: '{{ joinPath .ROOT_DIR "build" }}'
PATTERN: "{{.ITEM}}"
for:
- "*.tar"
- "*.tar.gz"
- "*.sbom"
- "*.sbom.att"
- "*.sbom.att.json"
- "*.sbom.spdx"
- "*.sbom.spdx.json"
- "*.sbom.spdx.json"
- "*.sbom.cyclonedx.xml"
- "*.sbom.cyclonedx.json"
- "*.sigstore.pem"
- "*.sigstore.sig"
- "*.sigstore.bundle"
- "*.intoto.json"
- "*.in-toto.json"
- "*.jsonl"
- task: internal:rm-file-glob
vars:
DIRECTORY: '{{ joinPath .ROOT_DIR ".task" "checksum" }}'
PATTERN: "*"
- task: internal:rmdir
vars:
DIRECTORY: "{{ .ITEM }}"
for:
- "{{ .GO_COVER_DIR }}"
- '{{ joinPath .ROOT_DIR "bin" }}'
- '{{ joinPath .ROOT_DIR ".task" "checksum" }}'
- '{{ joinPath .ROOT_DIR ".task" }}'
- '{{ joinPath .ROOT_DIR "dist" }}'