From 09f701eed5a9324c5bf012b85fe2e8c40ec8c69f Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Thu, 10 Nov 2022 15:31:42 +0000 Subject: [PATCH 1/4] update docker files to take advantage of aarch64 binaries also: - cleanup dockerfiles so that we don't do binary copying between images - change base image from distroless to debian:bullseye-slim - unify 3 dockerfiles into 2 --- .circleci/config.yml | 4 +- dockerfiles/Dockerfile.router | 18 +------ dockerfiles/diy/build_docker_image.sh | 8 ++-- .../diy/dockerfiles/Dockerfile.release | 47 ------------------- dockerfiles/diy/dockerfiles/Dockerfile.repo | 14 ++---- 5 files changed, 11 insertions(+), 80 deletions(-) delete mode 100644 dockerfiles/diy/dockerfiles/Dockerfile.release diff --git a/.circleci/config.yml b/.circleci/config.yml index dd64a73ed6..0720801075 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -486,9 +486,7 @@ jobs: name: Docker build command: | ROUTER_TAG=ghcr.io/apollographql/router - # Build debug image - docker build --build-arg ROUTER_RELEASE=${VERSION} --build-arg DEBUG_IMAGE=":debug" -f dockerfiles/Dockerfile.router -t ${ROUTER_TAG}:${VERSION}-debug . - # Build release image + # Build image docker build --build-arg ROUTER_RELEASE=${VERSION} -f dockerfiles/Dockerfile.router -t ${ROUTER_TAG}:${VERSION} . # Note: GH Token owned by apollo-bot2, no expire echo ${GITHUB_OCI_TOKEN} | docker login ghcr.io -u apollo-bot2 --password-stdin diff --git a/dockerfiles/Dockerfile.router b/dockerfiles/Dockerfile.router index 088a4c0e4f..40d475ef3d 100644 --- a/dockerfiles/Dockerfile.router +++ b/dockerfiles/Dockerfile.router @@ -1,6 +1,4 @@ -ARG DEBUG_IMAGE -# Build is required to extract the release files -FROM --platform=linux/amd64 debian:bullseye-slim AS build +FROM debian:bullseye-slim ARG ROUTER_RELEASE=latest @@ -22,23 +20,9 @@ RUN mkdir config schema # Copy configuration for docker image COPY dockerfiles/router.yaml config -# Required so we can copy in libz.so.1 -FROM --platform=linux/amd64 gcr.io/distroless/java17-debian11${DEBUG_IMAGE} as libz-required - -# Final image uses distroless -FROM --platform=linux/amd64 gcr.io/distroless/cc-debian11${DEBUG_IMAGE} - LABEL org.opencontainers.image.authors="Apollo Graph, Inc. https://github.com/apollographql/router" LABEL org.opencontainers.image.source="https://github.com/apollographql/router" -# Copy in the extracted/created files -COPY --from=libz-required /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1 - -WORKDIR /dist - -# Copy in the extracted/created files -COPY --from=build --chown=root:root /dist . - ENV APOLLO_ROUTER_CONFIG_PATH="/dist/config/router.yaml" # Default executable is the router diff --git a/dockerfiles/diy/build_docker_image.sh b/dockerfiles/diy/build_docker_image.sh index 60389a6b38..208f9b756b 100755 --- a/dockerfiles/diy/build_docker_image.sh +++ b/dockerfiles/diy/build_docker_image.sh @@ -122,8 +122,10 @@ fi echo "Building in: ${BUILD_DIR}" # Copy in our dockerfiles, we'll need them later -cp dockerfiles/* "${BUILD_DIR}" || terminate "Couldn't copy dockerfiles to ${BUILD_DIR}" -cp ../router.yaml "${BUILD_DIR}" || terminate "Couldn't copy ../router.yaml to ${BUILD_DIR}" +mkdir "${BUILD_DIR}/dockerfiles" +cp dockerfiles/Dockerfile.repo "${BUILD_DIR}" || terminate "Couldn't copy dockerfiles to ${BUILD_DIR}" +cp ../Dockerfile.router "${BUILD_DIR}" || terminate "Couldn't copy dockerfiles to ${BUILD_DIR}" +cp ../router.yaml "${BUILD_DIR}/dockerfiles" || terminate "Couldn't copy ../router.yaml to ${BUILD_DIR}" # Change to our build directory cd "${BUILD_DIR}" || terminate "Couldn't cd to ${BUILD_DIR}"; @@ -149,7 +151,7 @@ else echo "Building image: ${ROUTER_VERSION}" from released version"" docker build -q -t "router:${ROUTER_VERSION}" \ --build-arg ROUTER_RELEASE="${ROUTER_VERSION}" \ - --no-cache -f Dockerfile.release . \ + --no-cache -f Dockerfile.router . \ || terminate "Couldn't build router image" fi diff --git a/dockerfiles/diy/dockerfiles/Dockerfile.release b/dockerfiles/diy/dockerfiles/Dockerfile.release deleted file mode 100644 index 54c13245d1..0000000000 --- a/dockerfiles/diy/dockerfiles/Dockerfile.release +++ /dev/null @@ -1,47 +0,0 @@ -# Note: We require linux/amd64 images here, because we are definitely -# downloading linux/amd64 images from github and would like our image -# builds to work on platforms such as Mac OS X/M1 (with some help from -# rosetta) -# Build is required to extract the release files -FROM --platform=linux/amd64 debian:bullseye-slim AS build - -ARG ROUTER_RELEASE=latest - -WORKDIR /dist - -# Install curl -RUN \ - apt-get update -y \ - && apt-get install -y \ - curl \ - && rm -rf /var/lib/apt/lists/* - -# Run the Router downloader which puts Router into current working directory -RUN curl -sSL https://router.apollo.dev/download/nix/${ROUTER_RELEASE}/ | sh - -# Make directories for config and schema -RUN mkdir config schema - -# Copy configuration for docker image -COPY router.yaml config - -# Required so we can copy in libz.so.1 -FROM --platform=linux/amd64 gcr.io/distroless/java17-debian11 as libz-required - -# Final image uses distroless. Feel free to change this to an image that suits your needs. -FROM --platform=linux/amd64 gcr.io/distroless/cc-debian11 - -LABEL org.opencontainers.image.authors="Apollo Graph, Inc. https://github.com/apollographql/router" - -# Copy in the extracted/created files -COPY --from=libz-required /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1 - -WORKDIR /dist - -# Copy in the extracted/created files -COPY --from=build --chown=root:root /dist . - -ENV APOLLO_ROUTER_CONFIG_PATH="/dist/config/router.yaml" - -# Default executable is the router -ENTRYPOINT ["/dist/router"] diff --git a/dockerfiles/diy/dockerfiles/Dockerfile.repo b/dockerfiles/diy/dockerfiles/Dockerfile.repo index 296e2eb894..3e0a5b9664 100644 --- a/dockerfiles/diy/dockerfiles/Dockerfile.repo +++ b/dockerfiles/diy/dockerfiles/Dockerfile.repo @@ -28,17 +28,11 @@ RUN mkdir -p /dist/config && \ # Copy configuration for docker image COPY dockerfiles/router.yaml /dist/config -# Required so we can copy in libz.so.1 -FROM --platform=linux/amd64 gcr.io/distroless/java17-debian11 as libz-required +FROM debian:bullseye-slim -# Final image uses distroless. Feel free to change this to an image that suits your needs. -FROM gcr.io/distroless/cc-debian11 - -# Set a label for our image -LABEL org.opencontainers.image.authors="ApolloGraphQL https://github.com/apollographql/router" - -# Copy in the extracted/created files -COPY --from=libz-required /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1 +# Set labels for our image +LABEL org.opencontainers.image.authors="Apollo Graph, Inc. https://github.com/apollographql/router" +LABEL org.opencontainers.image.source="https://github.com/apollographql/router" # Copy in the required files from our build image COPY --from=build --chown=root:root /dist /dist From 43814fb5b81348e617e88d57a8e2231904d9b5c9 Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Thu, 10 Nov 2022 15:48:00 +0000 Subject: [PATCH 2/4] add a changelog --- NEXT_CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 6ed8f7d23f..40bb2ba91e 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -43,4 +43,15 @@ By [@garypen](https://github.com/garypen) and [@Geal](https://github.com/Geal) i ## 🐛 Fixes ## 🛠 Maintenance + +### Use debian:bullseye-slim as our base docker image ([PR #2085](https://github.com/apollographql/router/pull/2085)) + +A while ago, when we added compression support to the router, we discovered that distroless doesn't ship with a copy of `libz.so.1`. We addressed that problem by copying in a version of the library from a distroless image (java) which does ship it. That was ugly. Now, as we try to consider how to add support for both aarch64 and amd64 docker images, that ugliness would expand substantially. + +Rather than persist with this complexity, we've concluded that it would be better to just use a base image which ships with `libz.so.1`, hence the change to `debian:bullseye-slim` + +We'll also stop creating the `-debug` image, since the contents of that image were the same as the main image with the addition of a busybox shell for debugging. Our new base image has a shell, so it's already debuggable. + +By [@garypen](https://github.com/garypen) in https://github.com/apollographql/router/pull/2085 + ## 📚 Documentation From 584ca8a91e5b577b520ae9186292de1fee0c9f5c Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Tue, 15 Nov 2022 09:07:51 +0000 Subject: [PATCH 3/4] add back the debug image As per team feedback. --- .circleci/config.yml | 4 +++- NEXT_CHANGELOG.md | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0720801075..c09d662e03 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -486,7 +486,9 @@ jobs: name: Docker build command: | ROUTER_TAG=ghcr.io/apollographql/router - # Build image + # Build debug image + docker build --build-arg ROUTER_RELEASE=${VERSION} -f dockerfiles/Dockerfile.router -t ${ROUTER_TAG}:${VERSION}-debug . + # Build release image docker build --build-arg ROUTER_RELEASE=${VERSION} -f dockerfiles/Dockerfile.router -t ${ROUTER_TAG}:${VERSION} . # Note: GH Token owned by apollo-bot2, no expire echo ${GITHUB_OCI_TOKEN} | docker login ghcr.io -u apollo-bot2 --password-stdin diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 40bb2ba91e..4f28ed8555 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -50,8 +50,6 @@ A while ago, when we added compression support to the router, we discovered that Rather than persist with this complexity, we've concluded that it would be better to just use a base image which ships with `libz.so.1`, hence the change to `debian:bullseye-slim` -We'll also stop creating the `-debug` image, since the contents of that image were the same as the main image with the addition of a busybox shell for debugging. Our new base image has a shell, so it's already debuggable. - By [@garypen](https://github.com/garypen) in https://github.com/apollographql/router/pull/2085 ## 📚 Documentation From ff2402c711b39d587adb0cc2c6bbf46dc4e56b84 Mon Sep 17 00:00:00 2001 From: Gary Pennington Date: Tue, 15 Nov 2022 09:57:00 +0000 Subject: [PATCH 4/4] Update NEXT_CHANGELOG.md Co-authored-by: Jesse Rosenberger --- NEXT_CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 4f28ed8555..0297d14dfc 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -44,11 +44,11 @@ By [@garypen](https://github.com/garypen) and [@Geal](https://github.com/Geal) i ## 🐛 Fixes ## 🛠 Maintenance -### Use debian:bullseye-slim as our base docker image ([PR #2085](https://github.com/apollographql/router/pull/2085)) +### Use `debian:bullseye-slim` as our base Docker image ([PR #2085](https://github.com/apollographql/router/pull/2085)) -A while ago, when we added compression support to the router, we discovered that distroless doesn't ship with a copy of `libz.so.1`. We addressed that problem by copying in a version of the library from a distroless image (java) which does ship it. That was ugly. Now, as we try to consider how to add support for both aarch64 and amd64 docker images, that ugliness would expand substantially. +A while ago, when we added compression support to the router, we discovered that the Distroless base-images we were using didn't ship with a copy of `libz.so.1`. We addressed that problem by copying in a version of the library from the Distroless image (Java) which does ship it. While that worked, we found challenges in adding support for both `aarch64` and `amd64` Docker images that would make it less than ideal to continue using those Distroless images. -Rather than persist with this complexity, we've concluded that it would be better to just use a base image which ships with `libz.so.1`, hence the change to `debian:bullseye-slim` +Rather than persist with this complexity, we've concluded that it would be better to just use a base image which ships with `libz.so.1`, hence the change to `debian:bullseye-slim`. Those images are still quite minimal and the resulting images are similar in size. By [@garypen](https://github.com/garypen) in https://github.com/apollographql/router/pull/2085