-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
190 lines (182 loc) · 7.11 KB
/
Taskfile.yaml
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
---
version: '3'
vars:
IMAGE_REGISTRY: containers.io
ORG: test
tasks:
default:
cmds:
- go-task -l
silent: true
push:
desc: |-
go-task APP=<app> push
cmds:
- |-
for channel in $(jq --raw-output '.channels | .[] | .name' apps/{{ .APP }}/metadata.json); do
go-task APP={{ .APP }} CHANNEL=${channel} push-channel
done
build:
desc: |-
go-task APP=<app> build
cmds:
- |-
for channel in $(jq --raw-output '.channels | .[] | .name' apps/{{ .APP }}/metadata.json); do
go-task APP={{ .APP }} CHANNEL=${channel} build-channel
done
test:
desc: |-
go-task APP=<app> test
cmds:
- |-
for channel in $(jq --raw-output '.channels | .[] | .name' apps/{{ .APP }}/metadata.json); do
go-task APP={{ .APP }} CHANNEL=${channel} test-channel
done
push-channel:
desc: |-
go-task APP=<app> CHANNEL=<stable|devel> push-channel
cmds:
- task: build
- |-
for tag in {{ .TAGS }}; do
echo docker push "${tag}"
done
vars:
BASEIMGVERSION:
sh: >-
jq --arg chan "{{ .CHANNEL }}" --raw-output '(.channels | .[] | select(.name == $chan)) | .baseimgversion'
./apps/{{ .APP }}/metadata.json
VERSION:
sh: >-
jq --arg chan "{{ .CHANNEL }}" --raw-output '(.channels | .[] | select(.name == $chan)) |
if .version == "master" then "latest" else .version end'
./apps/{{ .APP }}/metadata.json
TAGS:
sh: >-
echo '{{ .VERSION }}' |
sed -E 's@^([0-9]{4})-([0-9]{2})-([0-9]{2})(.*)$@\1.\2.\3\4@g' |
awk -F. '{ print "#" $1 "#" $1 "." $2 "#" $1 "." $2 "." $3 "#" }' |
sed -E 's@[^#]+\.+#@@g' |
sed 's@#$@@g' |
{{ if eq .CHANNEL "stable" }}
sed 's@#@ {{ .IMAGE_REGISTRY }}/{{ .ORG }}/{{ .APP }}:@g' |
awk -F\# '{ print $0 " {{ .IMAGE_REGISTRY }}/{{ .ORG }}/{{ .APP }}:latest"}'
{{ else }}
sed 's@#@ {{ .IMAGE_REGISTRY }}/{{ .ORG }}/{{ .APP }}-{{ .CHANNEL }}:@g' |
awk -F\# '{ print $0 " {{ .IMAGE_REGISTRY }}/{{ .ORG }}/{{ .APP }}-{{ .CHANNEL }}:latest"}'
{{ end }}
build-channel:
desc: |-
go-task APP=<app> CHANNEL=<stable|devel> build-channel
cmds:
# prepare multiarch docker build
# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- task: test
# yamllint disable rule:line-length
- |-
for platform in $(jq --arg chan "{{ .CHANNEL }}" --raw-output \
'(.channels | .[] | select(.name == $chan)) | .platforms | join(" ")' ./apps/{{ .APP }}/metadata.json); do
docker buildx build --load \
{{ .TAGS }} \
--build-arg CHANNEL={{ .CHANNEL }} \
--build-arg METAVAR={{ .METAVAR }} \
--build-arg BASEIMGVERSION={{ .BASEIMGVERSION }} \
--build-arg VERSION={{ .VERSION }} \
--build-arg TARGETPLATFORM="${platform}" \
--platform "${platform}" \
--label '{{ .LABEL_TYPE }}.created={{ .BUILD_DATE }}' \
--label '{{ .LABEL_TYPE }}.title={{ .APP }} ({{ .CHANNEL }})' \
--label '{{ .LABEL_TYPE }}.version={{ .VERSION }}' \
--label '{{ .LABEL_TYPE }}.authors=Igor Rzegocki <[email protected]>' \
--label '{{ .LABEL_TYPE }}.url=https://github.com/deedee-ops/containers/tree/master/apps/{{ .APP }}' \
--label '{{ .LABEL_TYPE }}.documentation=https://github.com/deedee-ops/containers/tree/master/apps/{{ .APP }}/README.md' \
-f apps/{{ .APP }}/Dockerfile apps/{{ .APP }}
done
# yamllint enable
vars:
BASE:
sh: "jq '.base' apps/{{ .APP }}/metadata.json"
BUILD_DATE:
sh: "date --rfc-3339=seconds --utc"
LABEL_TYPE:
sh: >-
echo "org.opencontainers.image{{if eq .BASE "true"}}.base{{end}}"
BASEIMGVERSION:
sh: >-
jq --arg chan "{{ .CHANNEL }}" --raw-output '(.channels | .[] | select(.name == $chan)) | .baseimgversion'
./apps/{{ .APP }}/metadata.json
METAVAR:
sh: >-
jq --arg chan "{{ .CHANNEL }}" --raw-output '(.channels | .[] | select(.name == $chan)) | .metavar'
./apps/{{ .APP }}/metadata.json
VERSION:
sh: >-
jq --arg chan "{{ .CHANNEL }}" --raw-output '(.channels | .[] | select(.name == $chan)) | .version'
./apps/{{ .APP }}/metadata.json
TAGS:
sh: >-
echo '{{ .VERSION }}' |
sed -E 's@^([0-9]{4})-([0-9]{2})-([0-9]{2})(.*)$@\1.\2.\3\4@g' |
awk -F. '{ print "#" $1 "#" $1 "." $2 "#" $1 "." $2 "." $3 "#" }' |
sed -E 's@[^#]+\.+#@@g' |
sed 's@#$@@g' |
{{ if eq .CHANNEL "stable" }}
sed 's@#@ -t {{ .IMAGE_REGISTRY }}/{{ .ORG }}/{{ .APP }}:@g' |
awk -F\# '{ print $0 " -t {{ .IMAGE_REGISTRY }}/{{ .ORG }}/{{ .APP }}:latest"}'
{{ else }}
sed 's@#@ -t {{ .IMAGE_REGISTRY }}/{{ .ORG }}/{{ .APP }}-{{ .CHANNEL }}:@g' |
awk -F\# '{ print $0 " -t {{ .IMAGE_REGISTRY }}/{{ .ORG }}/{{ .APP }}-{{ .CHANNEL }}:latest"}'
{{ end }}
test-channel:
desc: |-
go-task APP=<app> CHANNEL=<stable|devel> test-channel
cmds:
- >-
cue vet --schema '#Spec' ./apps/{{ .APP }}/metadata.json metadata.rules.cue
- >-
docker buildx build --load
-t test/{{ .APP }}:{{ .CHANNEL }}
--build-arg CHANNEL={{ .CHANNEL }}
--build-arg METAVAR={{ .METAVAR }}
--build-arg BASEIMGVERSION={{ .BASEIMGVERSION }}
--build-arg VERSION={{ .VERSION }}
--platform linux/amd64
-f apps/{{ .APP }}/Dockerfile apps/{{ .APP }}
- >-
if [ -d apps/{{ .APP }}/ci ]; then
dgoss run
$([ -d apps/{{ .APP }}/ci/secrets ] && echo "-v $(pwd)/apps/{{ .APP }}/ci/secrets:/secrets")
{{if ne .INSECURE "true"}}
--read-only
-u 65000:65000
{{end}}
$([ -d /nix ] && echo "-v /nix:/nix")
--cap-drop=all
{{if eq .TEST_MUTE_CMD "true"}}--entrypoint ""{{end}}
test/{{ .APP }}:{{ .CHANNEL }}
{{if eq .TEST_MUTE_CMD "true"}}tail -f /dev/null{{end}};
fi
vars:
BASE:
sh: "jq '.base' apps/{{ .APP }}/metadata.json"
INSECURE:
sh: "jq '.insecure' apps/{{ .APP }}/metadata.json"
TEST_MUTE_CMD:
sh: "jq '.testMuteCmd' apps/{{ .APP }}/metadata.json"
BASEIMGVERSION:
sh: >-
jq --arg chan "{{ .CHANNEL }}" --raw-output '(.channels | .[] | select(.name == $chan)) | .baseimgversion'
./apps/{{ .APP }}/metadata.json
METAVAR:
sh: >-
jq --arg chan "{{ .CHANNEL }}" --raw-output '(.channels | .[] | select(.name == $chan)) | .metavar'
./apps/{{ .APP }}/metadata.json
VERSION:
sh: >-
jq --arg chan "{{ .CHANNEL }}" --raw-output '(.channels | .[] | select(.name == $chan)) | .version'
./apps/{{ .APP }}/metadata.json
env:
CONTAINER_RUNTIME: docker
GOSS_OPTS: --sleep 5s --retry-timeout 60s --color --format documentation
GOSS_SLEEP: 2
GOSS_FILE: ./apps/{{.APP}}/ci/goss.yaml