diff --git a/Makefile b/Makefile index 2a5467477b5..71c06f997a6 100644 --- a/Makefile +++ b/Makefile @@ -12,14 +12,18 @@ OVS_VERSION := $(shell head -n 1 build/images/deps/ovs-version) GO_VERSION := $(shell head -n 1 build/images/deps/go-version) CNI_BINARIES_VERSION := $(shell head -n 1 build/images/deps/cni-binaries-version) NANOSERVER_VERSION := $(shell head -n 1 build/images/deps/nanoserver-version) +UBUNTU_BUILD_TAG := $(shell build/images/chains/build-tag.sh ubuntu) +UBI_BUILD_TAG := $(shell build/images/chains/build-tag.sh ubi) WIN_BUILD_TAG := $(shell echo $(GO_VERSION) $(CNI_BINARIES_VERSION) $(NANOSERVER_VERSION)|md5sum|head -c 10) GIT_HOOKS := $(shell find hack/git_client_side_hooks -type f -print) DOCKER_NETWORK ?= default TRIVY_TARGET_IMAGE ?= -DOCKER_BUILD_ARGS = --build-arg OVS_VERSION=$(OVS_VERSION) +DOCKER_BUILD_ARGS := --build-arg OVS_VERSION=$(OVS_VERSION) DOCKER_BUILD_ARGS += --build-arg GO_VERSION=$(GO_VERSION) -WIN_BUILD_ARGS = --build-arg GO_VERSION=$(GO_VERSION) +UBUNTU_BUILD_ARGS := $(DOCKER_BUILD_ARGS) --build-arg BUILD_TAG=$(UBUNTU_BUILD_TAG) +UBI_BUILD_ARGS := $(DOCKER_BUILD_ARGS) --build-arg BUILD_TAG=$(UBI_BUILD_TAG) +WIN_BUILD_ARGS := --build-arg GO_VERSION=$(GO_VERSION) WIN_BUILD_ARGS += --build-arg CNI_BINARIES_VERSION=$(CNI_BINARIES_VERSION) WIN_BUILD_ARGS += --build-arg NANOSERVER_VERSION=$(NANOSERVER_VERSION) WIN_BUILD_ARGS += --build-arg WIN_BUILD_TAG=$(WIN_BUILD_TAG) @@ -330,9 +334,9 @@ mockgen: ubuntu: @echo "===> Building antrea/antrea-ubuntu Docker image <===" ifneq ($(NO_PULL),) - docker build -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.ubuntu $(DOCKER_BUILD_ARGS) . + docker build -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.ubuntu $(UBUNTU_BUILD_ARGS) . else - docker build --pull -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.ubuntu $(DOCKER_BUILD_ARGS) . + docker build --pull -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.ubuntu $(UBUNTU_BUILD_ARGS) . endif docker tag antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) antrea/antrea-ubuntu @@ -341,9 +345,9 @@ endif build-ubuntu: @echo "===> Building Antrea bins and antrea/antrea-ubuntu Docker image <===" ifneq ($(NO_PULL),) - docker build -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubuntu $(DOCKER_BUILD_ARGS) . + docker build -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubuntu $(UBUNTU_BUILD_ARGS) . else - docker build --pull -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubuntu $(DOCKER_BUILD_ARGS) . + docker build --pull -t antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubuntu $(UBUNTU_BUILD_ARGS) . endif docker tag antrea/antrea-ubuntu:$(DOCKER_IMG_VERSION) antrea/antrea-ubuntu @@ -352,9 +356,9 @@ endif build-ubi: @echo "===> Building Antrea bins and antrea/antrea-ubi Docker image <===" ifneq ($(NO_PULL),"") - docker build -t antrea/antrea-ubi:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubi $(DOCKER_BUILD_ARGS) . + docker build -t antrea/antrea-ubi:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubi $(UBI_BUILD_ARGS) . else - docker build --pull -t antrea/antrea-ubi:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubi $(DOCKER_BUILD_ARGS) . + docker build --pull -t antrea/antrea-ubi:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.ubi $(UBI_BUILD_ARGS) . endif docker tag antrea/antrea-ubi:$(DOCKER_IMG_VERSION) antrea/antrea-ubi @@ -372,9 +376,9 @@ endif build-ubuntu-coverage: @echo "===> Building Antrea bins and antrea/antrea-ubuntu-coverage Docker image <===" ifneq ($(NO_PULL),) - docker build -t antrea/antrea-ubuntu-coverage:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.coverage $(DOCKER_BUILD_ARGS) . + docker build -t antrea/antrea-ubuntu-coverage:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.coverage $(UBUNTU_BUILD_ARGS) . else - docker build --pull -t antrea/antrea-ubuntu-coverage:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.coverage $(DOCKER_BUILD_ARGS) . + docker build --pull -t antrea/antrea-ubuntu-coverage:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.coverage $(UBUNTU_BUILD_ARGS) . endif docker tag antrea/antrea-ubuntu-coverage:$(DOCKER_IMG_VERSION) antrea/antrea-ubuntu-coverage diff --git a/build/images/Dockerfile.build.coverage b/build/images/Dockerfile.build.coverage index 7b1aebd3ab3..f52f38e5ce9 100644 --- a/build/images/Dockerfile.build.coverage +++ b/build/images/Dockerfile.build.coverage @@ -13,7 +13,7 @@ # limitations under the License. ARG GO_VERSION -ARG OVS_VERSION +ARG BUILD_TAG FROM golang:${GO_VERSION} as antrea-build WORKDIR /antrea @@ -27,7 +27,7 @@ COPY . /antrea RUN make antrea-agent antrea-controller antrea-cni antctl-linux antrea-controller-instr-binary antrea-agent-instr-binary antctl-instr-binary RUN mv bin/antctl-linux bin/antctl -FROM antrea/base-ubuntu:${OVS_VERSION} +FROM antrea/base-ubuntu:${BUILD_TAG} LABEL maintainer="Antrea " LABEL description="The Docker image to deploy the Antrea CNI with code coverage measurement enabled (used for testing)." diff --git a/build/images/Dockerfile.build.ubi b/build/images/Dockerfile.build.ubi index 33099751fba..20e0554976d 100644 --- a/build/images/Dockerfile.build.ubi +++ b/build/images/Dockerfile.build.ubi @@ -13,7 +13,7 @@ # limitations under the License. ARG GO_VERSION -ARG OVS_VERSION +ARG BUILD_TAG FROM golang:${GO_VERSION} as antrea-build WORKDIR /antrea @@ -27,7 +27,7 @@ COPY . /antrea RUN make antrea-agent antrea-controller antrea-cni antctl-linux RUN mv bin/antctl-linux bin/antctl -FROM antrea/base-ubi:${OVS_VERSION} +FROM antrea/base-ubi:${BUILD_TAG} LABEL maintainer="Antrea " LABEL description="The Docker image to deploy the Antrea CNI. " diff --git a/build/images/Dockerfile.build.ubuntu b/build/images/Dockerfile.build.ubuntu index 1fec8336eff..c95410db54e 100644 --- a/build/images/Dockerfile.build.ubuntu +++ b/build/images/Dockerfile.build.ubuntu @@ -13,7 +13,7 @@ # limitations under the License. ARG GO_VERSION -ARG OVS_VERSION +ARG BUILD_TAG FROM golang:${GO_VERSION} as antrea-build WORKDIR /antrea @@ -27,7 +27,7 @@ COPY . /antrea RUN make antrea-agent antrea-controller antrea-cni antctl-linux RUN mv bin/antctl-linux bin/antctl -FROM antrea/base-ubuntu:${OVS_VERSION} +FROM antrea/base-ubuntu:${BUILD_TAG} LABEL maintainer="Antrea " LABEL description="The Docker image to deploy the Antrea CNI." diff --git a/build/images/Dockerfile.ubuntu b/build/images/Dockerfile.ubuntu index 11fd1cf0697..05db9e4ab77 100644 --- a/build/images/Dockerfile.ubuntu +++ b/build/images/Dockerfile.ubuntu @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -ARG OVS_VERSION -FROM antrea/base-ubuntu:${OVS_VERSION} +ARG BUILD_TAG +FROM antrea/base-ubuntu:${BUILD_TAG} LABEL maintainer="Antrea " LABEL description="The Docker image to deploy the Antrea CNI." diff --git a/build/images/base/.dockerignore b/build/images/base/.dockerignore new file mode 100644 index 00000000000..6c7b69a0156 --- /dev/null +++ b/build/images/base/.dockerignore @@ -0,0 +1 @@ +.gitignore diff --git a/build/images/base/.gitignore b/build/images/base/.gitignore new file mode 100644 index 00000000000..3f9cfafd337 --- /dev/null +++ b/build/images/base/.gitignore @@ -0,0 +1 @@ +deps diff --git a/build/images/base/Dockerfile b/build/images/base/Dockerfile index daa5e4e665b..fb349881be4 100644 --- a/build/images/base/Dockerfile +++ b/build/images/base/Dockerfile @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -ARG OVS_VERSION -FROM ubuntu:20.04 as cni-binaries +ARG BUILD_TAG +FROM ubuntu:22.04 as cni-binaries ARG CNI_BINARIES_VERSION ARG WHEREABOUTS_VERSION=v0.5.4 @@ -37,7 +37,7 @@ RUN set -eux; \ wget -q -O - https://github.com/containernetworking/plugins/releases/download/$CNI_BINARIES_VERSION/cni-plugins-linux-${pluginsArch}-$CNI_BINARIES_VERSION.tgz | tar xz -C /opt/cni/bin $CNI_PLUGINS; \ wget -q -O /opt/cni/bin/whereabouts https://github.com/k8snetworkplumbingwg/whereabouts/releases/download/$WHEREABOUTS_VERSION/whereabouts-${pluginsArch} && chmod +x /opt/cni/bin/whereabouts -FROM antrea/openvswitch:${OVS_VERSION} +FROM antrea/openvswitch:${BUILD_TAG} LABEL maintainer="Antrea " LABEL description="An Ubuntu based Docker base image for Antrea." @@ -56,3 +56,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends ipset jq inotif /iptables-wrapper-installer.sh COPY --from=cni-binaries /opt/cni/bin /opt/cni/bin + +# Useful if one needs to check version of dependencies at runtime +COPY deps /opt/antrea/deps diff --git a/build/images/base/Dockerfile.ubi b/build/images/base/Dockerfile.ubi index 7352071f829..8d22406cd79 100644 --- a/build/images/base/Dockerfile.ubi +++ b/build/images/base/Dockerfile.ubi @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -ARG OVS_VERSION -FROM ubuntu:20.04 as cni-binaries +ARG BUILD_TAG +FROM ubuntu:22.04 as cni-binaries ARG CNI_BINARIES_VERSION ARG WHEREABOUTS_VERSION=v0.5.1 @@ -37,7 +37,7 @@ RUN set -eux; \ wget -q -O - https://github.com/containernetworking/plugins/releases/download/$CNI_BINARIES_VERSION/cni-plugins-linux-${pluginsArch}-$CNI_BINARIES_VERSION.tgz | tar xz -C /opt/cni/bin $CNI_PLUGINS; \ wget -q -O /opt/cni/bin/whereabouts https://github.com/k8snetworkplumbingwg/whereabouts/releases/download/$WHEREABOUTS_VERSION/whereabouts-${pluginsArch} && chmod +x /opt/cni/bin/whereabouts -FROM antrea/openvswitch-ubi:${OVS_VERSION} +FROM antrea/openvswitch-ubi:${BUILD_TAG} LABEL maintainer="Antrea " LABEL description="An UBI8 based Docker base image for Antrea." @@ -47,3 +47,6 @@ USER root RUN yum install ipset jq -y && yum clean all COPY --from=cni-binaries /opt/cni/bin /opt/cni/bin + +# Useful if one needs to check version of dependencies at runtime +COPY deps /opt/antrea/deps diff --git a/build/images/base/build.sh b/build/images/base/build.sh index 1348242b169..48324db4d23 100755 --- a/build/images/base/build.sh +++ b/build/images/base/build.sh @@ -24,7 +24,7 @@ function echoerr { } _usage="Usage: $0 [--pull] [--push] [--platform ] [--distro [ubuntu|ubi]] -Build the antrea/base-ubuntu: image. +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 @@ -90,28 +90,33 @@ THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" pushd $THIS_DIR > /dev/null -OVS_VERSION=$(head -n 1 ../deps/ovs-version) CNI_BINARIES_VERSION=$(head -n 1 ../deps/cni-binaries-version) +BUILD_TAG=$(../chains/build-tag.sh "$DISTRO") +echo "BUILD_TAG: $BUILD_TAG" +DEPS=$(../chains/show-deps.sh "$DISTRO") +echo "$DEPS" +echo "$DEPS" > deps + if $PULL; then if [[ ${DOCKER_REGISTRY} == "" ]]; then - docker pull $PLATFORM_ARG ubuntu:20.04 + docker pull $PLATFORM_ARG ubuntu:22.04 else - docker pull ${DOCKER_REGISTRY}/antrea/ubuntu:20.04 - docker tag ${DOCKER_REGISTRY}/antrea/ubuntu:20.04 ubuntu:20.04 + docker pull ${DOCKER_REGISTRY}/antrea/ubuntu:22.04 + docker tag ${DOCKER_REGISTRY}/antrea/ubuntu:22.04 ubuntu:22.04 fi if [ "$DISTRO" == "ubuntu" ]; then IMAGES_LIST=( - "antrea/openvswitch:$OVS_VERSION" + "antrea/openvswitch:$BUILD_TAG" "antrea/cni-binaries:$CNI_BINARIES_VERSION" - "antrea/base-ubuntu:$OVS_VERSION" + "antrea/base-ubuntu:$BUILD_TAG" ) elif [ "$DISTRO" == "ubi" ]; then IMAGES_LIST=( - "antrea/openvswitch-ubi:$OVS_VERSION" + "antrea/openvswitch-ubi:$BUILD_TAG" "antrea/cni-binaries:$CNI_BINARIES_VERSION" - "antrea/base-ubi:$OVS_VERSION" + "antrea/base-ubi:$BUILD_TAG" ) fi for image in "${IMAGES_LIST[@]}"; do @@ -131,28 +136,30 @@ 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 OVS_VERSION=$OVS_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:$OVS_VERSION \ - -t antrea/base-ubuntu:$OVS_VERSION \ + --cache-from antrea/base-ubuntu:$BUILD_TAG \ + -t antrea/base-ubuntu:$BUILD_TAG \ --build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \ - --build-arg OVS_VERSION=$OVS_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-ubuntu:$OVS_VERSION \ - -t antrea/base-ubi:$OVS_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 OVS_VERSION=$OVS_VERSION . + --build-arg BUILD_TAG=$BUILD_TAG . fi if $PUSH; then docker push antrea/cni-binaries:$CNI_BINARIES_VERSION - docker push antrea/base-$DISTRO:$OVS_VERSION + docker push antrea/base-$DISTRO:$BUILD_TAG fi +rm -f deps + popd > /dev/null diff --git a/build/images/chains/README.md b/build/images/chains/README.md new file mode 100644 index 00000000000..1e59e61a417 --- /dev/null +++ b/build/images/chains/README.md @@ -0,0 +1,20 @@ +# Managing dependency versions + +For each build chain (e.g., "ubuntu"), a `.def` text file should be added to +this directory. It must define the following variables: + + * `tag_prefix`: a string which will be used as prefix to the final build tag. + * `deps`: a Bash array of dependency names. + * `deps_files`: a Bash array listing version files (from the [deps/](../deps) + directory) which are used to track the version of build / runtime + dependencies (e.g., OVS version). Unlike for `deps`, the dependencies + included here tend to be generic and not specific to a given build chain. + +To generate the build tag, a hash (md5sum) is computed from the `deps` string +and from the contents of the version files listed in `deps_files`. + +To add a dependency to a build chain, you typically define a new version file in +[deps/](../deps) and include it in `deps_files` for all appropriate build +chains. + +See [ubuntu.def](ubuntu.def) for an example. diff --git a/build/images/chains/build-tag.sh b/build/images/chains/build-tag.sh new file mode 100755 index 00000000000..98fa2c79310 --- /dev/null +++ b/build/images/chains/build-tag.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# call with build chain name (e.g. ubuntu) +function build_tag() { + local chain="$1" + local this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + source "$this_dir/$chain.def" + local deps_str="" + for x in "${deps[@]}"; do + deps_str="$deps_str $x" + done + for x in "${deps_files[@]}"; do + local v=$(head -n 1 $this_dir/../deps/$x) + deps_str="$deps_str $v" + done + local hash="$(echo $deps_str| md5sum| head -c 10)" + local antrea_version=$(head -n 1 $this_dir/../../../VERSION | cut -f1,2 -d'.') + local tag="${antrea_version}_$hash" + if [ "$tag_prefix" != "" ]; then + tag="${tag_prefix}_${tag}" + fi + echo "$tag" +} + +echo "$(build_tag "$@")" diff --git a/build/images/chains/show-deps.sh b/build/images/chains/show-deps.sh new file mode 100755 index 00000000000..b69033a034f --- /dev/null +++ b/build/images/chains/show-deps.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# call with build chain name (e.g. ubuntu) +function show_deps() { + local chain="$1" + local this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + source "$this_dir/$chain.def" + for x in "${deps[@]}"; do + echo "$x" + done + for x in "${deps_files[@]}"; do + local v=$(head -n 1 $this_dir/../deps/$x) + echo "$x: $v" + done +} + +echo "$(show_deps "$@")" diff --git a/build/images/chains/ubi.def b/build/images/chains/ubi.def new file mode 100644 index 00000000000..b1195b7a206 --- /dev/null +++ b/build/images/chains/ubi.def @@ -0,0 +1,3 @@ +tag_prefix="" +deps=("centos7" "ubi8") +deps_files=("ovs-version" "go-version" "cni-binaries-version") diff --git a/build/images/chains/ubuntu.def b/build/images/chains/ubuntu.def new file mode 100644 index 00000000000..3e1049d5f07 --- /dev/null +++ b/build/images/chains/ubuntu.def @@ -0,0 +1,6 @@ +# Will be prepended to the tag +tag_prefix="22.04" +# The image is built using the Ubuntu 22.04 distribution +deps=("ubuntu22.04") +# Build or runtime dependencies whose version is tracked using a file in this directory +deps_files=("ovs-version" "go-version" "cni-binaries-version") diff --git a/build/images/ovs/Dockerfile b/build/images/ovs/Dockerfile index b229f9fe35c..8dc33e1828e 100644 --- a/build/images/ovs/Dockerfile +++ b/build/images/ovs/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM ubuntu:20.04 as ovs-debs +FROM ubuntu:22.04 as ovs-debs # Some patches may not apply cleanly if a non-default version is provided. # See build/images/deps/ovs-version for the default version. @@ -39,10 +39,10 @@ RUN wget -q -O - https://www.openvswitch.org/releases/openvswitch-$OVS_VERSION.t cd / && rm -rf /tmp/openvswitch* -FROM ubuntu:20.04 +FROM ubuntu:22.04 LABEL maintainer="Antrea " -LABEL description="A Docker image based on Ubuntu 20.04 which includes Open vSwitch built from source." +LABEL description="A Docker image based on Ubuntu 22.04 which includes Open vSwitch built from source." COPY --from=ovs-debs /tmp/ovs-debs/* /tmp/ovs-debs/ COPY charon-logging.conf /tmp diff --git a/build/images/ovs/README.md b/build/images/ovs/README.md index 455e4b8b16b..533fc957943 100644 --- a/build/images/ovs/README.md +++ b/build/images/ovs/README.md @@ -2,14 +2,13 @@ This directory contains utilities to build a Docker image which includes Open vSwitch (OVS) built from source. We build OVS from source because some features -of Antrea (such as IPsec) require a recent version of OVS, more recent than the -version included in Ubuntu 20.04. The built image is then used as the base image -for the Antrea main Docker image. +of Antrea (such as IPsec) may require a recent version of OVS, more recent than +the version included in the base distribution. The built image is then used as +the base image for the Antrea main Docker image. -The image is re-built and pushed to Dockerhub periodically (every 12 hours) by a -[Github workflow](/.github/workflows/update_ovs_image.yml). Therefore, there -should be no need to update the registry image manually. If it's needed for any -reason, you can follow the instructions below. +The image is re-built and pushed to Dockerhub every time the main branch is +updated. Therefore, there should be no need to update the registry image +manually. If it's needed for any reason, you can follow the instructions below. ## Manually building the image and pushing it to Dockerhub @@ -18,9 +17,5 @@ cd build/images/ovs ./build.sh --pull --push ``` -The image will be pushed to Dockerhub as `antrea/openvswitch:`. The -OVS version used is determined by the contents of the -`build/images/deps/ovs-version` file. - The script will fail if you do not have permission to push to the `antrea` Dockerhub repository. diff --git a/build/images/ovs/apply-patches.sh b/build/images/ovs/apply-patches.sh index 97edf183324..aa62b5a53ed 100755 --- a/build/images/ovs/apply-patches.sh +++ b/build/images/ovs/apply-patches.sh @@ -100,7 +100,7 @@ if version_lt "$OVS_VERSION" "2.18.0" ; then fi # OVS hardcodes the installation path to /usr/lib/python3.7/dist-packages/ but this location -# does not seem to be in the Python path in Ubuntu 20.04. There may be a better way to do this, +# does not seem to be in the Python path in Ubuntu 22.04. There may be a better way to do this, # but this seems like an acceptable workaround. -sed -i 's/python3\.7/python3\.8/' debian/openvswitch-test.install -sed -i 's/python3\.7/python3\.8/' debian/python3-openvswitch.install +sed -i 's/python3\.7/python3\.10/' debian/openvswitch-test.install +sed -i 's/python3\.7/python3\.10/' debian/python3-openvswitch.install diff --git a/build/images/ovs/build.sh b/build/images/ovs/build.sh index 3e09006db13..d20784ccec0 100755 --- a/build/images/ovs/build.sh +++ b/build/images/ovs/build.sh @@ -24,7 +24,7 @@ function echoerr { } _usage="Usage: $0 [--pull] [--push] [--platform ] [--distro [ubuntu|ubi]] -Build the antrea/base-ubuntu: image. +Build the antrea openvswitch 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 @@ -92,6 +92,9 @@ pushd $THIS_DIR > /dev/null OVS_VERSION=$(head -n 1 ../deps/ovs-version) +BUILD_TAG=$(../chains/build-tag.sh "$DISTRO") +echo "BUILD_TAG: $BUILD_TAG" + # This is a bit complicated but we make sure that we only build OVS if # necessary, and at the moment --cache-from does not play nicely with multistage # builds: we need to push the intermediate image to the registry. Note that the @@ -101,20 +104,20 @@ OVS_VERSION=$(head -n 1 ../deps/ovs-version) if $PULL; then if [[ ${DOCKER_REGISTRY} == "" ]]; then - docker pull $PLATFORM_ARG ubuntu:20.04 + docker pull $PLATFORM_ARG ubuntu:22.04 else - docker pull ${DOCKER_REGISTRY}/antrea/ubuntu:20.04 - docker tag ${DOCKER_REGISTRY}/antrea/ubuntu:20.04 ubuntu:20.04 + docker pull ${DOCKER_REGISTRY}/antrea/ubuntu:22.04 + docker tag ${DOCKER_REGISTRY}/antrea/ubuntu:22.04 ubuntu:22.04 fi if [ "$DISTRO" == "ubuntu" ]; then IMAGES_LIST=( - "antrea/openvswitch-debs:$OVS_VERSION" - "antrea/openvswitch:$OVS_VERSION" + "antrea/openvswitch-debs:$BUILD_TAG" + "antrea/openvswitch:$BUILD_TAG" ) elif [ "$DISTRO" == "ubi" ]; then IMAGES_LIST=( - "antrea/openvswitch-rpms:$OVS_VERSION" - "antrea/openvswitch-ubi:$OVS_VERSION" + "antrea/openvswitch-rpms:$BUILD_TAG" + "antrea/openvswitch-ubi:$BUILD_TAG" ) fi for image in "${IMAGES_LIST[@]}"; do @@ -132,37 +135,37 @@ fi if [ "$DISTRO" == "ubuntu" ]; then docker build $PLATFORM_ARG --target ovs-debs \ - --cache-from antrea/openvswitch-debs:$OVS_VERSION \ - -t antrea/openvswitch-debs:$OVS_VERSION \ + --cache-from antrea/openvswitch-debs:$BUILD_TAG \ + -t antrea/openvswitch-debs:$BUILD_TAG \ --build-arg OVS_VERSION=$OVS_VERSION . docker build $PLATFORM_ARG \ - --cache-from antrea/openvswitch-debs:$OVS_VERSION \ - --cache-from antrea/openvswitch:$OVS_VERSION \ - -t antrea/openvswitch:$OVS_VERSION \ + --cache-from antrea/openvswitch-debs:$BUILD_TAG \ + --cache-from antrea/openvswitch:$BUILD_TAG \ + -t antrea/openvswitch:$BUILD_TAG \ --build-arg OVS_VERSION=$OVS_VERSION . elif [ "$DISTRO" == "ubi" ]; then docker build $PLATFORM_ARG --target ovs-rpms \ - --cache-from antrea/openvswitch-rpms:$OVS_VERSION \ - -t antrea/openvswitch-rpms:$OVS_VERSION \ + --cache-from antrea/openvswitch-rpms:$BUILD_TAG \ + -t antrea/openvswitch-rpms:$BUILD_TAG \ --build-arg OVS_VERSION=$OVS_VERSION \ -f Dockerfile.ubi . docker build \ - --cache-from antrea/openvswitch-rpms:$OVS_VERSION \ - --cache-from antrea/openvswitch-ubi:$OVS_VERSION \ - -t antrea/openvswitch-ubi:$OVS_VERSION \ + --cache-from antrea/openvswitch-rpms:$BUILD_TAG \ + --cache-from antrea/openvswitch-ubi:$BUILD_TAG \ + -t antrea/openvswitch-ubi:$BUILD_TAG \ --build-arg OVS_VERSION=$OVS_VERSION \ -f Dockerfile.ubi . fi if $PUSH; then if [ "$DISTRO" == "ubuntu" ]; then - docker push antrea/openvswitch-debs:$OVS_VERSION - docker push antrea/openvswitch:$OVS_VERSION + docker push antrea/openvswitch-debs:$BUILD_TAG + docker push antrea/openvswitch:$BUILD_TAG elif [ "$DISTRO" == "ubi" ]; then - docker push antrea/openvswitch-rpms:$OVS_VERSION - docker push antrea/openvswitch-ubi:$OVS_VERSION + docker push antrea/openvswitch-rpms:$BUILD_TAG + docker push antrea/openvswitch-ubi:$BUILD_TAG fi fi diff --git a/build/images/test/Dockerfile b/build/images/test/Dockerfile index 63b3a1aa082..d75241b7fc3 100644 --- a/build/images/test/Dockerfile +++ b/build/images/test/Dockerfile @@ -13,7 +13,7 @@ # limitations under the License. ARG OVS_VERSION -FROM antrea/openvswitch:${OVS_VERSION} +FROM antrea/openvswitch:22.04-ovs${OVS_VERSION} LABEL maintainer="Antrea " LABEL description="A Docker image for Antrea integration tests." diff --git a/hack/build-antrea-linux-all.sh b/hack/build-antrea-linux-all.sh index bd931040d56..4ac01eb8695 100755 --- a/hack/build-antrea-linux-all.sh +++ b/hack/build-antrea-linux-all.sh @@ -21,9 +21,9 @@ function echoerr { } _usage="Usage: $0 [--pull] [--push-base-images] [--coverage] [--platform ] [--distro [ubuntu|ubi]] -Build the antrea/antrea-ubuntu image, as well as all the base images in the build chain. This is -typically used in CI to build the image with the latest version of all dependencies, taking into -account changes to all Dockerfiles. +Build the antrea image, as well as all the base images in the build chain. This is typically used in +CI to build the image with the latest version of all dependencies, taking into account changes to +all Dockerfiles. --pull Always attempt to pull a newer version of the base images. --push-base-images Push built images to the registry. Only base images will be pushed. --coverage Build the image with support for code coverage. @@ -101,10 +101,12 @@ if [ "$DISTRO" == "ubi" ]; then ARGS="$ARGS --distro ubi" fi -OVS_VERSION=$(head -n 1 build/images/deps/ovs-version) CNI_BINARIES_VERSION=$(head -n 1 build/images/deps/cni-binaries-version) GO_VERSION=$(head -n 1 build/images/deps/go-version) +BUILD_TAG=$(build/images/chains/build-tag.sh "$DISTRO") +echo "BUILD_TAG: $BUILD_TAG" + # We pull all images ahead of time, instead of calling the independent build.sh # scripts with "--pull". We do not want to overwrite the antrea/openvswitch # image we just built when calling build.sh to build the antrea/base-ubuntu @@ -112,27 +114,27 @@ GO_VERSION=$(head -n 1 build/images/deps/go-version) # new base images in the build chain. if $PULL; then if [[ ${DOCKER_REGISTRY} == "" ]]; then - docker pull $PLATFORM_ARG ubuntu:20.04 + docker pull $PLATFORM_ARG ubuntu:22.04 docker pull $PLATFORM_ARG golang:$GO_VERSION else - docker pull ${DOCKER_REGISTRY}/antrea/ubuntu:20.04 - docker tag ${DOCKER_REGISTRY}/antrea/ubuntu:20.04 ubuntu:20.04 + docker pull ${DOCKER_REGISTRY}/antrea/ubuntu:22.04 + docker tag ${DOCKER_REGISTRY}/antrea/ubuntu:22.04 ubuntu:22.04 docker pull ${DOCKER_REGISTRY}/antrea/golang:$GO_VERSION docker tag ${DOCKER_REGISTRY}/antrea/golang:$GO_VERSION golang:$GO_VERSION fi if [ "$DISTRO" == "ubuntu" ]; then IMAGES_LIST=( - "antrea/openvswitch-debs:$OVS_VERSION" - "antrea/openvswitch:$OVS_VERSION" + "antrea/openvswitch-debs:$BUILD_TAG" + "antrea/openvswitch:$BUILD_TAG" "antrea/cni-binaries:$CNI_BINARIES_VERSION" - "antrea/base-ubuntu:$OVS_VERSION" + "antrea/base-ubuntu:$BUILD_TAG" ) elif [ "$DISTRO" == "ubi" ]; then IMAGES_LIST=( - "antrea/openvswitch-rpms:$OVS_VERSION" - "antrea/openvswitch-ubi:$OVS_VERSION" + "antrea/openvswitch-rpms:$BUILD_TAG" + "antrea/openvswitch-ubi:$BUILD_TAG" "antrea/cni-binaries:$CNI_BINARIES_VERSION" - "antrea/base-ubi:$OVS_VERSION" + "antrea/base-ubi:$BUILD_TAG" ) fi for image in "${IMAGES_LIST[@]}"; do