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:
yosifkit 2016-06-06 11:26:32 -07:00
commit 92c79c69df
2 changed files with 56 additions and 65 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
set -eo pipefail set -e
repo="$1" repo="$1"
if [ -z "$repo" ]; then if [ -z "$repo" ]; then
@ -8,67 +8,6 @@ if [ -z "$repo" ]; then
exit 1 exit 1
fi fi
IFS=$'\n' bashbrew cat \
lines=( $(curl -fsSL 'https://raw.githubusercontent.com/docker-library/official-images/master/library/'"$repo" | grep -vE '^$|^#') ) -F "$(dirname "$BASH_SOURCE")/$(basename "$BASH_SOURCE" .sh).tmpl" \
unset IFS "https://github.com/docker-library/official-images/raw/master/library/$repo"
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 "[![](https://badge.imagelayers.io/$repo:$latest.svg)]($imageLayers)"
echo

View File

@ -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" -}}
[![](
{{- "https://badge.imagelayers.io/" -}}
{{- /* either "repo:latest" or "repo:first-tag" */ -}}
{{- printf "%s:%s" .RepoName (.Manifest.GetTag "latest" | ternary "latest" ((.Entries | first).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" -}}