Skip to content

Commit

Permalink
Build different images for antrea-agent and antrea-controller (antrea…
Browse files Browse the repository at this point in the history
…-io#5902)

This helps reduce image sizes, leading to a better user experience
when installing Antrea.

For antrea-io#5691 

---------

Signed-off-by: Pulkit Jain <[email protected]>
Signed-off-by: Antonin Bas <[email protected]>
Co-authored-by: Antonin Bas <[email protected]>
  • Loading branch information
jainpulkit22 and antoninbas authored Jan 23, 2024
1 parent 053751d commit 18dc013
Show file tree
Hide file tree
Showing 10 changed files with 400 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ jobs:
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
./hack/build-antrea-linux-all.sh --pull --push-base-images
docker tag antrea/antrea-ubuntu:latest antrea/antrea-ubuntu-amd64:latest
docker tag antrea/antrea-controller-ubuntu:latest antrea/antrea-controller-ubuntu-amd64:latest
docker tag antrea/antrea-agent-ubuntu:latest antrea/antrea-agent-ubuntu-amd64:latest
docker push antrea/antrea-ubuntu-amd64:latest
docker push antrea/antrea-controller-ubuntu-amd64:latest
docker push antrea/antrea-agent-ubuntu-amd64:latest
- name: Trigger Antrea arm builds and multi-arch manifest update
if: ${{ github.repository == 'antrea-io/antrea' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: benc-uk/workflow-dispatch@v1
Expand Down Expand Up @@ -81,6 +85,8 @@ jobs:
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
./hack/build-antrea-linux-all.sh --pull --push-base-images --distro ubi
docker push antrea/antrea-ubi:latest
docker push antrea/antrea-agent-ubi:latest
docker push antrea/antrea-controller-ubi:latest
build-scale:
needs: check-changes
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/build_tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ jobs:
./hack/build-antrea-linux-all.sh --pull
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker tag antrea/antrea-ubuntu:"${VERSION}" antrea/antrea-ubuntu-amd64:"${VERSION}"
docker tag antrea/antrea-agent-ubuntu:"${VERSION}" antrea/antrea-agent-ubuntu-amd64:"${VERSION}"
docker tag antrea/antrea-controller-ubuntu:"${VERSION}" antrea/antrea-controller-ubuntu-amd64:"${VERSION}"
docker push antrea/antrea-ubuntu-amd64:"${VERSION}"
docker push antrea/antrea-agent-ubuntu-amd64:"${VERSION}"
docker push antrea/antrea-controller-ubuntu-amd64:"${VERSION}"
- name: Trigger Antrea arm builds and multi-arch manifest update
uses: benc-uk/workflow-dispatch@v1
with:
Expand All @@ -61,6 +65,8 @@ jobs:
./hack/build-antrea-linux-all.sh --pull --distro ubi
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push antrea/antrea-ubi:"${VERSION}"
docker push antrea/antrea-agent-ubi:"${VERSION}"
docker push antrea/antrea-controller-ubi:"${VERSION}"
build-windows:
runs-on: [windows-2019]
Expand Down
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ else
endif
docker tag antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) antrea/antrea-ubuntu

.PHONY: build-controller-ubuntu
build-controller-ubuntu:
@echo "===> Building antrea/antrea-controller-ubuntu Docker image <==="
ifneq ($(NO_PULL),)
docker build -t antrea/antrea-controller-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.controller.ubuntu $(DOCKER_BUILD_ARGS) .
else
docker build --pull -t antrea/antrea-controller-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.controller.ubuntu $(DOCKER_BUILD_ARGS) .
endif
docker tag antrea/antrea-controller-ubuntu:$(DOCKER_IMG_VERSION) antrea/antrea-controller-ubuntu

.PHONY: build-agent-ubuntu
build-agent-ubuntu:
@echo "===> Building antrea/antrea-agent-ubuntu Docker image <==="
ifneq ($(NO_PULL),)
docker build -t antrea/antrea-agent-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.agent.ubuntu $(DOCKER_BUILD_ARGS) .
else
docker build --pull -t antrea/antrea-agent-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.agent.ubuntu $(DOCKER_BUILD_ARGS) .
endif
docker tag antrea/antrea-agent-ubuntu:$(DOCKER_IMG_VERSION) antrea/antrea-agent-ubuntu

# Build bins in a golang container, and build the antrea-ubuntu Docker image.
.PHONY: build-ubuntu
build-ubuntu:
Expand All @@ -354,6 +374,26 @@ else
endif
docker tag antrea/antrea-ubi:$(DOCKER_IMG_VERSION) antrea/antrea-ubi

.PHONY: build-agent-ubi
build-agent-ubi:
@echo "===> Building Antrea bins and antrea/antrea-agent-ubi Docker image <==="
ifneq ($(NO_PULL),"")
docker build -t antrea/antrea-agent-ubi:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.agent.ubi $(DOCKER_BUILD_ARGS) .
else
docker build --pull -t antrea/antrea-agent-ubi:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.agent.ubi $(DOCKER_BUILD_ARGS) .
endif
docker tag antrea/antrea-agent-ubi:$(DOCKER_IMG_VERSION) antrea/antrea-agent-ubi

.PHONY: build-controller-ubi
build-controller-ubi:
@echo "===> Building Antrea bins and antrea/antrea-controller-ubi Docker image <==="
ifneq ($(NO_PULL),"")
docker build -t antrea/antrea-controller-ubi:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.controller.ubi $(DOCKER_BUILD_ARGS) .
else
docker build --pull -t antrea/antrea-controller-ubi:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.controller.ubi $(DOCKER_BUILD_ARGS) .
endif
docker tag antrea/antrea-controller-ubi:$(DOCKER_IMG_VERSION) antrea/antrea-controller-ubi

.PHONY: build-windows
build-windows:
@echo "===> Building Antrea bins and antrea/antrea-windows Docker image <==="
Expand All @@ -374,6 +414,26 @@ else
endif
docker tag antrea/antrea-ubuntu-coverage:$(DOCKER_IMG_VERSION) antrea/antrea-ubuntu-coverage

.PHONY: build-controller-ubuntu-coverage
build-controller-ubuntu-coverage:
@echo "===> Building Antrea bins and antrea/antrea-controller-ubuntu-coverage Docker image <==="
ifneq ($(NO_PULL),)
docker build -t antrea/antrea-controller-ubuntu-coverage:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.controller.coverage $(DOCKER_BUILD_ARGS) .
else
docker build --pull -t antrea/antrea-controller-ubuntu-coverage:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.controller.coverage $(DOCKER_BUILD_ARGS) .
endif
docker tag antrea/antrea-controller-ubuntu-coverage:$(DOCKER_IMG_VERSION) antrea/antrea-controller-ubuntu-coverage

.PHONY: build-agent-ubuntu-coverage
build-agent-ubuntu-coverage:
@echo "===> Building Antrea bins and antrea/antrea-agent-ubuntu-coverage Docker image <==="
ifneq ($(NO_PULL),)
docker build -t antrea/antrea-agent-ubuntu-coverage:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.agent.coverage $(DOCKER_BUILD_ARGS) .
else
docker build --pull -t antrea/antrea-agent-ubuntu-coverage:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.agent.coverage $(DOCKER_BUILD_ARGS) .
endif
docker tag antrea/antrea-agent-ubuntu-coverage:$(DOCKER_IMG_VERSION) antrea/antrea-agent-ubuntu-coverage

.PHONY: build-scale-simulator
build-scale-simulator:
@echo "===> Building simulator bin and antrea-ubuntu-simulator image"
Expand Down
47 changes: 47 additions & 0 deletions build/images/Dockerfile.build.agent.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2024 Antrea Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG GO_VERSION
ARG BUILD_TAG
FROM golang:${GO_VERSION} as antrea-build

WORKDIR /antrea

COPY go.mod /antrea/go.mod

RUN go mod download

COPY . /antrea

RUN make antrea-agent antrea-cni antrea-agent-instr-binary
# Disable CGO for antctl in case it is copied outside of the container image. It
# also reduces the size of the binary and aligns with how we distribute antctl
# in release assets.
RUN CGO_ENABLED=0 make antctl-linux antctl-instr-binary
RUN mv bin/antctl-linux bin/antctl

FROM antrea/base-ubuntu:${BUILD_TAG}

LABEL maintainer="Antrea <[email protected]>"
LABEL description="The Docker image to deploy the antrea-agent with code coverage measurement enabled (used for testing)."

USER root

COPY build/images/scripts/* /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antrea-agent /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antrea-agent-coverage /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antrea-cni /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antctl /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antctl-coverage /usr/local/bin/
COPY --from=antrea-build /antrea/test/e2e/coverage/agent-arg-file /
65 changes: 65 additions & 0 deletions build/images/Dockerfile.build.agent.ubi
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2024 Antrea Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG BUILD_TAG
FROM registry.access.redhat.com/ubi8 as antrea-build

ADD https://go.dev/dl/?mode=json&include=all go-versions.json

RUN yum install ca-certificates gcc git jq make wget -y

ARG GO_VERSION

# GO_VERSION is a Go minor version, we use the downloaded go-versions.json file
# to identify and install the latest patch release for this minor version.
RUN set -eux; \
arch="$(uname -m)"; \
case "${arch##*-}" in \
x86_64) goArch='amd64' ;; \
arm) goArch='armv6l' ;; \
aarch64) goArch='arm64' ;; \
*) goArch=''; echo >&2; echo >&2 "unsupported architecture '$arch'"; echo >&2 ; exit 1 ;; \
esac; \
GO_ARCHIVE=$(jq --arg version_prefix "go${GO_VERSION}." --arg arch "$goArch" -r '. | map(select(. | .version | startswith($version_prefix))) | first | .files[] | select(.os == "linux" and .arch == $arch and .kind == "archive").filename' go-versions.json); \
wget -q -O - https://go.dev/dl/${GO_ARCHIVE} | tar xz -C /usr/local/

# Using ENV makes the change persistent, but this is just a builder image.
ENV PATH /usr/local/go/bin:$PATH

WORKDIR /antrea

COPY go.mod /antrea/go.mod

RUN go mod download

COPY . /antrea

RUN make antrea-agent antrea-cni
# Disable CGO for antctl in case it is copied outside of the container image. It
# also reduces the size of the binary and aligns with how we distribute antctl
# in release assets.
RUN CGO_ENABLED=0 make antctl-linux
RUN mv bin/antctl-linux bin/antctl

FROM antrea/base-ubi:${BUILD_TAG}

LABEL maintainer="Antrea <[email protected]>"
LABEL description="The Docker image to deploy the antrea-agent."

USER root

COPY build/images/scripts/* /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antrea-agent /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antrea-cni /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antctl /usr/local/bin/
44 changes: 44 additions & 0 deletions build/images/Dockerfile.build.agent.ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 Antrea Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG GO_VERSION
ARG BUILD_TAG
FROM golang:${GO_VERSION} as antrea-build

WORKDIR /antrea

COPY go.mod /antrea/go.mod

RUN go mod download

COPY . /antrea

RUN make antrea-agent antrea-cni
# Disable CGO for antctl in case it is copied outside of the container image. It
# also reduces the size of the binary and aligns with how we distribute antctl
# in release assets.
RUN CGO_ENABLED=0 make antctl-linux
RUN mv bin/antctl-linux bin/antctl

FROM antrea/base-ubuntu:${BUILD_TAG}

LABEL maintainer="Antrea <[email protected]>"
LABEL description="The Docker image to deploy the antrea-agent."

USER root

COPY build/images/scripts/* /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antrea-agent /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antrea-cni /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antctl /usr/local/bin/
45 changes: 45 additions & 0 deletions build/images/Dockerfile.build.controller.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2024 Antrea Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG GO_VERSION
ARG BUILD_TAG
FROM golang:${GO_VERSION} as antrea-build

WORKDIR /antrea

COPY go.mod /antrea/go.mod

RUN go mod download

COPY . /antrea

RUN make antrea-controller antrea-controller-instr-binary
# Disable CGO for antctl in case it is copied outside of the container image. It
# also reduces the size of the binary and aligns with how we distribute antctl
# in release assets.
RUN CGO_ENABLED=0 make antctl-linux antctl-instr-binary
RUN mv bin/antctl-linux bin/antctl

FROM ubuntu:22.04

LABEL maintainer="Antrea <[email protected]>"
LABEL description="The Docker image to deploy the antrea-controller with code coverage measurement enabled (used for testing)."

USER root

COPY --from=antrea-build /antrea/bin/antrea-controller /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antctl /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antrea-controller-coverage /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antctl-coverage /usr/local/bin/
COPY --from=antrea-build /antrea/test/e2e/coverage/controller-arg-file /
63 changes: 63 additions & 0 deletions build/images/Dockerfile.build.controller.ubi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2024 Antrea Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG BUILD_TAG
FROM registry.access.redhat.com/ubi8 as antrea-build

ADD https://go.dev/dl/?mode=json&include=all go-versions.json

RUN yum install ca-certificates gcc git jq make wget -y

ARG GO_VERSION

# GO_VERSION is a Go minor version, we use the downloaded go-versions.json file
# to identify and install the latest patch release for this minor version.
RUN set -eux; \
arch="$(uname -m)"; \
case "${arch##*-}" in \
x86_64) goArch='amd64' ;; \
arm) goArch='armv6l' ;; \
aarch64) goArch='arm64' ;; \
*) goArch=''; echo >&2; echo >&2 "unsupported architecture '$arch'"; echo >&2 ; exit 1 ;; \
esac; \
GO_ARCHIVE=$(jq --arg version_prefix "go${GO_VERSION}." --arg arch "$goArch" -r '. | map(select(. | .version | startswith($version_prefix))) | first | .files[] | select(.os == "linux" and .arch == $arch and .kind == "archive").filename' go-versions.json); \
wget -q -O - https://go.dev/dl/${GO_ARCHIVE} | tar xz -C /usr/local/

# Using ENV makes the change persistent, but this is just a builder image.
ENV PATH /usr/local/go/bin:$PATH

WORKDIR /antrea

COPY go.mod /antrea/go.mod

RUN go mod download

COPY . /antrea

RUN make antrea-controller
# Disable CGO for antctl in case it is copied outside of the container image. It
# also reduces the size of the binary and aligns with how we distribute antctl
# in release assets.
RUN CGO_ENABLED=0 make antctl-linux
RUN mv bin/antctl-linux bin/antctl

FROM ubuntu:22.04

LABEL maintainer="Antrea <[email protected]>"
LABEL description="The Docker image to deploy the antrea-controller."

USER root

COPY --from=antrea-build /antrea/bin/antctl /usr/local/bin/
COPY --from=antrea-build /antrea/bin/antrea-controller /usr/local/bin/
Loading

0 comments on commit 18dc013

Please sign in to comment.