Skip to content

Commit

Permalink
Improve Docker build for FlowAggregator image (#6388)
Browse files Browse the repository at this point in the history
We have made some improvements to the "main" Antrea Docker images
(Agent, Controller) in the past, which can also benefit the
FlowAggregator image:

* use Docker cache mounts to accelerate builds
* improve layer sharing between images by building antctl first
* install apt packages first in the final image (before copying binaries
  over from the intermediate build image); this improves caching and
  build parallelism.

Signed-off-by: Antonin Bas <[email protected]>
  • Loading branch information
antoninbas authored Jun 3, 2024
1 parent 50cfb7a commit baea218
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
21 changes: 16 additions & 5 deletions build/images/flow-aggregator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,34 @@ FROM golang:${GO_VERSION} as flow-aggregator-build

WORKDIR /antrea

RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download

COPY . /antrea

RUN make flow-aggregator antctl-linux
RUN mv bin/antctl-linux bin/antctl
# Build antctl first in order to share an extra layer with other Antrea Docker images.
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target=/root/.cache/go-build/ \
make antctl-linux && mv bin/antctl-linux bin/antctl

RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target=/root/.cache/go-build/ \
make flow-aggregator

# Chose this base image so that a shell is available for users to exec into the container, run antctl and run tools like pprof easily
FROM ubuntu:22.04

LABEL maintainer="Antrea <[email protected]>"
LABEL description="The docker image for the flow aggregator"

COPY --from=flow-aggregator-build /antrea/bin/flow-aggregator /
COPY --from=flow-aggregator-build /antrea/bin/antctl /usr/local/bin/

# install ca-certificates
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*

COPY --from=flow-aggregator-build /antrea/bin/flow-aggregator /
COPY --from=flow-aggregator-build /antrea/bin/antctl /usr/local/bin/

ENTRYPOINT ["/flow-aggregator"]
16 changes: 11 additions & 5 deletions build/images/flow-aggregator/Dockerfile.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ FROM golang:${GO_VERSION} as flow-aggregator-build

WORKDIR /antrea

COPY go.mod /antrea/go.mod

RUN go mod download

COPY . /antrea

RUN make flow-aggregator-instr-binary antctl-instr-binary
RUN make antctl-instr-binary

RUN make flow-aggregator-instr-binary

FROM ubuntu:22.04

Expand All @@ -28,6 +34,10 @@ LABEL description="The docker image for the flow aggregator with code coverage m

USER root

RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*

COPY --from=flow-aggregator-build /antrea/bin/flow-aggregator-coverage /usr/local/bin/flow-aggregator
COPY --from=flow-aggregator-build /antrea/bin/antctl-coverage /usr/local/bin/antctl
COPY --from=flow-aggregator-build /antrea/test/e2e/utils/run_cov_binary.sh /
Expand All @@ -36,8 +46,4 @@ COPY --from=flow-aggregator-build /antrea/test/e2e/utils/run_cov_binary.sh /
ENV GOCOVERDIR=/tmp/coverage
RUN mkdir -p $GOCOVERDIR

RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/*

ENTRYPOINT [ "/run_cov_binary.sh" ]

0 comments on commit baea218

Please sign in to comment.