Skip to content

Commit

Permalink
Add support for multiple supported upstream architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Jun 18, 2020
1 parent acc3930 commit 551cff2
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions 6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# This image re-bundles the Docker image from the upstream provider, Elastic.
FROM docker.elastic.co/elasticsearch/elasticsearch:6.8.10@sha256:f8e21f6b2ef75dcda374da505fcb0ff4bf7e8d025f12096c498123fa4e372c1b
# Supported Bashbrew Architectures: amd64

# The upstream image was built by:
# https://github.com/elastic/dockerfiles/tree/v6.8.10/elasticsearch
Expand Down
3 changes: 2 additions & 1 deletion 7/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Elasticsearch 7.8.0

# This image re-bundles the Docker image from the upstream provider, Elastic.
FROM docker.elastic.co/elasticsearch/elasticsearch:7.8.0@sha256:ddf17c4027bf3e154b776949a201c188de7c658ea3195ffae352f5771cd51aae
FROM docker.elastic.co/elasticsearch/elasticsearch:7.8.0@sha256:161bc8c7054c622b057324618a2e8bc49ae703e64901b141a16d9c8bdd3b82f9
# Supported Bashbrew Architectures: amd64 arm64v8

# The upstream image was built by:
# https://github.com/elastic/dockerfiles/tree/v7.8.0/elasticsearch
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# This image re-bundles the Docker image from the upstream provider, Elastic.
FROM %%UPSTREAM_IMAGE_DIGEST%%
# Supported Bashbrew Architectures: %%UPSTREAM_IMAGE_ARCHITECTURES%%

# The upstream image was built by:
# %%UPSTREAM_DOCKERFILE_LINK%%
Expand Down
3 changes: 3 additions & 0 deletions generate-stackbrew-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ for version in "${versions[@]}"; do
versionAliases=( $fullVersion )
# TODO decide whether to support X.Y aliases as well

versionArches="$(git show "$commit":"$version/Dockerfile" | awk -F ': ' '$1 == "# Supported Bashbrew Architectures" { print $2; exit }')"

echo
cat <<-EOE
Tags: $(join ', ' "${versionAliases[@]}")
Architectures: $(join ', ' $versionArches)
GitCommit: $commit
Directory: $version
EOE
Expand Down
49 changes: 48 additions & 1 deletion update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,57 @@ for version in "${versions[@]}"; do

# Parse image manifest for sha
authToken="$(curl -fsSL "https://docker-auth.elastic.co/auth?service=token-service&scope=repository:$upstreamImageRepo:pull" | jq -r .token)"
digest="$(curl --head -fsSL -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' -H "Authorization: Bearer $authToken" "https://docker.elastic.co/v2/$upstreamImageRepo/manifests/$fullVersion" | tr -d '\r' | gawk -F ':[[:space:]]+' '$1 == "Docker-Content-Digest" { print $2 }')"
manifestList="$(
curl -D- -fsSL \
-H 'Accept: application/vnd.docker.distribution.manifest.list.v2+json' \
-H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \
-H "Authorization: Bearer $authToken" \
"https://docker.elastic.co/v2/$upstreamImageRepo/manifests/$fullVersion" \
| tr -d '\r'
)"
digest="$(gawk -F ':[[:space:]]+' '$1 == "Docker-Content-Digest" { print $2; exit }' <<<"$manifestList")"
manifestList="$(gawk '/^$/ { pre = 1; next } pre { print }' <<<"$manifestList")"

# Format image reference (image@sha)
upstreamImageDigest="$upstreamImage@$digest"

schemaVersion="$(jq -r '.schemaVersion' <<<"$manifestList")"
[ "$schemaVersion" = 2 ] # sanity check
mediaType="$(jq -r '.mediaType' <<<"$manifestList")"
case "$mediaType" in
'application/vnd.docker.distribution.manifest.v2+json')
upstreamImageArchitectures='amd64'
;;

'application/vnd.docker.distribution.manifest.list.v2+json')
upstreamImageArchitectures="$(
jq -r '
.manifests[].platform
| if .os != "linux" then
.os + "-"
else "" end
+ if .architecture == "arm" then
"arm32"
elif .architecture == "386" then
"i386"
else .architecture end
+ if .variant then
.variant
elif .architecture == "arm64" then
"v8"
else "" end
' <<<"$manifestList" \
| sort -u \
| xargs
)"
;;

*)
echo >&2 "error: unknown media type on '$upstreamImageDigest': '$mediaType'"
exit 1
;;
esac

upstreamDockerfileTag="v$fullVersion"
upstreamDockerfileLink="https://github.com/elastic/dockerfiles/tree/$upstreamDockerfileTag/$upstreamProduct"
upstreamDockerfile="${upstreamDockerfileLink//tree/raw}/Dockerfile"
Expand All @@ -65,6 +111,7 @@ for version in "${versions[@]}"; do

sed -e 's!%%VERSION%%!'"$fullVersion"'!g' \
-e 's!%%UPSTREAM_IMAGE_DIGEST%%!'"$upstreamImageDigest"'!g' \
-e 's!%%UPSTREAM_IMAGE_ARCHITECTURES%%!'"$upstreamImageArchitectures"'!g' \
-e 's!%%UPSTREAM_DOCKERFILE_LINK%%!'"$upstreamDockerfileLink"'!g' \
-e 's!%%UPSTREAM_DOCKER_BUILD%%!'"$upstreamDockerBuild"'!g' \
Dockerfile.template > "$version/Dockerfile"
Expand Down

0 comments on commit 551cff2

Please sign in to comment.