Last active
November 14, 2023 16:06
-
-
Save abscondment/e12fd25b9ada4d4445f8b2e286e5d6cc to your computer and use it in GitHub Desktop.
docker-nginx-unprivileged build/run/test script
This file contains hidden or 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
#!/usr/bin/env bash | |
set -euo pipefail | |
MAINLINE_VERSION=${MAINLINE_VERSION:-1.25.3} | |
STABLE_VERSION=${STABLE_VERSION:-1.24.0} | |
# Platforms based on https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/README.md#architectures | |
ALPINE_PLATFORMS=(amd64 arm/v6 arm/v7 arm64 386 ppc64le s390x) | |
DEBIAN_PLATFORMS=(amd64 arm/v5 arm/v7 arm64 386 mips64le ppc64le s390x) | |
build_image () { | |
directory=$1 | |
platform=$2 | |
tag=$3 | |
container=$(echo ${directory}:${platform} | sed 's/[^a-zA-Z0-9]/_/g') | |
pushd ${directory} | |
DOCKER_BUILDKIT=1 docker build --platform=linux/${platform} -t ${tag} -t ${container} -f Dockerfile . | |
popd | |
} | |
run_image () { | |
directory=$1 | |
platform=$2 | |
container=$(echo ${directory}:${platform} | sed 's/[^a-zA-Z0-9]/_/g') | |
trap 'docker stop ${container}' SIGINT | |
trap 'docker stop ${container}' ERR | |
docker run --platform=linux/${platform} --rm -p 8080:8080 -dt --name ${container} ${container} | |
sleep 1 | |
curl -If http://localhost:8080/ | |
docker stop ${container} | |
trap - SIGINT | |
trap - ERR | |
} | |
set -x | |
for builds in "mainline ${MAINLINE_VERSION}" "stable ${STABLE_VERSION}" | |
do | |
set -- $builds | |
release=$1 | |
version=$2 | |
# ALPINE | |
for platform in ${ALPINE_PLATFORMS[@]} | |
do | |
build_image ${release}/alpine-slim ${platform} nginxinc/nginx-unprivileged:${version}-alpine-slim | |
run_image ${release}/alpine-slim ${platform} | |
build_image ${release}/alpine ${platform} nginxinc/nginx-unprivileged:${version}-alpine | |
run_image ${release}/alpine ${platform} | |
build_image ${release}/alpine-perl ${platform} nginxinc/nginx-unprivileged:${version}-alpine-perl | |
run_image ${release}/alpine-perl ${platform} | |
done | |
# DEBIAN | |
for platform in ${DEBIAN_PLATFORMS[@]} | |
do | |
build_image ${release}/debian ${platform} nginxinc/nginx-unprivileged:${version} | |
run_image ${release}/debian ${platform} | |
build_image ${release}/debian-perl ${platform} nginxinc/nginx-unprivileged:${version}-perl | |
run_image ${release}/debian-perl ${platform} | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment