diff --git a/Makefile b/Makefile index e612daeb145..ac99ab7dfd1 100644 --- a/Makefile +++ b/Makefile @@ -332,6 +332,26 @@ else endif docker tag antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) antrea/antrea-ubuntu +.PHONY: build-ubuntu-controller +build-ubuntu-controller: + @echo "===> Building antrea/antrea-ubuntu Docker image <===" +ifneq ($(NO_PULL),) + docker build -t antrea/antrea-controller-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubuntu.controller $(DOCKER_BUILD_ARGS) . +else + docker build --pull -t antrea/antrea-controller-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubuntu.controller $(DOCKER_BUILD_ARGS) . +endif + docker tag antrea/antrea-controller-ubuntu:$(DOCKER_IMG_VERSION) antrea/antrea-controller-ubuntu + +.PHONY: build-ubuntu-agent +build-ubuntu-agent: + @echo "===> Building antrea/antrea-ubuntu Docker image <===" +ifneq ($(NO_PULL),) + docker build -t antrea/antrea-agent-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubuntu.agent $(DOCKER_BUILD_ARGS) . +else + docker build --pull -t antrea/antrea-agent-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubuntu.agent $(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: diff --git a/build/images/Dockerfile.build.ubuntu b/build/images/Dockerfile.build.ubuntu index 8ac916b6969..c7958a37cd1 100644 --- a/build/images/Dockerfile.build.ubuntu +++ b/build/images/Dockerfile.build.ubuntu @@ -31,7 +31,7 @@ RUN make antrea-agent antrea-controller antrea-cni RUN CGO_ENABLED=0 make antctl-linux RUN mv bin/antctl-linux bin/antctl -FROM antrea/base-ubuntu:${BUILD_TAG} +FROM antrea/unified-base-ubuntu:${BUILD_TAG} LABEL maintainer="Antrea " LABEL description="The Docker image to deploy the Antrea CNI." diff --git a/build/images/Dockerfile.build.ubuntu.agent b/build/images/Dockerfile.build.ubuntu.agent new file mode 100644 index 00000000000..582cd5638e4 --- /dev/null +++ b/build/images/Dockerfile.build.ubuntu.agent @@ -0,0 +1,42 @@ +# Copyright 2023 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/agent-base-ubuntu:${BUILD_TAG} + +LABEL maintainer="Antrea " +LABEL description="The Docker image to deploy the Antrea CNI." + +USER root + +COPY build/images/scripts/* /usr/local/bin/ +COPY --from=antrea-build /antrea/bin/* /usr/local/bin/ diff --git a/build/images/Dockerfile.build.ubuntu.controller b/build/images/Dockerfile.build.ubuntu.controller new file mode 100644 index 00000000000..f317b10ecbf --- /dev/null +++ b/build/images/Dockerfile.build.ubuntu.controller @@ -0,0 +1,42 @@ +# Copyright 2023 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 antrea/controller-base-ubuntu:${BUILD_TAG} + +LABEL maintainer="Antrea " +LABEL description="The Docker image to deploy the Antrea CNI." + +USER root + +COPY build/images/scripts/* /usr/local/bin/ +COPY --from=antrea-build /antrea/bin/* /usr/local/bin/ diff --git a/build/images/base/Dockerfile.controller b/build/images/base/Dockerfile.controller new file mode 100644 index 00000000000..71bbde04584 --- /dev/null +++ b/build/images/base/Dockerfile.controller @@ -0,0 +1,29 @@ +# Copyright 2023 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 ubuntu:22.04 as cni-binaries + +RUN apt-get update && \ + apt-get install -y --no-install-recommends wget ca-certificates + +# Download containernetworking plugin binaries for the correct architecture +RUN set -eux; \ + dpkgArch="$(dpkg --print-architecture)"; \ + case "${dpkgArch##*-}" in \ + amd64) pluginsArch='amd64' ;; \ + armhf) pluginsArch='arm' ;; \ + arm64) pluginsArch='arm64' ;; \ + *) pluginsArch=''; echo >&2; echo >&2 "unsupported architecture '$dpkgArch'"; echo >&2 ; exit 1 ;; \ + esac; diff --git a/build/images/base/build.sh b/build/images/base/build.sh index 36d282345fe..d6d8d9e349c 100755 --- a/build/images/base/build.sh +++ b/build/images/base/build.sh @@ -28,7 +28,8 @@ Build the antrea base image. --pull Always attempt to pull a newer version of the base images --push Push the built image to the registry --platform Target platform for the image if server is multi-platform capable - --distro Target Linux distribution" + --distro Target Linux distribution + --type Type of image, whether it is for agent, ontroller or unified" function print_usage { echoerr "$_usage" @@ -38,6 +39,7 @@ PULL=false PUSH=false PLATFORM="" DISTRO="ubuntu" +TYPE="unified" while [[ $# -gt 0 ]] do @@ -60,6 +62,10 @@ case $key in DISTRO="$2" shift 2 ;; + --type) + TYPE="$2" + shift 2 + ;; -h|--help) print_usage exit 0 @@ -129,29 +135,73 @@ if $PULL; then done fi -docker build $PLATFORM_ARG --target cni-binaries \ - --cache-from antrea/cni-binaries:$CNI_BINARIES_VERSION \ - -t antrea/cni-binaries:$CNI_BINARIES_VERSION \ - --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ - --build-arg BUILD_TAG=$BUILD_TAG . - -if [ "$DISTRO" == "ubuntu" ]; then - docker build $PLATFORM_ARG \ - --cache-from antrea/cni-binaries:$CNI_BINARIES_VERSION \ - --cache-from antrea/base-ubuntu:$BUILD_TAG \ - -t antrea/base-ubuntu:$BUILD_TAG \ - --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ - --build-arg SURICATA_VERSION=$SURICATA_VERSION \ - --build-arg BUILD_TAG=$BUILD_TAG . -elif [ "$DISTRO" == "ubi" ]; then - docker build $PLATFORM_ARG \ - --cache-from antrea/cni-binaries:$CNI_BINARIES_VERSION \ - --cache-from antrea/base-ubi:$BUILD_TAG \ - -t antrea/base-ubi:$BUILD_TAG \ - -f Dockerfile.ubi \ - --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ - --build-arg SURICATA_VERSION=$SURICATA_VERSION \ - --build-arg BUILD_TAG=$BUILD_TAG . +if [ "$TYPE" == "unified" ]; then + docker build $PLATFORM_ARG --target cni-binaries \ + --cache-from antrea/cni-binaries:$CNI_BINARIES_VERSION \ + -t antrea/cni-binaries:$CNI_BINARIES_VERSION \ + --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ + --build-arg BUILD_TAG=$BUILD_TAG . + + if [ "$DISTRO" == "ubuntu" ]; then + docker build $PLATFORM_ARG \ + --cache-from antrea/cni-binaries:$CNI_BINARIES_VERSION \ + --cache-from antrea/base-ubuntu:$BUILD_TAG \ + -t antrea/unified-base-ubuntu:$BUILD_TAG \ + --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ + --build-arg SURICATA_VERSION=$SURICATA_VERSION \ + --build-arg BUILD_TAG=$BUILD_TAG . + elif [ "$DISTRO" == "ubi" ]; then + docker build $PLATFORM_ARG \ + --cache-from antrea/cni-binaries:$CNI_BINARIES_VERSION \ + --cache-from antrea/base-ubi:$BUILD_TAG \ + -t antrea/base-ubi:$BUILD_TAG \ + -f Dockerfile.ubi \ + --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ + --build-arg SURICATA_VERSION=$SURICATA_VERSION \ + --build-arg BUILD_TAG=$BUILD_TAG . + fi +elif [ "$TYPE" == "agent" ]; then + docker build $PLATFORM_ARG --target cni-binaries \ + --cache-from antrea/cni-binaries:$CNI_BINARIES_VERSION \ + -t antrea/cni-binaries:$CNI_BINARIES_VERSION \ + --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ + --build-arg BUILD_TAG=$BUILD_TAG . + + if [ "$DISTRO" == "ubuntu" ]; then + docker build $PLATFORM_ARG \ + --cache-from antrea/cni-binaries:$CNI_BINARIES_VERSION \ + --cache-from antrea/base-ubuntu:$BUILD_TAG \ + -t antrea/agent-base-ubuntu:$BUILD_TAG \ + --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ + --build-arg SURICATA_VERSION=$SURICATA_VERSION \ + --build-arg BUILD_TAG=$BUILD_TAG . + elif [ "$DISTRO" == "ubi" ]; then + docker build $PLATFORM_ARG \ + --cache-from antrea/cni-binaries:$CNI_BINARIES_VERSION \ + --cache-from antrea/base-ubi:$BUILD_TAG \ + -t antrea/base-ubi:$BUILD_TAG \ + -f Dockerfile.ubi \ + --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ + --build-arg SURICATA_VERSION=$SURICATA_VERSION \ + --build-arg BUILD_TAG=$BUILD_TAG . + fi +else + if [ "$DISTRO" == "ubuntu" ]; then + docker build $PLATFORM_ARG \ + --cache-from antrea/base-ubuntu:$BUILD_TAG \ + -t antrea/controller-base-ubuntu:$BUILD_TAG \ + -f Dockerfile.controller \ + --build-arg BUILD_TAG=$BUILD_TAG . + elif [ "$DISTRO" == "ubi" ]; then + docker build $PLATFORM_ARG \ + --cache-from antrea/cni-binaries:$CNI_BINARIES_VERSION \ + --cache-from antrea/base-ubi:$BUILD_TAG \ + -t antrea/base-ubi:$BUILD_TAG \ + -f Dockerfile.ubi \ + --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ + --build-arg SURICATA_VERSION=$SURICATA_VERSION \ + --build-arg BUILD_TAG=$BUILD_TAG . + fi fi if $PUSH; then diff --git a/build/yamls/antrea.yml b/build/yamls/antrea.yml index 28a9c10267d..ce20e644724 100644 --- a/build/yamls/antrea.yml +++ b/build/yamls/antrea.yml @@ -6887,7 +6887,7 @@ spec: serviceAccountName: antrea-agent initContainers: - name: install-cni - image: "antrea/antrea-ubuntu:latest" + image: "antrea/antrea-agent-ubuntu:latest" imagePullPolicy: IfNotPresent resources: requests: @@ -6920,7 +6920,7 @@ spec: mountPath: /var/run/antrea containers: - name: antrea-agent - image: "antrea/antrea-ubuntu:latest" + image: "antrea/antrea-agent-ubuntu:latest" imagePullPolicy: IfNotPresent command: ["antrea-agent"] # Log to both "/var/log/antrea/" and stderr (so "kubectl logs" can work).- @@ -7011,7 +7011,7 @@ spec: - name: xtables-lock mountPath: /run/xtables.lock - name: antrea-ovs - image: "antrea/antrea-ubuntu:latest" + image: "antrea/antrea-agent-ubuntu:latest" imagePullPolicy: IfNotPresent resources: requests: @@ -7127,7 +7127,7 @@ spec: serviceAccountName: antrea-controller containers: - name: antrea-controller - image: "antrea/antrea-ubuntu:latest" + image: "antrea/antrea-controller-ubuntu:latest" imagePullPolicy: IfNotPresent resources: requests: diff --git a/hack/build-antrea-linux-all.sh b/hack/build-antrea-linux-all.sh index 9cf787bc1be..36b2871af03 100755 --- a/hack/build-antrea-linux-all.sh +++ b/hack/build-antrea-linux-all.sh @@ -155,7 +155,12 @@ cd build/images/ovs cd - cd build/images/base -./build.sh $ARGS +ARGS1="$ARGS --type controller" +ARGS2="$ARGS --type agent" +ARGS3="$ARGS --type unified" +./build.sh $ARGS1 +./build.sh $ARGS2 +./build.sh $ARGS3 cd - export NO_PULL=1 @@ -163,6 +168,8 @@ if [ "$DISTRO" == "ubuntu" ]; then if $COVERAGE; then make build-ubuntu-coverage else + make build-ubuntu-controller + make build-ubuntu-agent make fi elif [ "$DISTRO" == "ubi" ]; then