diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f33f0640259..eb51345968d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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 diff --git a/.github/workflows/build_tag.yml b/.github/workflows/build_tag.yml index 2eddbccb246..bc31d7bf311 100644 --- a/.github/workflows/build_tag.yml +++ b/.github/workflows/build_tag.yml @@ -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: @@ -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] diff --git a/Makefile b/Makefile index 0bed0777b0d..096bd1fbbd7 100644 --- a/Makefile +++ b/Makefile @@ -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: @@ -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 <===" @@ -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" diff --git a/build/images/Dockerfile.build.agent.coverage b/build/images/Dockerfile.build.agent.coverage new file mode 100644 index 00000000000..1e2e36a3e8f --- /dev/null +++ b/build/images/Dockerfile.build.agent.coverage @@ -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 " +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 / diff --git a/build/images/Dockerfile.build.agent.ubi b/build/images/Dockerfile.build.agent.ubi new file mode 100644 index 00000000000..71d3aaa80e6 --- /dev/null +++ b/build/images/Dockerfile.build.agent.ubi @@ -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 " +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/ diff --git a/build/images/Dockerfile.build.agent.ubuntu b/build/images/Dockerfile.build.agent.ubuntu new file mode 100644 index 00000000000..68d52268fbc --- /dev/null +++ b/build/images/Dockerfile.build.agent.ubuntu @@ -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 " +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/ diff --git a/build/images/Dockerfile.build.controller.coverage b/build/images/Dockerfile.build.controller.coverage new file mode 100644 index 00000000000..3675a88e71d --- /dev/null +++ b/build/images/Dockerfile.build.controller.coverage @@ -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 " +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 / diff --git a/build/images/Dockerfile.build.controller.ubi b/build/images/Dockerfile.build.controller.ubi new file mode 100644 index 00000000000..376801bde38 --- /dev/null +++ b/build/images/Dockerfile.build.controller.ubi @@ -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 " +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/ diff --git a/build/images/Dockerfile.build.controller.ubuntu b/build/images/Dockerfile.build.controller.ubuntu new file mode 100644 index 00000000000..ba1129fc741 --- /dev/null +++ b/build/images/Dockerfile.build.controller.ubuntu @@ -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 " +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/ diff --git a/hack/build-antrea-linux-all.sh b/hack/build-antrea-linux-all.sh index 9cf787bc1be..56604ccd08c 100755 --- a/hack/build-antrea-linux-all.sh +++ b/hack/build-antrea-linux-all.sh @@ -28,7 +28,8 @@ all Dockerfiles. --push-base-images Push built images to the registry. Only base images will be pushed. --coverage Build the image with support for code coverage. --platform Target platform for the images if server is multi-platform capable. - --distro Target Linux distribution." + --distro Target Linux distribution. + --skip-unified-image Skips building the Antrea unified image." function print_usage { echoerr "$_usage" @@ -39,6 +40,7 @@ PUSH=false COVERAGE=false PLATFORM="" DISTRO="ubuntu" +UNIFIED=true while [[ $# -gt 0 ]] do @@ -65,6 +67,10 @@ case $key in DISTRO="$2" shift 2 ;; + --skip-unified-image) + UNIFIED=false + shift 2 + ;; -h|--help) print_usage exit 0 @@ -161,12 +167,24 @@ cd - export NO_PULL=1 if [ "$DISTRO" == "ubuntu" ]; then if $COVERAGE; then - make build-ubuntu-coverage + make build-controller-ubuntu-coverage + make build-agent-ubuntu-coverage + if $UNIFIED; then + make build-ubuntu-coverage + fi else - make + make build-controller-ubuntu + make build-agent-ubuntu + if $UNIFIED; then + make + fi fi elif [ "$DISTRO" == "ubi" ]; then - make build-ubi + make build-controller-ubi + make build-agent-ubi + if $UNIFIED; then + make build-ubi + fi fi popd > /dev/null