-
Notifications
You must be signed in to change notification settings - Fork 2
/
justfile
106 lines (90 loc) · 3.13 KB
/
justfile
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
version := ''
image := 'ghcr.io/linkerd/dev'
_tag := if version != '' { "--tag=" + image + ':' + version } else { "" }
k3s-image := 'docker.io/rancher/k3s'
targets := 'go rust rust-musl tools devcontainer'
load := 'false'
push := 'false'
output := if push == 'true' {
'type=registry'
} else if load == 'true' {
'type=docker'
} else {
'type=image'
}
export DOCKER_PROGRESS := env_var_or_default('DOCKER_PROGRESS', 'auto')
all: sync-k3s-images build
build: && _list-if-load
#!/usr/bin/env bash
set -euo pipefail
for tgt in {{ targets }} ; do
just output='{{ output }}' \
image='{{ image }}' \
version='{{ version }}' \
_target "$tgt"
done
_list-if-load:
#!/usr/bin/env bash
set -euo pipefail
if [ '{{ load }}' = 'true' ] ; then
just image='{{ image }}' \
targets='{{ targets }}' \
version='{{ version }}' \
list
fi
list:
#!/usr/bin/env bash
set -euo pipefail
if [ -z '{{ version }}' ]; then
echo "Usage: just version=<version> list" >&2
exit 64
fi
for tgt in {{ targets }} ; do
if [ "$tgt" == "devcontainer" ]; then
docker image ls {{ image }}:{{ version }} | sed 1d
else
docker image ls {{ image }}:{{ version }}-$tgt | sed 1d
fi
done
# Fetch the latest version of k3s images and record their tags and digests.
sync-k3s-images:
#!/usr/bin/env bash
set -euo pipefail
CHANNELS=$(just minimum-k8s='{{ minimum-k8s }}' _k3s-channels)
DIGESTS=$(for tag in $(echo "$CHANNELS" | jq -r 'to_entries | .[].value' | sort -u) ; do
jo key="$tag" value="$(just k3s-image='{{ k3s-image }}' _k3s-inspect "${tag}" | jq -r '.Digest')"
done | jq -cs 'from_entries')
jo name='{{ k3s-image }}' channels="$CHANNELS" digests="$DIGESTS" \
| jq . > k3s-images.json
jq . k3s-images.json
minimum-k8s := '20'
# Inspect a k3s image by tag
_k3s-inspect tag:
skopeo inspect 'docker://{{ k3s-image }}:{{ tag }}'
# Fetch the latest tag for non-EOL channels.
_k3s-channels:
#!/usr/bin/env bash
set -euo pipefail
scurl 'https://update.k3s.io/v1-release/channels' \
| jq -cr '[.data[]
| select(.type == "channel")
| select(.id | test("^(.*-)?testing") | not)
| (.latest | sub("\\+"; "-")) as $tag
| ($tag | capture("^v1\\.(?<v>\\d+)\\.\\d+-.*") | .v | tonumber) as $version
| select($version >= {{ minimum-k8s }})
| {key:.id, value:$tag}
] | from_entries'
_target target='':
@just \
output='{{ output }}' \
image='{{ image }}' \
_build --target='{{ target }}' \
{{ if version == '' { '' } else { '--tag=' + image + ':' + version + if target == 'devcontainer' { '' } else { '-' + target } } }}
# Build the devcontainer image
_build *args='':
docker buildx build . {{ _tag }} --pull \
--progress='{{ DOCKER_PROGRESS }}' \
--output='{{ output }}' \
{{ args }}
md-lint *patterns="'**/*.md' '!repos/**'":
@bin/just-md lint {{ patterns }}