Skip to content

Commit

Permalink
Add arch suffix to base images
Browse files Browse the repository at this point in the history
This way we can push the base images to the registry, but we don't have
to worry about making a multi-platform image manifest.

Signed-off-by: Antonin Bas <antonin.bas@broadcom.com>
  • Loading branch information
antoninbas committed Sep 13, 2024
1 parent 719e2a0 commit db551e1
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 43 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ endif
ifneq ($(NO_CACHE),)
DOCKER_BUILD_ARGS += --no-cache
endif
ifneq ($(DOCKER_TARGETPLATFORM),)
DOCKER_BUILD_ARGS += --platform $(DOCKER_TARGETPLATFORM)
endif
DOCKER_BUILD_ARGS += --build-arg OVS_VERSION=$(OVS_VERSION)
DOCKER_BUILD_ARGS += --build-arg GO_VERSION=$(GO_VERSION)
DOCKER_BUILD_ARGS += --build-arg BUILD_TAG=$(BUILD_TAG)
Expand Down
1 change: 1 addition & 0 deletions build/images/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.targetarch
2 changes: 1 addition & 1 deletion build/images/Dockerfile.agent.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

ARG BUILD_TAG
FROM antrea/base-ubuntu:${BUILD_TAG}
FROM antrea/base-ubuntu-${TARGETPLATFORM}:${BUILD_TAG}

LABEL maintainer="Antrea <projectantrea-dev@googlegroups.com>"
LABEL description="The development Docker image to deploy the antrea-agent."
Expand Down
2 changes: 1 addition & 1 deletion build/images/Dockerfile.build.agent.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN make antctl-instr-binary

RUN make antrea-cni antrea-agent-instr-binary

FROM antrea/base-ubuntu:${BUILD_TAG}
FROM antrea/base-ubuntu-${TARGETARCH}:${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)."
Expand Down
2 changes: 1 addition & 1 deletion build/images/Dockerfile.build.agent.ubi
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target=/root/.cache/go-build/ \
make antrea-agent antrea-cni

FROM antrea/base-ubi:${BUILD_TAG}
FROM antrea/base-ubi-${TARGETARCH}:${BUILD_TAG}

LABEL maintainer="Antrea <projectantrea-dev@googlegroups.com>"
LABEL description="The Docker image to deploy the antrea-agent."
Expand Down
2 changes: 1 addition & 1 deletion build/images/Dockerfile.build.agent.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target=/root/.cache/go-build/ \
make antrea-agent antrea-cni

FROM antrea/base-ubuntu:${BUILD_TAG}
FROM antrea/base-ubuntu-${TARGETARCH}:${BUILD_TAG}

LABEL maintainer="Antrea <projectantrea-dev@googlegroups.com>"
LABEL description="The Docker image to deploy the antrea-agent."
Expand Down
1 change: 0 additions & 1 deletion build/images/Dockerfile.build.controller.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

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

WORKDIR /antrea
Expand Down
1 change: 0 additions & 1 deletion build/images/Dockerfile.build.controller.ubi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

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

WORKDIR /antrea
Expand Down
1 change: 0 additions & 1 deletion build/images/Dockerfile.build.controller.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

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

WORKDIR /antrea
Expand Down
3 changes: 1 addition & 2 deletions build/images/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

ARG BUILD_TAG
FROM ubuntu:24.04 AS cni-binaries

ARG CNI_BINARIES_VERSION
Expand All @@ -35,7 +34,7 @@ RUN set -eux; \
mkdir -p /opt/cni/bin; \
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

FROM antrea/openvswitch:${BUILD_TAG}
FROM antrea-openvswitch

ARG SURICATA_VERSION

Expand Down
3 changes: 1 addition & 2 deletions build/images/base/Dockerfile.ubi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

ARG BUILD_TAG
FROM ubuntu:24.04 AS cni-binaries

ARG CNI_BINARIES_VERSION
Expand All @@ -35,7 +34,7 @@ RUN set -eux; \
mkdir -p /opt/cni/bin; \
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

FROM antrea/openvswitch-ubi:${BUILD_TAG}
FROM antrea-openvswitch

ARG SURICATA_VERSION

Expand Down
34 changes: 16 additions & 18 deletions build/images/base/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ if $PUSH && ! check_docker_build_driver "docker-container"; then
exit 1
fi

if [ "$PLATFORM" != "" ] && $PUSH; then
echoerr "Cannot use --platform with --push"
exit 1
fi
TARGETARCH=$(set -e; get_target_arch "$PLATFORM" "$THIS_DIR/../.targetarch")
echo "Target arch: $TARGETARCH"

PLATFORM_ARG=""
if [ "$PLATFORM" != "" ]; then
Expand All @@ -118,24 +116,23 @@ if [[ $BUILD_TAG == "" ]]; then
BUILD_TAG=$BUILD_CACHE_TAG
fi

ANTREA_OPENVSWITCH_IMAGE=""
if [ "$DISTRO" == "ubuntu" ]; then
ANTREA_OPENVSWITCH_IMAGE="antrea/openvswitch-$TARGETARCH:$BUILD_TAG"
elif [ "$DISTRO" == "ubi" ]; then
ANTREA_OPENVSWITCH_IMAGE="antrea/openvswitch-ubi-$TARGETARCH:$BUILD_TAG"
fi

if $PULL; then
# The ubuntu image is also used for the UBI build (for the cni-binaries intermediate image).
if [[ ${DOCKER_REGISTRY} == "" ]]; then
docker pull $PLATFORM_ARG ubuntu:24.04
else
docker pull ${DOCKER_REGISTRY}/antrea/ubuntu:24.04
docker pull $PLATFORM_ARG ${DOCKER_REGISTRY}/antrea/ubuntu:24.04
docker tag ${DOCKER_REGISTRY}/antrea/ubuntu:24.04 ubuntu:24.04
fi

if [ "$DISTRO" == "ubuntu" ]; then
IMAGES_LIST=(
"antrea/openvswitch:$BUILD_TAG"
)
elif [ "$DISTRO" == "ubi" ]; then
IMAGES_LIST=(
"antrea/openvswitch-ubi:$BUILD_TAG"
)
fi
IMAGES_LIST=("$ANTREA_OPENVSWITCH_IMAGE")
for image in "${IMAGES_LIST[@]}"; do
if [[ ${DOCKER_REGISTRY} == "" ]]; then
docker pull $PLATFORM_ARG "${image}" || true
Expand All @@ -152,7 +149,8 @@ fi
function docker_build_and_push() {
local image="$1"
local dockerfile="$2"
local build_args="--build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION --build-arg SURICATA_VERSION=$SURICATA_VERSION --build-arg BUILD_TAG=$BUILD_TAG"
local build_args="--build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION --build-arg SURICATA_VERSION=$SURICATA_VERSION"
local build_context="--build-context antrea-openvswitch=docker-image://$ANTREA_OPENVSWITCH_IMAGE"
local cache_args=""
if $PUSH; then
cache_args="$cache_args --cache-to type=registry,ref=$image-cache:$BUILD_CACHE_TAG,mode=max"
Expand All @@ -162,7 +160,7 @@ function docker_build_and_push() {
else
cache_args="$cache_args --cache-from type=registry,ref=$image-cache:$BUILD_CACHE_TAG,mode=max"
fi
docker buildx build $PLATFORM_ARG -o type=docker -t $image:$BUILD_TAG $cache_args $build_args -f $dockerfile .
docker buildx build $PLATFORM_ARG -o type=docker -t $image:$BUILD_TAG $cache_args $build_args $build_context -f $dockerfile .

if $PUSH; then
docker push $image:$BUILD_TAG
Expand All @@ -171,9 +169,9 @@ function docker_build_and_push() {


if [ "$DISTRO" == "ubuntu" ]; then
docker_build_and_push "antrea/base-ubuntu" Dockerfile
docker_build_and_push "antrea/base-ubuntu-$TARGETARCH" Dockerfile
elif [ "$DISTRO" == "ubi" ]; then
docker_build_and_push "antrea/base-ubi" Dockerfile.ubi
docker_build_and_push "antrea/base-ubi-$TARGETARCH" Dockerfile.ubi
fi

popd > /dev/null
21 changes: 21 additions & 0 deletions build/images/build-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,24 @@ function docker_build_and_push_windows() {

docker buildx build --platform windows/amd64 -o ${output} -t ${image}:${build_tag} ${pull_option} ${build_args} -f $dockerfile .
}

function get_target_arch() {
local platform="$1"
local output_cache_path="$2"
local arch=""
if [ -n "$output_cache_path" ] && [ -f "$output_cache_path" ]; then
arch=$(head -n 1 "$output_cache_path")
fi
if [ -z "$arch" ]; then
local platform_arg=""
if [ -n "$platform" ]; then
platform_arg="--platform $platform"
fi
echo "FROM scratch" | docker buildx build $platform_arg -t antrea-test-arch -
arch=$(docker inspect antrea-test-arch --format '{{ .Architecture }}')
if [ -n "$output_cache_path" ]; then
echo "$arch" > "$output_cache_path"
fi
fi
echo "$arch"
}
14 changes: 6 additions & 8 deletions build/images/ovs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,14 @@ if $PUSH && [ "$DISTRO" != "windows" ] && ! check_docker_build_driver "docker-co
exit 1
fi

if [ "$PLATFORM" != "" ] && $PUSH; then
echoerr "Cannot use --platform with --push"
exit 1
fi

if [ "$DISTRO" != "ubuntu" ] && [ "$DISTRO" != "ubi" ] && [ "$DISTRO" != "windows" ]; then
echoerr "Invalid distribution $DISTRO"
exit 1
fi

TARGETARCH=$(set -e; get_target_arch "$PLATFORM" "$THIS_DIR/../.targetarch")
echo "Target arch: $TARGETARCH"

OVS_VERSION_FILE="../deps/ovs-version"
if [ "$DISTRO" == "windows" ]; then
OVS_VERSION_FILE="../deps/ovs-version-windows"
Expand All @@ -127,7 +125,7 @@ if $PULL; then
if [[ ${DOCKER_REGISTRY} == "" ]]; then
docker pull $PLATFORM_ARG ubuntu:24.04
else
docker pull ${DOCKER_REGISTRY}/antrea/ubuntu:24.04
docker pull $PLATFORM_ARG ${DOCKER_REGISTRY}/antrea/ubuntu:24.04
docker tag ${DOCKER_REGISTRY}/antrea/ubuntu:24.04 ubuntu:24.04
fi
elif [ "$DISTRO" == "ubi" ]; then
Expand Down Expand Up @@ -159,9 +157,9 @@ function docker_build_and_push() {
}

if [ "$DISTRO" == "ubuntu" ]; then
docker_build_and_push "antrea/openvswitch" "Dockerfile"
docker_build_and_push "antrea/openvswitch-$TARGETARCH" "Dockerfile"
elif [ "$DISTRO" == "ubi" ]; then
docker_build_and_push "antrea/openvswitch-ubi" "Dockerfile.ubi"
docker_build_and_push "antrea/openvswitch-ubi-$TARGETARCH" "Dockerfile.ubi"
elif [ "$DISTRO" == "windows" ]; then
image="antrea/windows-ovs"
build_args="--build-arg OVS_VERSION=$OVS_VERSION"
Expand Down
2 changes: 1 addition & 1 deletion build/images/test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

ARG BUILD_TAG
FROM antrea/openvswitch:${BUILD_TAG}
FROM antrea/openvswitch-$TARGETARCH:$BUILD_TAG

LABEL maintainer="Antrea <projectantrea-dev@googlegroups.com>"
LABEL description="A Docker image for Antrea integration tests."
Expand Down
11 changes: 6 additions & 5 deletions hack/build-antrea-linux-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,15 @@ if [ "$BUILD_TAG" != "" ]; then
fi

# 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
# image!
# scripts with "--pull".
if $PULL; then
if [[ ${DOCKER_REGISTRY} == "" ]]; then
docker pull $PLATFORM_ARG ubuntu:24.04
docker pull $PLATFORM_ARG golang:$GO_VERSION
else
docker pull ${DOCKER_REGISTRY}/antrea/ubuntu:24.04
docker pull $PLATFORM_ARG ${DOCKER_REGISTRY}/antrea/ubuntu:24.04
docker tag ${DOCKER_REGISTRY}/antrea/ubuntu:24.04 ubuntu:24.04
docker pull ${DOCKER_REGISTRY}/antrea/golang:$GO_VERSION
docker pull $PLATFORM_ARG ${DOCKER_REGISTRY}/antrea/golang:$GO_VERSION
docker tag ${DOCKER_REGISTRY}/antrea/golang:$GO_VERSION golang:$GO_VERSION
fi
if [ "$DISTRO" == "ubi" ]; then
Expand All @@ -169,6 +167,9 @@ export NO_PULL=1
# explicitly (note that we already set DOCKER_CLI_EXPERIMENTAL=enabled at the
# beginning of the script).
export DOCKER_BUILDKIT=1
if [ "$PLATFORM" != "" ]; then
export DOCKER_TARGETPLATFORM="$PLATFORM"
fi
if [ "$DISTRO" == "ubuntu" ]; then
if $COVERAGE; then
make build-controller-ubuntu-coverage
Expand Down

0 comments on commit db551e1

Please sign in to comment.