Skip to content

Commit

Permalink
Add scripts/files used to generate https://hub.docker.com/r/tianon/gosu
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Apr 9, 2021
1 parent 5169221 commit 549de11
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 0 deletions.
21 changes: 21 additions & 0 deletions hub/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM alpine:3.13

# https://github.com/tianon/gosu/releases
ENV GOSU_VERSION 1.12

RUN set -eux; \
apk add --no-cache --virtual .fetch-deps dpkg gnupg; \
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME"; unset GNUPGHOME; \
apk del --no-network .fetch-deps; \
chmod +x /usr/local/bin/gosu; \
gosu --version; \
gosu nobody true; \
# hard link to / for ease of COPY --from
ln -v /usr/local/bin/gosu /
26 changes: 26 additions & 0 deletions hub/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM debian:buster-slim

# https://github.com/tianon/gosu/releases
ENV GOSU_VERSION 1.12

RUN set -eux; \
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends ca-certificates dirmngr gnupg wget; \
rm -rf /var/lib/apt/lists/*; \
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME"; unset GNUPGHOME; \
apt-mark auto '.*' > /dev/null; \
[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
chmod +x /usr/local/bin/gosu; \
gosu --version; \
gosu nobody true; \
# hard link to / for ease of COPY --from
ln -v /usr/local/bin/gosu /
9 changes: 9 additions & 0 deletions hub/alpine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
image: tianon/gosu:alpine
manifests:
- { image: tianon/gosu:alpine-amd64, platform: { os: linux, architecture: amd64 } }
- { image: tianon/gosu:alpine-arm32v6, platform: { os: linux, architecture: arm, variant: v6 } }
- { image: tianon/gosu:alpine-arm32v7, platform: { os: linux, architecture: arm, variant: v7 } }
- { image: tianon/gosu:alpine-arm64v8, platform: { os: linux, architecture: arm64, variant: v8 } }
- { image: tianon/gosu:alpine-i386, platform: { os: linux, architecture: 386 } }
- { image: tianon/gosu:alpine-ppc64le, platform: { os: linux, architecture: ppc64le } }
- { image: tianon/gosu:alpine-s390x, platform: { os: linux, architecture: s390x } }
65 changes: 65 additions & 0 deletions hub/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
set -Eeuo pipefail

declare -A platforms=(
[amd64]='linux/amd64'
[arm32v5]='linux/arm/v5'
[arm32v6]='linux/arm/v6'
[arm32v7]='linux/arm/v7'
[arm64v8]='linux/arm64/v8'
[i386]='linux/386'
[mips64le]='linux/mips64le'
[ppc64le]='linux/ppc64le'
[s390x]='linux/s390x'
)

declare -A arches=(
[alpine]='amd64 arm32v6 arm32v7 arm64v8 i386 ppc64le s390x'
[debian]='amd64 arm32v5 arm32v7 arm64v8 i386 mips64le ppc64le s390x'
)
preferredOrder=( alpine debian )

_platformToOCI() {
local platform="$1"; shift
local os="${platform%%/*}"
platform="${platform#$os/}"
local architecture="${platform%%/*}"
platform="${platform#$architecture/}"
local variant="$platform"
[ "$architecture" != "$variant" ] || variant=
echo "{ os: $os, architecture: $architecture${variant:+, variant: $variant} }"
}

declare -A latest=()
for variant in "${preferredOrder[@]}"; do
cat > "$variant.yml" <<-EOYAML
image: tianon/gosu:$variant
manifests:
EOYAML
for arch in ${arches[$variant]}; do
platform="${platforms[$arch]}"
docker build --pull --platform "$platform" --tag "tianon/gosu:$variant-$arch" - < "Dockerfile.$variant"
: "${latest[$arch]:=$variant}"
platform="$(_platformToOCI "$platform")"
echo " - { image: tianon/gosu:$variant-$arch, platform: $platform }" >> "$variant.yml"
done
done

cat > latest.yml <<-'EOYAML'
image: tianon/gosu:latest
manifests:
EOYAML
for arch in "${!latest[@]}"; do
variant="${latest[$arch]}"
docker tag "tianon/gosu:$variant-$arch" "tianon/gosu:$arch"
platform="$(_platformToOCI "${platforms[$arch]}")"
echo " - { image: tianon/gosu:$arch, platform: $platform }" >> latest.yml
done

echo
echo '$ # now:'
echo
echo '$ docker push --all-tags tianon/gosu'
for variant in "${preferredOrder[@]}" latest; do
echo "\$ manifest-tool push from-spec $variant.yml"
done
10 changes: 10 additions & 0 deletions hub/debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
image: tianon/gosu:debian
manifests:
- { image: tianon/gosu:debian-amd64, platform: { os: linux, architecture: amd64 } }
- { image: tianon/gosu:debian-arm32v5, platform: { os: linux, architecture: arm, variant: v5 } }
- { image: tianon/gosu:debian-arm32v7, platform: { os: linux, architecture: arm, variant: v7 } }
- { image: tianon/gosu:debian-arm64v8, platform: { os: linux, architecture: arm64, variant: v8 } }
- { image: tianon/gosu:debian-i386, platform: { os: linux, architecture: 386 } }
- { image: tianon/gosu:debian-mips64le, platform: { os: linux, architecture: mips64le } }
- { image: tianon/gosu:debian-ppc64le, platform: { os: linux, architecture: ppc64le } }
- { image: tianon/gosu:debian-s390x, platform: { os: linux, architecture: s390x } }
11 changes: 11 additions & 0 deletions hub/latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
image: tianon/gosu:latest
manifests:
- { image: tianon/gosu:mips64le, platform: { os: linux, architecture: mips64le } }
- { image: tianon/gosu:arm32v5, platform: { os: linux, architecture: arm, variant: v5 } }
- { image: tianon/gosu:arm32v6, platform: { os: linux, architecture: arm, variant: v6 } }
- { image: tianon/gosu:arm32v7, platform: { os: linux, architecture: arm, variant: v7 } }
- { image: tianon/gosu:arm64v8, platform: { os: linux, architecture: arm64, variant: v8 } }
- { image: tianon/gosu:s390x, platform: { os: linux, architecture: s390x } }
- { image: tianon/gosu:ppc64le, platform: { os: linux, architecture: ppc64le } }
- { image: tianon/gosu:i386, platform: { os: linux, architecture: 386 } }
- { image: tianon/gosu:amd64, platform: { os: linux, architecture: amd64 } }

0 comments on commit 549de11

Please sign in to comment.