From 6260010480f28aebcd81c400da476bd6ca0a66b1 Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Wed, 16 Oct 2024 17:14:04 +0200 Subject: [PATCH 1/5] feat: Build server image for different platforms Signed-off-by: Anatolii Bazko --- .github/workflows/next-build.yml | 6 +++++- .github/workflows/release.yml | 4 ++++ build/build.sh | 11 ++++++++++- make-release.sh | 3 ++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/next-build.yml b/.github/workflows/next-build.yml index b95aa18644..2b0c9be364 100644 --- a/.github/workflows/next-build.yml +++ b/.github/workflows/next-build.yml @@ -28,6 +28,10 @@ jobs: distribution: 'temurin' java-version: '11' cache: 'maven' + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Login to docker.io uses: redhat-actions/podman-login@v1 with: @@ -46,7 +50,7 @@ jobs: id: build run: | echo "short_sha1=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - ./build/build.sh --tag:next --sha-tag + ./build/build.sh --tag:next --sha-tag --build-platforms:linux/amd64,linux/ppc64le,linux/arm64 - name: Push docker images run: | podman push quay.io/eclipse/che-server:next diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4508e269f1..b3a49971e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,6 +62,10 @@ jobs: echo "cannot create release, when tag already exists" exit 1 fi + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Login to docker.io uses: docker/login-action@v2 with: diff --git a/build/build.sh b/build/build.sh index 261b61f711..8816ef6246 100755 --- a/build/build.sh +++ b/build/build.sh @@ -52,6 +52,8 @@ init() { DOCKERFILE="" BUILD_COMMAND="build" BUILD_ARGS="" + BUILD_PLATFORMS="" + BUILD_PLATFORMS_ARG="" while [ $# -gt 0 ]; do case $1 in @@ -89,6 +91,9 @@ init() { BUILD_ARGS_CSV="${1#*:}" prepare_build_args $BUILD_ARGS_CSV shift ;; + --build-platforms*:*) + BUILD_PLATFORMS="${1#*:}" + shift ;; --*) printf "${RED}Unknown parameter: $1${NC}\n"; exit 2 ;; *) @@ -137,6 +142,10 @@ build() { fi fi + if [ ! -z $BUILD_PLATFORMS ]; then + BUILD_PLATFORMS_ARG="--platform ${BUILD_PLATFORMS}" + fi + # If Dockerfile is empty, build all Dockerfiles if [ -z ${DOCKERFILE} ]; then DOCKERFILES_TO_BUILD="$(ls ${DIR}/Dockerfile*)" @@ -171,7 +180,7 @@ build_image() { -e "s;\${BUILD_PREFIX};${PREFIX};" \ -e "s;\${BUILD_TAG};${TAG};" \ > ${DIR}/.Dockerfile - cd "${DIR}" && "${BUILDER}" "${BUILD_COMMAND}" -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} . + cd "${DIR}" && "${BUILDER}" "${BUILD_COMMAND}" ${PLATFORMS_ARG} -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} . DOCKER_BUILD_STATUS=$? rm ${DIR}/.Dockerfile if [ $DOCKER_BUILD_STATUS -eq 0 ]; then diff --git a/make-release.sh b/make-release.sh index 572dbfeffe..1513252add 100755 --- a/make-release.sh +++ b/make-release.sh @@ -7,6 +7,7 @@ REGISTRY="quay.io" ORGANIZATION="eclipse" IMAGE="quay.io/eclipse/che-server" +BUILD_PLATFORMS="linux/amd64,linux/ppc64le,linux/arm64" sed_in_place() { SHORT_UNAME=$(uname -s) @@ -275,7 +276,7 @@ buildImages() { fi # BUILD IMAGES - bash "$(pwd)/che-server/build/build.sh" --tag:${TAG} + bash "$(pwd)/che-server/build/build.sh" --tag:${TAG} --build-platforms:${BUILD_PLATFORMS} if [[ $? -ne 0 ]]; then echo "ERROR:" echo "build of che-server image $TAG is failed!" From 3ecfefd12a4cf3b72b6b3755ad357ebe248d20bd Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Thu, 17 Oct 2024 09:23:49 +0200 Subject: [PATCH 2/5] Fixup Signed-off-by: Anatolii Bazko --- build/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build.sh b/build/build.sh index 8816ef6246..faf64de722 100755 --- a/build/build.sh +++ b/build/build.sh @@ -180,7 +180,7 @@ build_image() { -e "s;\${BUILD_PREFIX};${PREFIX};" \ -e "s;\${BUILD_TAG};${TAG};" \ > ${DIR}/.Dockerfile - cd "${DIR}" && "${BUILDER}" "${BUILD_COMMAND}" ${PLATFORMS_ARG} -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} . + cd "${DIR}" && "${BUILDER}" "${BUILD_COMMAND}" ${BUILD_PLATFORMS_ARG} -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} . DOCKER_BUILD_STATUS=$? rm ${DIR}/.Dockerfile if [ $DOCKER_BUILD_STATUS -eq 0 ]; then From 157a605f42d45603022603a1817000244d41b76b Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Thu, 17 Oct 2024 09:59:41 +0200 Subject: [PATCH 3/5] Fixup Signed-off-by: Anatolii Bazko --- .github/workflows/build-pr-check.yml | 6 +++++- build/build.sh | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-pr-check.yml b/.github/workflows/build-pr-check.yml index ea75d678bf..e6a46fce37 100644 --- a/.github/workflows/build-pr-check.yml +++ b/.github/workflows/build-pr-check.yml @@ -29,6 +29,10 @@ jobs: distribution: 'temurin' java-version: '11' cache: 'maven' + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Login to docker.io if: github.event_name == 'pull_request' uses: redhat-actions/podman-login@v1 @@ -47,7 +51,7 @@ jobs: run: mvn -B clean install -U -Pintegration - name: Build images if: github.event_name == 'pull_request' - run: ./build/build.sh --tag:${{ env.PR_IMAGE_TAG }} + run: ./build/build.sh --tag:${{ env.PR_IMAGE_TAG }} --build-platforms:linux/amd64,linux/ppc64le,linux/arm64 - name: Push images if: github.event_name == 'pull_request' run: podman push quay.io/eclipse/che-server:${{ env.PR_IMAGE_TAG }} diff --git a/build/build.sh b/build/build.sh index faf64de722..a67d9359fb 100755 --- a/build/build.sh +++ b/build/build.sh @@ -91,7 +91,7 @@ init() { BUILD_ARGS_CSV="${1#*:}" prepare_build_args $BUILD_ARGS_CSV shift ;; - --build-platforms*:*) + --build-platforms:*) BUILD_PLATFORMS="${1#*:}" shift ;; --*) From 6c1a49b3f06aabb0d5470a767f2edf6309c21360 Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Thu, 17 Oct 2024 12:05:49 +0200 Subject: [PATCH 4/5] fixup Signed-off-by: Anatolii Bazko --- .github/workflows/build-pr-check.yml | 9 ++----- build/build.sh | 38 +++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build-pr-check.yml b/.github/workflows/build-pr-check.yml index e6a46fce37..8fa0f46300 100644 --- a/.github/workflows/build-pr-check.yml +++ b/.github/workflows/build-pr-check.yml @@ -31,8 +31,6 @@ jobs: cache: 'maven' - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - name: Login to docker.io if: github.event_name == 'pull_request' uses: redhat-actions/podman-login@v1 @@ -49,9 +47,6 @@ jobs: registry: quay.io - name: Build with Maven run: mvn -B clean install -U -Pintegration - - name: Build images + - name: Build and push images if: github.event_name == 'pull_request' - run: ./build/build.sh --tag:${{ env.PR_IMAGE_TAG }} --build-platforms:linux/amd64,linux/ppc64le,linux/arm64 - - name: Push images - if: github.event_name == 'pull_request' - run: podman push quay.io/eclipse/che-server:${{ env.PR_IMAGE_TAG }} + run: ./build/build.sh --tag:${{ env.PR_IMAGE_TAG }} --build-platforms:linux/amd64,linux/ppc64le,linux/arm64 --builder:podman --push-image diff --git a/build/build.sh b/build/build.sh index a67d9359fb..efd60a3954 100755 --- a/build/build.sh +++ b/build/build.sh @@ -45,6 +45,7 @@ init() { ORGANIZATION="quay.io/eclipse" PREFIX="che" TAG="next" + PUSH_IMAGE=false SKIP_TESTS=false NAME="che" ARGS="" @@ -53,7 +54,6 @@ init() { BUILD_COMMAND="build" BUILD_ARGS="" BUILD_PLATFORMS="" - BUILD_PLATFORMS_ARG="" while [ $# -gt 0 ]; do case $1 in @@ -81,6 +81,9 @@ init() { --skip-tests) SKIP_TESTS=true shift ;; + --push-image) + PUSH_IMAGE=true + shift ;; --sha-tag) SHA_TAG=$(git rev-parse --short HEAD) shift ;; @@ -94,6 +97,9 @@ init() { --build-platforms:*) BUILD_PLATFORMS="${1#*:}" shift ;; + --builder:*) + BUILDER="${1#*:}" + shift ;; --*) printf "${RED}Unknown parameter: $1${NC}\n"; exit 2 ;; *) @@ -142,10 +148,6 @@ build() { fi fi - if [ ! -z $BUILD_PLATFORMS ]; then - BUILD_PLATFORMS_ARG="--platform ${BUILD_PLATFORMS}" - fi - # If Dockerfile is empty, build all Dockerfiles if [ -z ${DOCKERFILE} ]; then DOCKERFILES_TO_BUILD="$(ls ${DIR}/Dockerfile*)" @@ -180,11 +182,35 @@ build_image() { -e "s;\${BUILD_PREFIX};${PREFIX};" \ -e "s;\${BUILD_TAG};${TAG};" \ > ${DIR}/.Dockerfile - cd "${DIR}" && "${BUILDER}" "${BUILD_COMMAND}" ${BUILD_PLATFORMS_ARG} -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} . + cd "${DIR}" + + if [[ -n $BUILD_PLATFORMS ]]; then + if [[ $BUILDER == "podman" ]]; then + "${BUILDER}" manifest create ${IMAGE_NAME} + "${BUILDER}" "${BUILD_COMMAND}" --platform ${BUILD_PLATFORMS} -f ${DIR}/.Dockerfile --manifest ${IMAGE_NAME} ${BUILD_ARGS} . + else + printf "${RED}Multi-platform image building is only supported for podman builder${NC}\n" + exit 1 + fi + else + "${BUILDER}" "${BUILD_COMMAND}" -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} . + fi + DOCKER_BUILD_STATUS=$? rm ${DIR}/.Dockerfile if [ $DOCKER_BUILD_STATUS -eq 0 ]; then printf "Build of ${BLUE}${IMAGE_NAME} ${GREEN}[OK]${NC}\n" + + if [[ $PUSH_IMAGE == "true" ]]; then + printf "Push image ${BLUE}${IMAGE_NAME} ${NC}\n" + if [[ -n $BUILD_PLATFORMS ]] && [[ $BUILDER == "podman" ]]; then + ${BUILDER} manifest push ${IMAGE_NAME} + else + ${BUILDER} push ${IMAGE_NAME} + fi + printf "Push of ${BLUE}${IMAGE_NAME} ${GREEN}[OK]${NC}\n" + fi + if [ ! -z "${SHA_TAG}" ]; then SHA_IMAGE_NAME=${ORGANIZATION}/${PREFIX}-${NAME}:${SHA_TAG} "${BUILDER}" tag ${IMAGE_NAME} ${SHA_IMAGE_NAME} From deb7d80bf8ae20c5e956cc155fdeed6b5ace3df7 Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Thu, 17 Oct 2024 13:11:17 +0200 Subject: [PATCH 5/5] fixup Signed-off-by: Anatolii Bazko --- build/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build.sh b/build/build.sh index efd60a3954..6790115843 100755 --- a/build/build.sh +++ b/build/build.sh @@ -204,7 +204,7 @@ build_image() { if [[ $PUSH_IMAGE == "true" ]]; then printf "Push image ${BLUE}${IMAGE_NAME} ${NC}\n" if [[ -n $BUILD_PLATFORMS ]] && [[ $BUILDER == "podman" ]]; then - ${BUILDER} manifest push ${IMAGE_NAME} + ${BUILDER} manifest push ${IMAGE_NAME} docker://{IMAGE_NAME} else ${BUILDER} push ${IMAGE_NAME} fi