Skip to content

Commit

Permalink
Publishes multi-architecture Docker images
Browse files Browse the repository at this point in the history
This runs tests with linux/amd64, but publishes linux/amd64,linux/arm64.

Fixes #3141
  • Loading branch information
adriancole committed Oct 30, 2020
1 parent 7724e69 commit b325037
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-tests.yml
Expand Up @@ -46,7 +46,7 @@ jobs:
with:
fetch-depth: 1
- name: Build Docker image openzipkin/${{ matrix.target }}:test
run: docker/build_image ${{ matrix.target }}
run: docker/build_image openzipkin/${{ matrix.target }}:test
- name: Verify Docker image openzipkin/${{ matrix.target }}:test
run: |
# This just makes sure containers run and the HEALTHCHECK works (for now..)
Expand Down
8 changes: 6 additions & 2 deletions .travis.yml
Expand Up @@ -29,7 +29,8 @@ before_install:
# Ensure Docker buildx is available and can build multi-architecture
- |
# Enable experimental features on the server (multi-arch)
echo '{"experimental":"enabled"}' > sudo tee /etc/docker/daemon.json
echo '{"experimental":true}' | sudo tee /etc/docker/daemon.json
sudo service docker restart
# Enable experimental client features (eg docker buildx)
mkdir -p $HOME/.docker && echo '{"experimental":"enabled"}' > $HOME/.docker/config.json
- |
Expand All @@ -38,10 +39,13 @@ before_install:
BUILDX_URL=https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION}/buildx-v${BUILDX_VERSION}.linux-${TRAVIS_CPU_ARCH}
mkdir -p $HOME/.docker/cli-plugins
( cd $HOME/.docker/cli-plugins && wget -qO- $BUILDX_URL > docker-buildx && chmod 755 docker-buildx)
docker version
- |
# Enable execution of different multi-architecture containers by QEMU and binfmt_misc
# See https://github.com/multiarch/qemu-user-static
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
if [ "$(uname -m)" = "x86_64" ]; then
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
fi
docker buildx create --name builder --use
- |
# Use JDK 11, so we can release Java 6 bytecode
Expand Down
8 changes: 4 additions & 4 deletions docker/README.md
Expand Up @@ -97,18 +97,18 @@ If using an external MySQL server or image, ensure schema and other parameters m

## Building images

To build `openzipkin/zipkin:test`, from the top level of the repository, run:
To build `openzipkin/zipkin:test`, from the top-level of the repository, run:
```bash
$ docker/build_image zipkin
$ docker/build_image openzipkin/zipkin:test
```

If you want the slim distribution (openzipkin/zipkin-slim:test), run:
```bash
$ docker/build_image zipkin-slim
$ docker/build_image openzipkin/zipkin-slim:test
```

If you want the NGINX UI proxy (openzipkin/zipkin-ui:test), run:
```bash
$ docker/build_image zipkin-ui
$ docker/build_image openzipkin/zipkin-ui:test
```

4 changes: 4 additions & 0 deletions docker/bin/install.sh
Expand Up @@ -23,6 +23,10 @@ if [ "$RELEASE_FROM_CONTEXT" = "true" ]; then
cp /code/zipkin-slim.jar zipkin-slim.jar
elif [ "$RELEASE_VERSION" = "master" ]; then
echo "*** Building from source..."

# Defensively avoid arm64+alpine problems with posix_spawn
export MAVEN_OPTS="-Djdk.lang.Process.launchMechanism=vfork"

# Use the same command as we suggest in zipkin-server/README.md
# * Uses mvn not ./mvnw to reduce layer size: we control the Maven version in Docker
(cd /code; mvn -T1C -q --batch-mode -DskipTests -Dlicense.skip=true --also-make -pl zipkin-server package)
Expand Down
62 changes: 49 additions & 13 deletions docker/build_image
Expand Up @@ -19,16 +19,41 @@
# Java image mappings and ensures all metadata needed is taken from pom.xml.
set -ue

TARGET=${1:-zipkin}
TAG=${2:-test}
TAG=${1:-openzipkin/zipkin:test}
OP=${2:-load}

TARGET=$(echo $TAG|sed -e 's~.*/\(.*\):.*~\1~g')
# When true, main images reuse zipkin-exec.jar and zipkin-slim.jar in the context root
RELEASE_FROM_CONTEXT=${RELEASE_FROM_CONTEXT:-false}
RELEASE_VERSION=${RELEASE_VERSION:-master}

# When publishing jars, we build with JDK 11 to ensure we can write 1.6 zipkin.jar for Brave.
# However, when creating Docker images, there's no such requirement.
# Hence, we use one version to keep the layer count manageable and centralized here.
JAVA_VERSION=${JAVA_VERSION:-15.0.1-15.28.13}
JAVA_VERSION=${JAVA_VERSION:-15.0.1_p9}

# Arch of the running host. This determines which platform we load into Docker
ARCH=${ARCH:-$(uname -m)}
case ${ARCH} in
x86_64* )
ARCH=amd64
;;
amd64* )
;;
arm64* )
;;
aarch64* )
ARCH=arm64
;;
* )
echo ARCH ${ARCH} not yet supported in this script. export manually to amd64 or report issue.
exit 1
esac

# Platform to load into "docker images"
PLATFORM=${PLATFORM:-linux/${ARCH}}
# Platforms to eventually push to the registry
PLATFORMS="linux/amd64,linux/arm64"

case ${TARGET} in
zipkin )
Expand All @@ -49,7 +74,7 @@ case ${TARGET} in
zipkin-cassandra )
DOCKERFILE_PATH=docker/storage/cassandra/Dockerfile
# Until Cassandra v4, we are stuck on JRE 8 for Cassandra
JAVA_VERSION=8u272-8.50.0.21-jre-headless
JAVA_VERSION=8.252.09
;;
zipkin-elasticsearch6 )
DOCKERFILE_PATH=docker/storage/elasticsearch6/Dockerfile
Expand All @@ -61,15 +86,26 @@ case ${TARGET} in
DOCKERFILE_PATH=docker/storage/mysql/Dockerfile
;;
* )
echo "Invalid TARGET: ${TARGET}"
echo "Invalid TAG: ${TAG}, Ex. openzipkin/zipkin:test"
exit 1
esac

# Build the image
IMAGE=openzipkin/${TARGET}:${TAG}
echo "Building image ${IMAGE} with java_version ${JAVA_VERSION}"
docker build -f "${DOCKERFILE_PATH}" -t "${IMAGE}" \
--build-arg java_version="${JAVA_VERSION}" \
--build-arg release_from_context="${RELEASE_FROM_CONTEXT}" \
--build-arg release_version="${RELEASE_VERSION}" \
--target "${TARGET}" .
BUILDX="docker buildx build --progress plain \
--build-arg release_version=${RELEASE_VERSION} --label zipkin-version=${RELEASE_VERSION} \
--build-arg release_from_context=${RELEASE_FROM_CONTEXT} \
--build-arg java_version=${JAVA_VERSION}"

case ${OP} in
load )
# We can only load with one platform/arch https://github.com/docker/buildx/issues/59
echo "Building image ${TAG} with platform ${PLATFORM} and Java version ${JAVA_VERSION}"
${BUILDX} --target ${TARGET} --tag ${TAG} --platform=${PLATFORM} -f ${DOCKERFILE_PATH} . --load
;;
push )
echo "Pushing image ${TAG} with platforms ${PLATFORMS} and Java version ${JAVA_VERSION}"
${BUILDX} --target ${TARGET} --tag ${TAG} --platform=${PLATFORMS} -f ${DOCKERFILE_PATH} . --push
;;
* )
echo "Invalid OP: ${OP}, Ex. load or push"
exit 1
esac
11 changes: 2 additions & 9 deletions docker/builder/README.md
Expand Up @@ -3,16 +3,9 @@
This image is for internal use only for building other Docker images. It refreshes a
cache of maven and npm dependencies so downstream builds do not have to do so every build.

Normally, zipkin-builder is updated as part of the normal master build of zipkin-server. This
means it accumulates old dependencies over time. If the image disappears for any reason, or it has
accumulated too much cruft, it can be refreshed with the following:

This is rebuilt on master push, but can be republished manually like this:
```bash
# Build the builder and publish it
$ docker/build_image zipkin-builder latest
$ docker tag openzipkin/zipkin-builder ghcr.io/openzipkin/zipkin-builder
$ echo "$GH_TOKEN"| docker login ghcr.io -u "$GH_USER" --password-stdin
$ docker push ghcr.io/openzipkin/zipkin-builder
$ docker/build_image ghcr.io/openzipkin/zipkin-builder:latest push
```

We'll add a weekly cron at some point to do this automatically.
4 changes: 2 additions & 2 deletions docker/collector/kafka/README.md
Expand Up @@ -3,9 +3,9 @@
The `zipkin-kafka` testing image runs both Kafka+ZooKeeper for the [Kafka collector](../../../zipkin-collector/kafka)
and the upcoming [Kafka storage](https://github.com/openzipkin-contrib/zipkin-storage-kafka).

To build `openzipkin/zipkin-kafka:test`, from the top level of the repository, run:
To build `openzipkin/zipkin-kafka:test`, from the top-level of the repository, run:
```bash
$ docker/build_image zipkin-kafka
$ docker/build_image openzipkin/zipkin-kafka:test
```

Then configure the [Kafka sender](https://github.com/openzipkin/zipkin-reporter-java/blob/master/kafka/src/main/java/zipkin2/reporter/kafka/KafkaSender.java) using a `bootstrapServers` value of `host.docker.internal:9092` if your application is inside the same docker network or `localhost:19092` if not, but running on the same host.
Expand Down
2 changes: 1 addition & 1 deletion docker/hooks/build
Expand Up @@ -29,7 +29,7 @@ fi
# build command ourselves works fine.

# This hook is called with the current directory set to the same as the Dockerfile, so we go back
# to top level.
# to top-level.
cd ..

echo "Building images for ${SOURCE_BRANCH}"
Expand Down
2 changes: 1 addition & 1 deletion docker/hooks/push
Expand Up @@ -26,7 +26,7 @@ if [ "${DOCKER_TAG}" = "master" ]; then
fi

# This hook is called with the current directory set to the same as the Dockerfile, so we go back
# to top level.
# to top-level.
cd ..

if [ "${DOCKER_REPO}" = "index.docker.io/openzipkin/zipkin" ]; then
Expand Down
2 changes: 1 addition & 1 deletion docker/lens/README.md
Expand Up @@ -2,7 +2,7 @@

The `zipkin-ui` testing image contains the static parts of the Zipkin UI served directly with NGINX.

To build `openzipkin/zipkin-ui:test`, from the top level of the repository, run:
To build `openzipkin/zipkin-ui:test`, from the top-level of the repository, run:
```bash
$ docker/build_image zipkin-ui
```
4 changes: 2 additions & 2 deletions docker/storage/cassandra/Dockerfile
Expand Up @@ -25,7 +25,7 @@ COPY docker/storage/cassandra/install.sh /install/
COPY docker/storage/cassandra/docker-bin/* /docker-bin/

# Until Cassandra supports recent JDKs, we can't re-use our builder
FROM ghcr.io/openzipkin/java:${java_version} as install
FROM ghcr.io/openzipkin/java:${java_version}-jre as install

# Use latest stable release here.
ENV CASSANDRA_VERSION=3.11.8
Expand All @@ -36,7 +36,7 @@ COPY --from=scratch /zipkin-schemas/* ./zipkin-schemas/
COPY --from=scratch /install/install.sh /tmp/
RUN /tmp/install.sh && rm /tmp/install.sh

FROM ghcr.io/openzipkin/java:${java_version} as zipkin-cassandra
FROM ghcr.io/openzipkin/java:${java_version}-jre as zipkin-cassandra

# Add HEALTHCHECK and ENTRYPOINT scripts into the default search path
COPY --from=scratch /docker-bin/* /usr/local/bin/
Expand Down
4 changes: 2 additions & 2 deletions docker/storage/cassandra/README.md
Expand Up @@ -3,7 +3,7 @@
The `zipkin-cassandra` testing image runs Cassandra 3.11.x initialized with Zipkin's schema for
[Cassandra storage](../../../zipkin-storage/cassandra) integration.

To build `openzipkin/zipkin-cassandra:test`, from the top level of the repository, run:
To build `openzipkin/zipkin-cassandra:test`, from the top-level of the repository, run:
```bash
$ docker/build_image zipkin-cassandra
$ docker/build_image openzipkin/zipkin-cassandra:test
```
4 changes: 2 additions & 2 deletions docker/storage/elasticsearch6/README.md
Expand Up @@ -3,9 +3,9 @@
The `zipkin-elasticsearch6` testing image runs Elasticsearch 6.x for [Elasticsearch storage](../../../zipkin-storage/elasticsearch)
integration.

To build `openzipkin/zipkin-elasticsearch6:test`, from the top level of the repository, run:
To build `openzipkin/zipkin-elasticsearch6:test`, from the top-level of the repository, run:
```bash
$ docker/build_image zipkin-elasticsearch6
$ docker/build_image openzipkin/zipkin-elasticsearch6:test
```

You can use the env variable `JAVA_OPTS` to change settings such as heap size for Elasticsearch.
Expand Down
4 changes: 2 additions & 2 deletions docker/storage/elasticsearch7/README.md
Expand Up @@ -3,9 +3,9 @@
The `zipkin-elasticsearch7` testing image runs Elasticsearch 7.x for [Elasticsearch storage](../../../zipkin-storage/elasticsearch)
integration.

To build `openzipkin/zipkin-elasticsearch7:test`, from the top level of the repository, run:
To build `openzipkin/zipkin-elasticsearch7:test`, from the top-level of the repository, run:
```bash
$ docker/build_image zipkin-elasticsearch7
$ docker/build_image openzipkin/zipkin-elasticsearch7:test
```

You can use the env variable `JAVA_OPTS` to change settings such as heap size for Elasticsearch.
Expand Down
5 changes: 2 additions & 3 deletions docker/storage/mysql/README.md
Expand Up @@ -3,10 +3,9 @@
The `zipkin-mysql` testing image runs MySQL 3.11.x initialized with Zipkin's schema for
[MySQL storage](../../../zipkin-storage/mysql-v1) integration.

To build `openzipkin/zipkin-mysql`, from the top level of the repository, run:

To build `openzipkin/zipkin-mysql:test`, from the top-level of the repository, run:
```bash
$ docker build -t openzipkin/zipkin-mysql:test -f docker/storage/mysql/Dockerfile .
$ docker/build_image openzipkin/zipkin-mysql:test
```

When running with docker-machine, you can connect like so:
Expand Down
2 changes: 1 addition & 1 deletion travis/publish.sh
Expand Up @@ -72,7 +72,7 @@ check_release_tag() {
}

print_project_version() {
./mvnw help:evaluate -N -Dexpression=project.version|sed -n '/^[0-9]/p'
./mvnw help:evaluate -N -Dexpression=project.version -q -DforceStdout
}

is_release_commit() {
Expand Down

0 comments on commit b325037

Please sign in to comment.