forked from docker-library/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·201 lines (166 loc) · 6.1 KB
/
update.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
#!/bin/bash
set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
helperDir='.template-helpers'
# usage: ./update.sh [--namespace NAMESPACE] [[NAMESPACE/]IMAGE ...]
# ie: ./update.sh
# ./update.sh debian golang
# ./update.sh --namespace tianontesting debian golang
# ./update.sh tianontesting/debian tianontestingmore/golang
# BASHBREW_ARCH=windows-amd64 BASHBREW_ARCH_NAMESPACES='...' ./update.sh --namespace winamd64
forceNamespace=
if [ "${1:-}" = '--namespace' ]; then
shift
forceNamespace="$1"
shift
fi
images=( "$@" )
if [ ${#images[@]} -eq 0 ]; then
images=( */ )
fi
images=( "${images[@]%/}" )
if [ -n "$forceNamespace" ]; then
images=( "${images[@]/#/"$forceNamespace/"}" )
fi
replace_field() {
targetFile="$1"
field="$2"
content="$3"
extraSed="${4:-}"
sed_escaped_value="$(echo "$content" | sed 's/[\/&]/\\&/g')"
sed_escaped_value="${sed_escaped_value//$'\n'/\\n}"
sed -ri -e "s/${extraSed}%%${field}%%${extraSed}/$sed_escaped_value/g" "$targetFile"
}
for image in "${images[@]}"; do
repo="${image##*/}"
namespace="${image%$repo}"
namespace="${namespace%/}"
# this is used by subscripts to determine whether we're pushing /_/xxx or /r/ARCH/xxx
# (especialy for "supported tags")
export ARCH_SPECIFIC_DOCS=
if [ -n "$namespace" ] && [ -n "${BASHBREW_ARCH:-}" ]; then
export ARCH_SPECIFIC_DOCS=1
fi
if [ -x "$repo/update.sh" ]; then
( set -x; "$repo/update.sh" "$image" )
fi
if [ -e "$repo/content.md" ]; then
githubRepo="$(cat "$repo/github-repo")"
maintainer="$(cat "$repo/maintainer.md")"
issues="$(cat "$repo/issues.md" 2>/dev/null || cat "$helperDir/issues.md")"
getHelp="$(cat "$repo/get-help.md" 2>/dev/null || cat "$helperDir/get-help.md")"
license="$(cat "$repo/license.md" 2>/dev/null || true)"
licenseCommon="$(cat "$repo/license-common.md" 2>/dev/null || cat "$helperDir/license-common.md")"
if [ "$license" ]; then
license=$'\n\n''# License'$'\n\n'"$license"$'\n\n'"$licenseCommon"
fi
logo=
logoFile=
for f in png svg; do
if [ -e "$repo/logo.$f" ]; then
logoFile="$repo/logo.$f"
break
fi
done
if [ "$logoFile" ]; then
logoCommit="$(git log -1 --format='format:%H' -- "$logoFile" 2>/dev/null || true)"
[ "$logoCommit" ] || logoCommit='master'
logoUrl="https://raw.githubusercontent.com/docker-library/docs/$logoCommit/$logoFile"
if [ "${logoFile##*.}" = 'svg' ]; then
# https://stackoverflow.com/a/16462143/433558
logoUrl+='?sanitize=true'
fi
logo=""
fi
stack=
stackYml=
stackUrl=
if [ -f "$repo/stack.yml" ]; then
stack="$(cat "$repo/stack.md" 2>/dev/null || cat "$helperDir/stack.md")"
stackYml=$'```yaml\n'"$(cat "$repo/stack.yml")"$'\n```'
stackCommit="$(git log -1 --format='format:%H' -- "$repo/stack.yml" 2>/dev/null || true)"
[ "$stackCommit" ] || stackCommit='master'
stackUrl="https://raw.githubusercontent.com/docker-library/docs/$stackCommit/$repo/stack.yml"
fi
compose=
composeYml=
if [ -f "$repo/docker-compose.yml" ]; then
compose="$(cat "$repo/compose.md" 2>/dev/null || cat "$helperDir/compose.md")"
composeYml=$'```yaml\n'"$(cat "$repo/docker-compose.yml")"$'\n```'
fi
deprecated=
if [ -f "$repo/deprecated.md" ]; then
deprecated=$'# **DEPRECATION NOTICE**\n\n'
deprecated+="$(cat "$repo/deprecated.md")"
deprecated+=$'\n\n'
fi
echo ' GIT PREFETCH => "'"$repo"'"'
"$helperDir/git-prefetch.sh" "$repo"
if ! partial="$("$helperDir/generate-dockerfile-links-partial.sh" "$repo")"; then
{
echo
echo "WARNING: failed to fetch tags for '$repo'; skipping!"
echo
} >&2
continue
fi
targetFile="$repo/README.md"
{
cat "$helperDir/autogenerated-warning.md"
echo
echo -n "$deprecated"
cat "$helperDir/template.md"
} > "$targetFile"
echo ' TAGS => generate-dockerfile-links-partial.sh "'"$repo"'"'
if [ -z "$partial" ]; then
if [ -n "$ARCH_SPECIFIC_DOCS" ]; then
partial='**No supported tags found!**'$'\n\n''It is very likely that `%%REPO%%` does not support the currently selected architecture (`'"$BASHBREW_ARCH"'`).'
else
echo >&2 'error: missing TAGS for '"$repo"'!'
exit 1
fi
elif [ -n "$ARCH_SPECIFIC_DOCS" ]; then
jenkinsJobUrl="https://doi-janky.infosiftr.net/job/multiarch/job/$BASHBREW_ARCH/job/$repo/"
partial+=$'\n\n''[ (`%%IMAGE%%` build job)]('"$jenkinsJobUrl"')'
fi
replace_field "$targetFile" 'TAGS' "$partial"
echo ' ARCHES => arches.sh "'"$repo"'"'
arches="$("$helperDir/arches.sh" "$repo")"
[ "$arches" ]
replace_field "$targetFile" 'ARCHES' "$arches"
echo ' CONTENT => '"$repo"'/content.md'
replace_field "$targetFile" 'CONTENT' "$(cat "$repo/content.md")"
echo ' VARIANT => variant.sh'
replace_field "$targetFile" 'VARIANT' "$("$helperDir/variant.sh" "$repo")"
# has to be after CONTENT because it's contained in content.md
echo " LOGO => $logo"
replace_field "$targetFile" 'LOGO' "$logo" '\s*'
echo ' STACK => '"$repo"'/stack.md'
replace_field "$targetFile" 'STACK' "$stack"
echo ' STACK-YML => '"$repo"'/stack.yml'
replace_field "$targetFile" 'STACK-YML' "$stackYml"
echo ' STACK-URL => '"$repo"'/stack.yml'
replace_field "$targetFile" 'STACK-URL' "$stackUrl"
echo ' COMPOSE => '"$repo"'/compose.md'
replace_field "$targetFile" 'COMPOSE' "$compose"
echo ' COMPOSE-YML => '"$repo"'/docker-compose.yml'
replace_field "$targetFile" 'COMPOSE-YML' "$composeYml"
echo ' LICENSE => '"$repo"'/license.md'
replace_field "$targetFile" 'LICENSE' "$license"
echo ' ISSUES => "'"$issues"'"'
replace_field "$targetFile" 'ISSUES' "$issues"
echo ' GET-HELP => "'"$getHelp"'"'
replace_field "$targetFile" 'GET-HELP' "$getHelp"
echo ' MAINTAINER => "'"$maintainer"'"'
replace_field "$targetFile" 'MAINTAINER' "$maintainer"
echo ' IMAGE => "'"$image"'"'
replace_field "$targetFile" 'IMAGE' "$image"
echo ' REPO => "'"$repo"'"'
replace_field "$targetFile" 'REPO' "$repo"
echo ' GITHUB-REPO => "'"$githubRepo"'"'
replace_field "$targetFile" 'GITHUB-REPO' "$githubRepo"
echo
else
echo >&2 "skipping $repo: missing repo/content.md"
fi
done