Skip to content

Commit

Permalink
Build different images for antrea-agent and antrea-controller
Browse files Browse the repository at this point in the history
Signed-off-by: Pulkit Jain <jainpu@vmware.com>
  • Loading branch information
Pulkit Jain committed Jan 23, 2024
1 parent c0c3e25 commit d49c38e
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 4 deletions.
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 <projectantrea-dev@googlegroups.com>"
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 <projectantrea-dev@googlegroups.com>"
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 <projectantrea-dev@googlegroups.com>"
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 <projectantrea-dev@googlegroups.com>"
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 <projectantrea-dev@googlegroups.com>"
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/
42 changes: 42 additions & 0 deletions build/images/Dockerfile.build.controller.ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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
# 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 <projectantrea-dev@googlegroups.com>"
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 d49c38e

Please sign in to comment.