add docs and a portable shell script buildx.sh for pushing the multi-platform Docker image

This commit is contained in:
Kenneth Bingham
2021-04-15 16:22:31 -04:00
parent 2d5dbbd860
commit 39f8f776f5
3 changed files with 107 additions and 10 deletions
+27 -9
View File
@@ -1,4 +1,4 @@
The Dockerfile and scripts in this directory build a ziti-tunnel Docker image.
The Dockerfile and scripts in this directory build a `ziti-tunnel` (Go tunneler) Docker image. This procedure is highly similar to that of the `ziti-edge-tunnel` (C tunneler) Docker image [documented here](https://github.com/openziti/ziti-tunnel-sdk-c/blob/main/docker/BUILD.md).
Ziti binaries are downloaded from https://netfoundry.artifactory.io/netfoundry/ziti-release
by default. The following build arguments are supported:
@@ -47,7 +47,7 @@ the image to a public registry.
3. Create a Builder Instance
$ docker buildx create --use
$ docker buildx create --use --name=ziti-builder
## Building
@@ -66,10 +66,10 @@ Notes:
Unfortunately `buildx` doesn't currently support building images directly into
the local docker cache. Although the `--load` and `--output=type=docker` options
exist, the underlying capability will be implemented in a future docker release
(see https://github.com/docker/buildx/issues/59). In the meantime, you'll need
to push your image builds (with the `--push` build option) and then pull them to
run the image locally when building with `buildx`.
exist, the underlying capability to load a multi-platform image (OCI) will be
implemented in a future Docker release (see https://github.com/docker/buildx/issues/59).
In the meantime, you'll need to push your image builds (with the `--push` build option)
and then pull them to run the image locally when building with `buildx`.
- The armv8 image uses armv7 (32-bit) ziti executables. The 32-bit compatibility
libraries are installed in the image, but your Arm CPU must support 32-bit emulation.
@@ -81,14 +81,32 @@ Notes:
- <https://community.arm.com/developer/tools-software/tools/b/tools-software-ides-blog/posts/getting-started-with-docker-for-arm-on-linux>
- <https://medium.com/@drpdishant/installing-docker-on-fedora-31-a073db823bb8>
# Building for Development
This build method produces an image for the CPU that is running the build host
(typically amd64), and places the resulting image into your local Docker image
cache.
$ ziti_version="0.15.3" \
$ git fetch --tags && git tag -l | sort -Vr | head -1
v0.19.10
$ ziti_version="0.19.10" \
$ docker build \
--build-arg ZITI_VERSION="${ziti_version}" \
-t "netfoundry/ziti-tunnel:${ziti_version}" .
-t "netfoundry/ziti-tunnel:${ziti_version}" .
## Shell Script for Linux
$ ./buildx.sh -h
Usage: VARIABLES ./buildx.sh [OPTION]...
Build multi-platform Docker container image on Linux.
VARIABLES
ZITI_VERSION e.g. "0.16.1" corresponding to Git tag "v0.16.1"
OPTIONS
-r REPO container image repository e.g. netfoundry/ziti-edge-tunnel
-c don't check out v${ZITI_VERSION} (use Git working copy)
EXAMPLES
ZITI_VERSION=0.16.1 ./buildx.sh -r netfoundry/ziti-tunnel
+1 -1
View File
@@ -2,7 +2,7 @@ FROM debian:stable-slim as fetch-ziti-artifacts
# This build stage grabs artifacts that are copied into the final image.
# It uses the same base as the final image to maximize docker cache hits.
ARG ZITI_VERSION="0.18.2"
ARG ZITI_VERSION
ARG ARTIFACTORY_TOKEN
ARG ARTIFACTORY_BASE_URL="https://netfoundry.jfrog.io/netfoundry"
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
set -euo pipefail
_usage(){
cat >&2 <<-EOF
Usage: VARIABLES ./buildx.sh [OPTION]...
Build multi-platform Docker container image on Linux.
VARIABLES
ZITI_VERSION e.g. "0.16.1" corresponding to Git tag "v0.16.1"
OPTIONS
-r REPO container image repository e.g. netfoundry/ziti-edge-tunnel
-c don't check out v\${ZITI_VERSION} (use Git working copy)
EXAMPLES
ZITI_VERSION=0.16.1 ./buildx.sh -c
REFERENCE
https://github.com/openziti/ziti-tunnel-sdk-c/blob/main/docker/BUILD.md
EOF
[[ $# -eq 1 ]] && {
return $1
} || {
return 0
}
}
BASENAME=$(basename $0) || exit $?
DIRNAME=$(dirname $0) || exit $?
while getopts :r:c OPT;do
case $OPT in
r) CONTAINER_REPO=$OPTARG
;;
c) FLAGS+=$OPT # don't checkout vZITI_VERSION
;;
h) _usage; exit 0 # not an error
;;
*|\?) _usage 1 # error
;;
esac
done
shift "$((OPTIND-1))"
# default to latest
: ${ZITI_VERSION:=$(git fetch --quiet --tags && git tag -l|sort -Vr|head -1|sed -E 's/^v(.*)/\1/')}
# required opts
[[ ! -z ${CONTAINER_REPO:+true} ]] || {
echo "ERROR: missing -r REPO option to define container image repository name for image push" >&2
_usage; exit 1
}
if [[ ${FLAGS:-} =~ c ]]; then
echo "WARN: not checking out Git tag v${ZITI_VERSION}"
else
git diff --exit-code # bail if unstaged differences
git fetch --tags
git co v${ZITI_VERSION}
fi
docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64
egrep -q enabled /proc/sys/fs/binfmt_misc/qemu-arm
docker run --rm arm64v8/alpine uname -a|egrep -q 'aarch64 Linux'
docker run --rm arm32v7/alpine uname -a|egrep -q 'armv7l Linux'
docker buildx create --use --name=ziti-builder 2>/dev/null || docker buildx use --default ziti-builder
docker buildx build $DIRNAME \
--platform linux/amd64,linux/arm/v7,linux/arm64 \
--build-arg ZITI_VERSION=${ZITI_VERSION} \
--tag ${CONTAINER_REPO}:${ZITI_VERSION} \
--tag ${CONTAINER_REPO}:latest \
--push
docker buildx stop ziti-builder