forked from docker-library/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.sh
More file actions
executable file
·171 lines (159 loc) · 3.88 KB
/
Copy pathgenerate.sh
File metadata and controls
executable file
·171 lines (159 loc) · 3.88 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
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
#!/usr/bin/env bash
set -Eeuo pipefail
image="${GITHUB_REPOSITORY##*/}" # "python", "golang", etc
[ -x ./generate-stackbrew-library.sh ] # sanity check
tmp="$(mktemp -d)"
trap "$(printf 'rm -rf %q' "$tmp")" EXIT
# just to be safe
unset "${!BASHBREW_@}"
if ! command -v bashbrew &> /dev/null; then
echo 'Downloading bahbrew ...'
mkdir "$tmp/bin"
wget -qO "$tmp/bin/bashbrew" 'https://doi-janky.infosiftr.net/job/bashbrew/lastSuccessfulBuild/artifact/bin/bashbrew-amd64'
chmod +x "$tmp/bin/bashbrew"
export PATH="$tmp/bin:$PATH"
bashbrew --help > /dev/null
fi
mkdir "$tmp/library"
export BASHBREW_LIBRARY="$tmp/library"
./generate-stackbrew-library.sh > "$BASHBREW_LIBRARY/$image"
tags="$(bashbrew list --build-order --uniq "$image")"
order=()
declare -A metas=()
for tag in $tags; do
echo "Processing $tag ..."
meta="$(
bashbrew cat --format '
{{- $e := .TagEntry -}}
{{- "{" -}}
"name": {{- json ($e.Tags | first) -}},
"tags": {{- json ($.Tags "" false $e) -}},
"directory": {{- json $e.Directory -}},
"file": {{- json $e.File -}},
"constraints": {{- json $e.Constraints -}}
{{- "}" -}}
' "$tag" | jq -c '
{
name: .name,
os: (
if (.constraints | contains(["windowsservercore-1809"])) or (.constraints | contains(["nanoserver-1809"])) then
"windows-2019"
elif .constraints | contains(["windowsservercore-ltsc2016"]) then
"windows-2016"
elif .constraints == [] or .constraints == ["aufs"] then
"ubuntu-latest"
else
# use an intentionally invalid value so that GitHub chokes and we notice something is wrong
"invalid-or-unknown"
end
),
steps: [
{
name: ("Build " + .tags[0]),
run: (
[
"docker build"
]
+ (
.tags
| map(
"--tag " + (. | @sh)
)
)
+ if .file != "Dockerfile" then
[ "--file", (.file | @sh) ]
else
[]
end
+ [
"--pull",
(.directory | @sh)
]
| join(" ")
)
},
{
name: ("History " + .tags[0]),
run: ("docker history " + (.tags[0] | @sh))
},
{
name: ("Test " + .tags[0]),
run: ("~/oi/test/run.sh " + (.tags[0] | @sh))
}
]
}
'
)"
parent="$(bashbrew parents "$tag" | tail -1)" # if there ever exists an image with TWO parents in the same repo, this will break :)
if [ -n "$parent" ]; then
parent="$(bashbrew list --uniq "$parent")" # normalize
parentMeta="${metas["$parent"]}"
parentMeta="$(jq -c --argjson meta "$meta" '.steps += $meta.steps | .name += ", " + $meta.name' <<<"$parentMeta")"
metas["$parent"]="$parentMeta"
else
metas["$tag"]="$meta"
order+=( "$tag" )
fi
done
strategy="$(
for tag in "${order[@]}"; do
jq -c '.name' <<<"${metas["$tag"]}"
done | jq -cs '
{
"fail-fast": false,
matrix: { name: . }
}
'
)"
meta="$(
for tag in "${order[@]}"; do
jq -c '
.defaults = {
run: {
shell: "bash -Eeuo pipefail -x {0}"
}
}
| .steps = [
{ uses: "actions/checkout@v1" },
{
name: "Prepare Environment",
run: ([
"git clone --depth 1 https://github.com/docker-library/official-images.git ~/oi",
".github/workflows/prune.sh" # TODO move this to oi
] | join("\n"))
}
]
+ (
if .os | startswith("windows-") then
[]
else
[
{
name: "PGP Happy Eyeballs",
run: ([
"git clone --depth 1 https://github.com/tianon/pgp-happy-eyeballs.git ~/phe",
"~/phe/hack-my-builds.sh",
"rm -rf ~/phe"
] | join("\n"))
}
]
end
)
+ .steps
+ [
{
name: "\"docker images\"",
run: "docker images"
}
]
| { (.name) : . }
' <<<"${metas["$tag"]}"
done | jq -cs 'add'
)"
if [ "${GITHUB_ACTIONS:-}" = 'true' ]; then
echo "::set-output name=strategy::$strategy"
echo "::set-output name=meta::$meta"
else
jq <<<"$meta"
jq <<<"$strategy"
fi