Skip to content

Commit

Permalink
chore(cd): mount package directory at image build time (#13350)
Browse files Browse the repository at this point in the history
This updates our release workflow to use docker's build-time
[bind mount](https://docs.docker.com/reference/dockerfile/#run---mounttypebind)
support to supply the package file(s) instead of copying into the image.

The idea behind this is that mounting the package removes a large `COPY`
layer and reduces the image size.

The directory that is mounted is checksum-ed by docker as part of the build
context, so build cache is automatically invalidated when the package file
changes.
  • Loading branch information
flrgh authored Jul 10, 2024
1 parent 4ab5aa4 commit 4664b90
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ jobs:
platforms: ${{ steps.docker_platforms_arg.outputs.platforms }}
build-args: |
KONG_BASE_IMAGE=${{ matrix.base-image }}
KONG_ARTIFACT_PATH=bazel-bin/pkg/
KONG_ARTIFACT_PATH=bazel-bin/pkg
KONG_VERSION=${{ needs.metadata.outputs.kong-version }}
RPM_PLATFORM=${{ steps.docker_rpm_platform_arg.outputs.rpm_platform }}
EE_PORTS=8002 8445 8003 8446 8004 8447
Expand Down
9 changes: 4 additions & 5 deletions build/dockerfiles/deb.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ ARG EE_PORTS
ARG TARGETARCH

ARG KONG_ARTIFACT=kong.${TARGETARCH}.deb
ARG KONG_ARTIFACT_PATH=
COPY ${KONG_ARTIFACT_PATH}${KONG_ARTIFACT} /tmp/kong.deb
ARG KONG_ARTIFACT_PATH

RUN apt-get update \
RUN --mount=type=bind,source=${KONG_ARTIFACT_PATH},target=/tmp/pkg \
apt-get update \
&& apt-get -y upgrade \
&& apt-get -y autoremove \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata \
&& apt-get install -y --no-install-recommends /tmp/kong.deb \
&& apt-get install -y --no-install-recommends /tmp/pkg/${KONG_ARTIFACT} \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/kong.deb \
&& chown kong:0 /usr/local/bin/kong \
&& chown -R kong:0 ${KONG_PREFIX} \
&& ln -sf /usr/local/openresty/bin/resty /usr/local/bin/resty \
Expand Down
9 changes: 4 additions & 5 deletions build/dockerfiles/rpm.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ ARG EE_PORTS
ARG TARGETARCH

ARG KONG_ARTIFACT=kong.${RPM_PLATFORM}.${TARGETARCH}.rpm
ARG KONG_ARTIFACT_PATH=
COPY ${KONG_ARTIFACT_PATH}${KONG_ARTIFACT} /tmp/kong.rpm
ARG KONG_ARTIFACT_PATH

# hadolint ignore=DL3015
RUN yum update -y \
&& yum install -y /tmp/kong.rpm \
&& rm /tmp/kong.rpm \
RUN --mount=type=bind,source=${KONG_ARTIFACT_PATH},target=/tmp/pkg \
yum update -y \
&& yum install -y /tmp/pkg/${KONG_ARTIFACT} \
&& chown kong:0 /usr/local/bin/kong \
&& chown -R kong:0 /usr/local/kong \
&& ln -sf /usr/local/openresty/bin/resty /usr/local/bin/resty \
Expand Down

1 comment on commit 4664b90

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:4664b907c86cf95d8ad98c7f51dce768c52070c3
Artifacts available https://github.com/Kong/kong/actions/runs/9867820598

Please sign in to comment.