Created
July 12, 2019 03:56
-
-
Save grooverdan/136f7cec0cedf67d13608c797d9eccca to your computer and use it in GitHub Desktop.
build caddy multiarch docker manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -v -x | |
version=v1.0.1 | |
imagebase=caddyserver/caddy:${version} | |
images="" | |
# docker manifest is old, consistent but still experimental (for no great reason) | |
# mkdir -p ~/.docker | |
# echo '{ "experimental" : "enabled" }' > ~/.docker/config.json | |
# echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin | |
# note docker login writes to ~/.docker/config.json | |
build() | |
{ | |
local arch=$1 | |
local os=$2 | |
local img=${imagebase}_${arch}_${os} | |
docker build --tag $img -f - . <<EOF | |
FROM scratch | |
COPY caddy-$os-$arch /caddy | |
EXPOSE 80/tcp 443/tcp 2015/tcp | |
CMD ["/caddy"] | |
EOF | |
docker push $img | |
images="${images} ${img}" | |
} | |
buildall() | |
{ | |
os=$1 | |
shift | |
for arch in $@ | |
do | |
if [ ! -f caddy-$os-$arch ]; then | |
# arm7 hack | |
if [ $arch = arm ]; then | |
wget https://github.com/caddyserver/caddy/releases/download/${version}/caddy_${version}_${os}_${arch}7.tar.gz -O - \ | |
| tar -zxf - caddy | |
else | |
wget https://github.com/caddyserver/caddy/releases/download/${version}/caddy_${version}_${os}_${arch}.tar.gz -O - \ | |
| tar -zxf - caddy | |
fi | |
mv caddy caddy-$os-$arch | |
fi | |
build $arch $os | |
done | |
} | |
# TODO ppc64le s390x (not on github) | |
buildall linux amd64 arm arm64 386 | |
buildall freebsd amd64 | |
buildall openbsd amd64 | |
if [ ! -f caddy-darwin-amd64 ] | |
then | |
wget https://github.com/caddyserver/caddy/releases/download/${version}/caddy_${version}_darwin_amd64.zip | |
unzip caddy_${version}_darwin_amd64.zip caddy | |
mv caddy caddy-darwin-amd64 | |
fi | |
buildall darwin amd64 | |
if [ ! -f caddy.exe ] | |
then | |
wget https://github.com/caddyserver/caddy/releases/download/${version}/caddy_${version}_windows_amd64.zip | |
unzip caddy_${version}_windows_amd64.zip caddy.exe | |
fi | |
## ref https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/manage-windows-dockerfile | |
#img=${imagebase}_amd64_windows | |
#docker build --tag ${imagebase}_amd64_windows -f - . <<EOF | |
#FROM mcr.microsoft.com/windows/servercore:ltsc2019 | |
#COPY caddy.exe /caddy | |
#EXPOSE 80/tcp 443/tcp | |
#CMD ["/caddy.exe"] | |
#EOF | |
#images="${images} ${img}" | |
annotateall() | |
{ | |
os=$1 | |
shift | |
for arch in $@ | |
do | |
docker manifest annotate --arch $arch --os $os ${target} ${imagebase}_${arch}_${os} | |
done | |
} | |
for target in ${imagebase} ${imagebase%:*}:latest | |
do | |
docker manifest create --amend ${imagebase} ${images} | |
annotateall linux amd64 arm arm64 386 | |
annotateall darwin amd64 | |
#annotateall windows amd64 | |
annotateall freebsd amd64 | |
annotateall openbsd amd64 | |
docker manifest inspect ${imagebase} | |
docker manifest push ${imagebase} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment