Skip to content

Commit 4a7dea0

Browse files
committed
Merge pull request docker-library#95 from infosiftr/rfc2822
Convert "generate-stackbrew-library.sh" to output the new 2822-based format
2 parents f376892 + 47dccaf commit 4a7dea0

File tree

1 file changed

+67
-21
lines changed

1 file changed

+67
-21
lines changed

generate-stackbrew-library.sh

Lines changed: 67 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,88 @@
11
#!/bin/bash
2-
set -e
2+
set -eu
33

44
declare -A aliases
55
aliases=(
66
[1.6]='1 latest'
77
)
88

9+
self="$(basename "$BASH_SOURCE")"
910
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
1011

1112
versions=( */ )
1213
versions=( "${versions[@]%/}" )
13-
url='git://github.com/docker-library/golang'
1414

15-
echo '# maintainer: InfoSiftr <[email protected]> (@infosiftr)'
16-
echo '# maintainer: Johan Euphrosine <[email protected]> (@proppy)'
15+
# get the most recent commit which modified any of "$@"
16+
fileCommit() {
17+
git log -1 --format='format:%H' HEAD -- "$@"
18+
}
19+
20+
# get the most recent commit which modified "$1/Dockerfile" or any file COPY'd from "$1/Dockerfile"
21+
dirCommit() {
22+
local dir="$1"; shift
23+
(
24+
cd "$dir"
25+
fileCommit \
26+
Dockerfile \
27+
$(git show HEAD:./Dockerfile | awk '
28+
toupper($1) == "COPY" {
29+
for (i = 2; i < NF; i++) {
30+
print $i
31+
}
32+
}
33+
')
34+
)
35+
}
36+
37+
cat <<-EOH
38+
# this file is generated via https://github.com/docker-library/golang/blob/$(fileCommit "$self")/$self
39+
40+
Maintainers: Tianon Gravi <[email protected]> (@tianon),
41+
Joseph Ferguson <[email protected]> (@yosifkit),
42+
Johan Euphrosine <[email protected]> (@proppy)
43+
GitRepo: https://github.com/docker-library/golang.git
44+
45+
EOH
46+
47+
# prints "$2$1$3$1...$N"
48+
join() {
49+
local sep="$1"; shift
50+
local out; printf -v out "${sep//%/%%}%s" "$@"
51+
echo "${out#$sep}"
52+
}
1753

1854
for version in "${versions[@]}"; do
19-
commit="$(cd "$version" && git log -1 --format='format:%H' -- Dockerfile $(awk 'toupper($1) == "COPY" { for (i = 2; i < NF; i++) { print $i } }' Dockerfile))"
20-
fullVersion="$(grep -m1 'ENV GOLANG_VERSION ' "$version/Dockerfile" | cut -d' ' -f3)"
55+
commit="$(dirCommit "$version")"
56+
57+
fullVersion="$(git show "$commit":"$version/Dockerfile" | awk '$1 == "ENV" && $2 == "GOLANG_VERSION" { print $3; exit }')"
2158
[[ "$fullVersion" == *.*[^0-9]* ]] || fullVersion+='.0'
22-
versionAliases=( $fullVersion $version ${aliases[$version]} )
23-
59+
60+
versionAliases=(
61+
$fullVersion
62+
$version
63+
${aliases[$version]:-}
64+
)
65+
2466
echo
25-
for va in "${versionAliases[@]}"; do
26-
echo "$va: ${url}@${commit} $version"
27-
done
28-
67+
cat <<-EOE
68+
Tags: $(join ', ' "${versionAliases[@]}")
69+
GitCommit: $commit
70+
Directory: $version
71+
EOE
72+
2973
for variant in onbuild cross wheezy alpine; do
3074
[ -f "$version/$variant/Dockerfile" ] || continue
31-
commit="$(cd "$version/$variant" && git log -1 --format='format:%H' -- Dockerfile $(awk 'toupper($1) == "COPY" { for (i = 2; i < NF; i++) { print $i } }' Dockerfile))"
75+
76+
commit="$(dirCommit "$version/$variant")"
77+
78+
variantAliases=( "${versionAliases[@]/%/-$variant}" )
79+
variantAliases=( "${variantAliases[@]//latest-/}" )
80+
3281
echo
33-
for va in "${versionAliases[@]}"; do
34-
if [ "$va" = 'latest' ]; then
35-
va="$variant"
36-
else
37-
va="$va-$variant"
38-
fi
39-
echo "$va: ${url}@${commit} $version/$variant"
40-
done
82+
cat <<-EOE
83+
Tags: $(join ', ' "${variantAliases[@]}")
84+
GitCommit: $commit
85+
Directory: $version/$variant
86+
EOE
4187
done
4288
done

0 commit comments

Comments
 (0)