Skip to content

Commit 03bb6d0

Browse files
mattrobenoltthresheek
authored andcommitted
Add script to generate stackbrew library for upstream
Signed-off-by: Konstantin Pavlov <thresh@nginx.com>
1 parent 72725fc commit 03bb6d0

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

generate-stackbrew-library.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
declare -A aliases
5+
aliases=(
6+
[mainline]='1 1.11 latest'
7+
[stable]='1.10'
8+
)
9+
10+
self="$(basename "$BASH_SOURCE")"
11+
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
12+
base=jessie
13+
14+
versions=( */ )
15+
versions=( "${versions[@]%/}" )
16+
17+
# get the most recent commit which modified any of "$@"
18+
fileCommit() {
19+
git log -1 --format='format:%H' HEAD -- "$@"
20+
}
21+
22+
# get the most recent commit which modified "$1/Dockerfile" or any file COPY'd from "$1/Dockerfile"
23+
dirCommit() {
24+
local dir="$1"; shift
25+
(
26+
cd "$dir"
27+
fileCommit \
28+
Dockerfile \
29+
$(git show HEAD:./Dockerfile | awk '
30+
toupper($1) == "COPY" {
31+
for (i = 2; i < NF; i++) {
32+
print $i
33+
}
34+
}
35+
')
36+
)
37+
}
38+
39+
cat <<-EOH
40+
# this file is generated via https://github.com/nginxinc/docker-nginx/blob/$(fileCommit "$self")/$self
41+
42+
Maintainers: Docker Maintainers <docker-maint@nginx.com>
43+
GitRepo: https://github.com/nginxinc/docker-nginx.git
44+
EOH
45+
46+
# prints "$2$1$3$1...$N"
47+
join() {
48+
local sep="$1"; shift
49+
local out; printf -v out "${sep//%/%%}%s" "$@"
50+
echo "${out#$sep}"
51+
}
52+
53+
for version in "${versions[@]}"; do
54+
commit="$(dirCommit "$version/$base")"
55+
56+
fullVersion="$(git show "$commit":"$version/$base/Dockerfile" | awk '$1 == "ENV" && $2 == "NGINX_VERSION" { print $3; exit }')"
57+
fullVersion="${fullVersion%[.-]*}"
58+
59+
versionAliases=( $fullVersion )
60+
if [ "$version" != "$fullVersion" ]; then
61+
versionAliases+=( $version )
62+
fi
63+
versionAliases+=( ${aliases[$version]:-} )
64+
65+
echo
66+
cat <<-EOE
67+
Tags: $(join ', ' "${versionAliases[@]}")
68+
GitCommit: $commit
69+
Directory: $version/$base
70+
EOE
71+
72+
for variant in alpine; do
73+
commit="$(dirCommit "$version/$variant")"
74+
75+
variantAliases=( "${versionAliases[@]/%/-$variant}" )
76+
variantAliases=( "${variantAliases[@]//latest-/}" )
77+
78+
echo
79+
cat <<-EOE
80+
Tags: $(join ', ' "${variantAliases[@]}")
81+
GitCommit: $commit
82+
Directory: $version/$variant
83+
EOE
84+
done
85+
done

0 commit comments

Comments
 (0)