Merge pull request #593 from infosiftr/new-bashbrew
Update "generate-dockerfile-links-partial.sh" to utilize new bashbrew features for parsing manifest files
This commit is contained in:
commit
92c79c69df
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
set -eo pipefail
|
||||
set -e
|
||||
|
||||
repo="$1"
|
||||
if [ -z "$repo" ]; then
|
||||
|
|
@ -8,67 +8,6 @@ if [ -z "$repo" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
IFS=$'\n'
|
||||
lines=( $(curl -fsSL 'https://raw.githubusercontent.com/docker-library/official-images/master/library/'"$repo" | grep -vE '^$|^#') )
|
||||
unset IFS
|
||||
|
||||
if [ "${#lines[@]}" -eq 0 ]; then
|
||||
echo >&2 "Failed to read manifest file for $repo"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
repoDirs=()
|
||||
declare -A repoDirTags=()
|
||||
|
||||
latest=
|
||||
uniqImages=()
|
||||
for line in "${lines[@]}"; do
|
||||
tag="$(echo "$line" | awk -F ': +' '{ print $1 }')"
|
||||
if [ -z "$latest" -o "$tag" = 'latest' ]; then
|
||||
latest="$tag"
|
||||
fi
|
||||
repoDir="$(echo "$line" | awk -F ': +' '{ print $2 }')"
|
||||
if [ -z "${repoDirTags[$repoDir]}" ]; then
|
||||
repoDirs+=( "$repoDir" )
|
||||
uniqImages+=( "$repo:$tag" )
|
||||
else
|
||||
repoDirTags["$repoDir"]+=', '
|
||||
fi
|
||||
repoDirTags["$repoDir"]+='`'"$tag"'`'
|
||||
done
|
||||
|
||||
IFS=','
|
||||
imageLayers="https://imagelayers.io/?images=${uniqImages[*]}"
|
||||
unset IFS
|
||||
|
||||
for repoDir in "${repoDirs[@]}"; do
|
||||
if [[ "$repoDir" != *github.com* ]]; then
|
||||
# skip non-github.com for now
|
||||
continue
|
||||
fi
|
||||
|
||||
# split out some data
|
||||
gitUrl="${repoDir%%@*}"
|
||||
commitDir="${repoDir#*@}"
|
||||
commit="${commitDir%% *}"
|
||||
dir="${commitDir#* }"
|
||||
if [ "$dir" = "$commitDir" ]; then
|
||||
dir=''
|
||||
fi
|
||||
|
||||
# sanitize some data
|
||||
gitUrl="${gitUrl#git://}"
|
||||
gitUrl="${gitUrl%/}"
|
||||
gitUrl="${gitUrl%.git}"
|
||||
dir="${dir#/}"
|
||||
dir="${dir%/}"
|
||||
[ -z "$dir" ] || dir="$dir/"
|
||||
|
||||
url="https://$gitUrl/blob/$commit/${dir}Dockerfile"
|
||||
|
||||
echo $'-\t['"${repoDirTags["$repoDir"]}"' (*'"${dir}Dockerfile"'*)]('"$url"')'
|
||||
done
|
||||
|
||||
echo
|
||||
echo "[]($imageLayers)"
|
||||
echo
|
||||
bashbrew cat \
|
||||
-F "$(dirname "$BASH_SOURCE")/$(basename "$BASH_SOURCE" .sh).tmpl" \
|
||||
"https://github.com/docker-library/official-images/raw/master/library/$repo"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
{{- /*
|
||||
|
||||
This template defines the "Supported tags and Dockerfile links" portion of an image description.
|
||||
|
||||
*/ -}}
|
||||
|
||||
{{- define "dockerfilePath" -}}
|
||||
{{- if ne .Directory "." -}}
|
||||
{{- .Directory -}}
|
||||
/
|
||||
{{- end -}}
|
||||
Dockerfile
|
||||
{{- end -}}
|
||||
|
||||
{{- range $i, $e := $.Entries -}}
|
||||
{{- /* force bashbrew to "fetch" the GitCommit so that it is fully resolved */ -}}
|
||||
{{- $from := $.DockerFrom $e -}}
|
||||
|
||||
{{- $repoUrlBase := $e.GitRepo | replace "git://" "https://" | trimSuffixes ".git" -}}
|
||||
{{- $isGitHub := hasPrefix "https://github.com/" $repoUrlBase -}}
|
||||
|
||||
{{- if $i -}}
|
||||
{{- "\n" -}}
|
||||
{{- end -}}
|
||||
|
||||
- {{- "\t" -}}
|
||||
{{- if $isGitHub -}} [ {{- end -}}
|
||||
` {{- $e.Tags | join "`, `" -}} ` (* {{- template "dockerfilePath" $e -}} *)
|
||||
{{- if $isGitHub -}} ]( {{- $repoUrlBase -}} /blob/ {{- $e.GitCommit -}} / {{- template "dockerfilePath" $e -}} ) {{- end -}}
|
||||
{{- /* TODO decide what to do (if anything) about non-GitHub repos with respect to URL */ -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- "\n\n" -}}
|
||||
|
||||
[.Tags | first)) -}}
|
||||
|
||||
{{- ".svg" -}}
|
||||
)](
|
||||
{{- "https://imagelayers.io/?images=" -}}
|
||||
|
||||
{{- /* list all "repo:tag" combinations, comma separated */ -}}
|
||||
{{- range $i, $e := $.Entries -}}
|
||||
{{- if $i -}} , {{- end -}}
|
||||
{{- printf "%s:%s" $.RepoName ($e.Tags | first) -}}
|
||||
{{- end -}}
|
||||
)
|
||||
|
||||
{{- "\n\n" -}}
|
||||
Loading…
Reference in New Issue