Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
115 lines (105 loc) · 3.91 KB
/
Copy pathTaskfile.yml
File metadata and controls
115 lines (105 loc) · 3.91 KB
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
version: '3'
vars:
REGISTRY: '{{.REGISTRY | default "8gcr.container-registry.dev/oci-native"}}'
ENGINE:
sh: command -v podman || command -v docker
APPS:
sh: ls containers
tasks:
default:
silent: true
cmds:
- task --list
build:*:
desc: Build one app image; tag comes from its cask version
vars:
APP: '{{index .MATCH 0}}'
VERSION: &cask-version
sh: sed -n 's/^ *version "\(.*\)"$/\1/p' "$(find Casks -name '{{.APP}}.rb' -print -quit)" | tr '+' '-'
preconditions:
- sh: test -f 'containers/{{.APP}}/Containerfile'
msg: 'no containers/{{.APP}}/Containerfile'
- sh: test -n '{{.VERSION}}'
msg: 'no cask version found for {{.APP}}'
cmds:
- |
context=$(mktemp -d)
trap 'rm -rf "$context"' EXIT
cp 'containers/{{.APP}}'/* "$context/"
# A Containerfile that copies cask.deb gets the cask's own
# artifact, brew-fetched and sha256-verified.
artifact=$(grep -oEm1 '^COPY cask\.(deb|pkg)' 'containers/{{.APP}}/Containerfile' | cut -d' ' -f2 || true)
if [ -n "$artifact" ]; then
brew fetch --cask 'oci-native/pkgs/{{.APP}}'
cp "$(brew --cache --cask 'oci-native/pkgs/{{.APP}}')" "$context/$artifact"
fi
# BUILD_CACHE=1 shares layers through the registry (podman only),
# so ephemeral CI runners reuse layers from previous runs.
cache_args=""
if [ -n "${BUILD_CACHE:-}" ] && [ "$(basename '{{.ENGINE}}')" = podman ]; then
cache_args="--layers --cache-from={{.REGISTRY}}/cache/{{.APP}} --cache-to={{.REGISTRY}}/cache/{{.APP}} --cache-ttl=168h"
fi
{{.ENGINE}} build $cache_args --build-arg 'APP_VERSION={{.VERSION}}' \
-t '{{.REGISTRY}}/{{.APP}}:{{.VERSION}}' \
-t '{{.REGISTRY}}/{{.APP}}:latest' "$context"
push:*:
desc: Build and push one app image
vars:
APP: '{{index .MATCH 0}}'
VERSION: *cask-version
cmds:
- task: 'build:{{.APP}}'
- '{{.ENGINE}} push {{.REGISTRY}}/{{.APP}}:{{.VERSION}}'
- '{{.ENGINE}} push {{.REGISTRY}}/{{.APP}}:latest'
release:*:
desc: Push, sign, verify, and pin one app image by digest
vars:
APP: '{{index .MATCH 0}}'
VERSION: *cask-version
preconditions:
- sh: test "$(basename '{{.ENGINE}}')" = podman
msg: 'release needs podman (push --digestfile)'
- sh: command -v cosign
msg: 'cosign required to sign and verify'
cmds:
- task: 'build:{{.APP}}'
- |
digestfile=$(mktemp)
trap 'rm -f "$digestfile"' EXIT
{{.ENGINE}} push --digestfile "$digestfile" '{{.REGISTRY}}/{{.APP}}:{{.VERSION}}'
{{.ENGINE}} push '{{.REGISTRY}}/{{.APP}}:latest'
digest=$(cat "$digestfile")
ref='{{.REGISTRY}}/{{.APP}}@'"$digest"
cosign sign --yes "$ref"
cosign verify \
--certificate-identity-regexp 'https://github.com/oci-native/(homebrew-)?pkgs/' \
--certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \
"$ref" >/dev/null
# Pin the signed digest in the cask; version stays as the
# side comment, actions-pinning style.
cask=$(find Casks -name '{{.APP}}.rb' -print -quit)
sed -i "s|^\\( *DIGEST=\\)\"[^\"]*\" *#.*\$|\\1\"$digest\" # {{.VERSION}}|" "$cask"
echo "{{.APP}}: pinned $digest ({{.VERSION}})"
release-all:
desc: Push, sign, verify, and pin every app image
cmds:
- for: {var: APPS}
task: 'release:{{.ITEM}}'
build-all:
desc: Build every app image
cmds:
- for: {var: APPS}
task: 'build:{{.ITEM}}'
push-all:
desc: Build and push every app image
cmds:
- for: {var: APPS}
task: 'push:{{.ITEM}}'
lint:
desc: Run brew style across the tap
cmds:
- brew style --cask oci-native/pkgs
audit:
desc: Run brew audit across the tap
cmds:
- brew audit --tap oci-native/pkgs