forked from docker-flink/docker-flink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-stackbrew-library.sh
executable file
·210 lines (170 loc) · 5.95 KB
/
generate-stackbrew-library.sh
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
#!/bin/bash
# This script generates a manifest compatibile with the expectations set forth
# by docker-library/official-images.
#
# It is not compatible with the version of Bash currently shipped with OS X due
# to the use of features introduced in Bash 4.
set -eu
declare -A aliases=(
[1.7]='latest'
)
self="$(basename "$BASH_SOURCE")"
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
# Identify directories matching '?.?' (e.g. '1.7') and remove trailing slashes
versions=( ?.?/ )
versions=( "${versions[@]%/}" )
# get the most recent commit which modified any of "$@"
fileCommit() {
git log -1 --format='format:%H' HEAD -- "$@"
}
# get the most recent commit which modified "$1/Dockerfile" or any file COPY'd from "$1/Dockerfile"
dirCommit() {
local dir="$1"; shift
(
cd "$dir"
fileCommit \
Dockerfile \
$(git show HEAD:./Dockerfile | awk '
toupper($1) == "COPY" {
for (i = 2; i < NF; i++) {
print $i
}
}
')
)
}
getArches() {
local repo="$1"; shift
local officialImagesUrl='https://github.com/docker-library/official-images/raw/master/library/'
eval "declare -g -A parentRepoToArches=( $(
find -name 'Dockerfile' -exec awk '
toupper($1) == "FROM" && $2 !~ /^('"$repo"'|scratch|microsoft\/[^:]+)(:|$)/ {
print "'"$officialImagesUrl"'" $2
}
' '{}' + \
| sort -u \
| xargs bashbrew cat --format '[{{ .RepoName }}:{{ .TagName }}]="{{ join " " .TagEntry.Architectures }}"'
) )"
}
getArches 'flink'
cat <<-EOH
# this file is generated via https://github.com/docker-flink/docker-flink/blob/$(fileCommit "$self")/$self
Maintainers: Patrick Lucas <[email protected]> (@patricklucas),
Ismaël Mejía <[email protected]> (@iemejia)
GitRepo: https://github.com/docker-flink/docker-flink.git
EOH
# prints "$2$1$3$1...$N"
join() {
local sep="$1"; shift
local out; printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
}
# Sorry for the style here, but it makes the nested code easier to read
for version in "${versions[@]}"; do
# Defaults, can vary between versions
source_variants=( debian alpine )
hadoop_variants=( 24 26 27 28 0 )
scala_variants=( 2.11 )
# Version-specific variants (example)
# if [ "$version" = "x.y" ]; then
# hadoop_variants=( 24 26 27 28 0 )
# scala_variants=( 2.10 2.11 )
# fi
if [ "$version" = "1.7" ]; then
scala_variants=( 2.11 2.12 )
fi
for source_variant in "${source_variants[@]}"; do
for hadoop_variant in "${hadoop_variants[@]}"; do
for scala_variant in "${scala_variants[@]}"; do
if [ "$hadoop_variant" = "0" ]; then
hadoop_scala_variant="scala_${scala_variant}"
else
hadoop_scala_variant="hadoop${hadoop_variant}-scala_${scala_variant}"
fi
dir="$version/${hadoop_scala_variant}-${source_variant}"
# Not all Hadoop/Scala combinations may exist
[ -f "$dir/Dockerfile" ] || continue
commit="$(dirCommit "$dir")"
# Extract the full Flink version from the Dockerfile
flink_version="$(git show "$commit":"$dir/Dockerfile" | awk '/ENV FLINK_VERSION=(.*) /{ split($2,a,"="); print a[2]}')"
full_version=$flink_version-$hadoop_scala_variant
variantParent="$(awk 'toupper($1) == "FROM" { print $2 }' "$dir/Dockerfile")"
variantArches="${parentRepoToArches[$variantParent]}"
# Start with the full version e.g. "1.2.0-hadoop27-scala_2.11" and add
# additional tags as relevant
tags=( $full_version )
is_latest_version=
[ "$version" = "${versions[-1]}" ] && is_latest_version=1
is_latest_hadoop=
[ "$hadoop_variant" = "${hadoop_variants[-1]}" ] && is_latest_hadoop=1
is_latest_scala=
[ "$scala_variant" = "${scala_variants[-1]}" ] && is_latest_scala=1
# For the latest supported Hadoop version, add tags that omit it
if [ -n "$is_latest_hadoop" ]; then
# For Hadoop-free, the tag $flink_version-scala_$scala_variant is redundant
if [ "$hadoop_variant" = "0" ]; then
add_tags=( $version )
else
add_tags=( $flink_version $version )
fi
tags=(
${tags[@]}
${add_tags[@]/%/-scala_$scala_variant}
)
if [ -n "$is_latest_version" ]; then
tags=(
${tags[@]}
"scala_$scala_variant"
)
fi
fi
# For the latest supported Scala version, add tags that omit it
# (Not needed for Hadoop-free since there is no specific "hadoop*" tag for it)
if [ -n "$is_latest_scala" -a "$hadoop_variant" != "0" ]; then
add_tags=( $flink_version $version )
tags=(
${tags[@]}
${add_tags[@]/%/-hadoop$hadoop_variant}
)
if [ -n "$is_latest_version" ]; then
tags=(
${tags[@]}
"hadoop$hadoop_variant"
)
fi
fi
# For the latest supported Hadoop & Scala version, add tags that omit them
if [ -n "$is_latest_hadoop" ] && [ -n "$is_latest_scala" ]; then
tags=(
${tags[@]}
$flink_version
$version
)
fi
# Add -$variant suffix for non-debian-based images
if [ "$source_variant" != "debian" ]; then
tags=( ${tags[@]/%/-$source_variant} )
fi
# Finally, designate the 'latest' tag (or '$variant', for non-debian-based images)
if [ -n "$is_latest_hadoop" ] && [ -n "$is_latest_scala" ]; then
alias_tag="${aliases[$version]:-}"
if [ -n "$alias_tag" ] && [ "$source_variant" != "debian" ]; then
alias_tag="$source_variant"
fi
tags=(
${tags[@]}
$alias_tag
)
fi
echo
# The tabs here are necessary for the heredoc to work right
cat <<-EOE
Tags: $(join ', ' "${tags[@]}")
Architectures: $(join ', ' $variantArches)
GitCommit: $commit
Directory: $dir
EOE
done
done
done
done