Skip to content

Commit

Permalink
feat: Introduce multiplatform che-server image build (#730)
Browse files Browse the repository at this point in the history
* feat: Build server image for different platforms

Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha authored Oct 21, 2024
1 parent 1824619 commit 1a3d96b
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 63 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/build-pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
distribution: 'temurin'
java-version: '11'
cache: 'maven'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Login to docker.io
if: github.event_name == 'pull_request'
uses: redhat-actions/podman-login@v1
Expand All @@ -45,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 }}
- 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
10 changes: 4 additions & 6 deletions .github/workflows/next-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
distribution: 'temurin'
java-version: '11'
cache: 'maven'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Login to docker.io
uses: redhat-actions/podman-login@v1
with:
Expand All @@ -42,15 +44,11 @@ jobs:
registry: quay.io
- name: Build with Maven
run: mvn -B clean install -U -Pintegration
- name: Build images
- name: Build and push images
id: build
run: |
echo "short_sha1=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
./build/build.sh --tag:next --sha-tag
- name: Push docker images
run: |
podman push quay.io/eclipse/che-server:next
podman push quay.io/eclipse/che-server:${{ steps.build.outputs.short_sha1 }}
./build/build.sh --tag:next --sha-tag --build-platforms:linux/amd64,linux/ppc64le,linux/arm64 --builder:podman --push-image
- name: Create failure MM message
if: ${{ failure() }}
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ jobs:
echo "cannot create release, when tag already exists"
exit 1
fi
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Login to docker.io
uses: docker/login-action@v2
with:
Expand Down
132 changes: 107 additions & 25 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@ init() {
ORGANIZATION="quay.io/eclipse"
PREFIX="che"
TAG="next"
LATEST_TAG=false
PUSH_IMAGE=false
SKIP_TESTS=false
NAME="che"
ARGS=""
OPTIONS=""
DOCKERFILE=""
BUILD_COMMAND="build"
BUILD_ARGS=""
BUILD_PLATFORMS=""

while [ $# -gt 0 ]; do
case $1 in
Expand Down Expand Up @@ -79,16 +82,28 @@ init() {
--skip-tests)
SKIP_TESTS=true
shift ;;
--push-image)
PUSH_IMAGE=true
shift ;;
--sha-tag)
SHA_TAG=$(git rev-parse --short HEAD)
shift ;;
--latest-tag)
LATEST_TAG=true
shift ;;
--dockerfile:*)
DOCKERFILE="${1#*:}"
shift ;;
--build-arg*:*)
BUILD_ARGS_CSV="${1#*:}"
prepare_build_args $BUILD_ARGS_CSV
shift ;;
--build-platforms:*)
BUILD_PLATFORMS="${1#*:}"
shift ;;
--builder:*)
BUILDER="${1#*:}"
shift ;;
--*)
printf "${RED}Unknown parameter: $1${NC}\n"; exit 2 ;;
*)
Expand All @@ -97,6 +112,7 @@ init() {
done

IMAGE_NAME="$ORGANIZATION/$PREFIX-$NAME:$TAG"
IMAGE_MANIFEST="$NAME-$TAG"
}

build() {
Expand Down Expand Up @@ -171,41 +187,107 @@ 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} .
DOCKER_BUILD_STATUS=$?
rm ${DIR}/.Dockerfile
if [ $DOCKER_BUILD_STATUS -eq 0 ]; then
printf "Build of ${BLUE}${IMAGE_NAME} ${GREEN}[OK]${NC}\n"
cd "${DIR}"

if [[ -n $BUILD_PLATFORMS ]]; then
if [[ $BUILDER == "podman" ]]; then
printf "${BOLD}Creating manifest ${IMAGE_MANIFEST}${NC}\n"
"${BUILDER}" manifest create ${IMAGE_MANIFEST}
DOCKER_STATUS=$?
if [ ! $DOCKER_STATUS -eq 0 ]; then
printf "${RED}Failure when creating manifest ${IMAGE_MANIFEST}${NC}\n"
exit 1
fi

printf "${BOLD}Building image ${IMAGE_NAME}${NC}\n"
"${BUILDER}" build --platform ${BUILD_PLATFORMS} -f ${DIR}/.Dockerfile --manifest ${IMAGE_MANIFEST} .
DOCKER_STATUS=$?
if [ ! $DOCKER_STATUS -eq 0 ]; then
printf "${RED}Failure when building docker image ${IMAGE_NAME}${NC}\n"
exit 1
fi
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} .
DOCKER_STATUS=$?
if [ ! $DOCKER_STATUS -eq 0 ]; then
printf "${RED}Failure when building docker image ${IMAGE_NAME}${NC}\n"
exit 1
fi
fi

printf "Build of ${BLUE}${IMAGE_NAME} ${GREEN}[OK]${NC}\n"

if [[ $PUSH_IMAGE == "true" ]]; then
push_image ${IMAGE_NAME} ${IMAGE_NAME}

if [ ! -z "${SHA_TAG}" ]; then
SHA_IMAGE_NAME=${ORGANIZATION}/${PREFIX}-${NAME}:${SHA_TAG}
"${BUILDER}" tag ${IMAGE_NAME} ${SHA_IMAGE_NAME}
printf "Re-tagging with SHA based tag ${BLUE}${SHA_IMAGE_NAME} ${GREEN}[OK]${NC}\n"
push_image ${IMAGE_NAME} ${SHA_IMAGE_NAME}
fi

if [[ ${LATEST_TAG} == "true" ]]; then
LATEST_IMAGE_NAME=${ORGANIZATION}/${PREFIX}-${NAME}:latest
printf "Re-tagging with latest tag ${BLUE}${LATEST_IMAGE_NAME} ${GREEN}[OK]${NC}\n"
push_image ${IMAGE_NAME} ${LATEST_IMAGE_NAME}
fi
fi

if [ ! -z "${IMAGE_ALIASES}" ]; then
for TMP_IMAGE_NAME in ${IMAGE_ALIASES}
do
"${BUILDER}" tag ${IMAGE_NAME} ${TMP_IMAGE_NAME}:${TAG}
DOCKER_TAG_STATUS=$?
if [ $DOCKER_TAG_STATUS -eq 0 ]; then
printf "Re-tagging with SHA based tag ${BLUE}${SHA_IMAGE_NAME} ${GREEN}[OK]${NC}\n"
printf " /alias ${BLUE}${TMP_IMAGE_NAME}:${TAG}${NC} ${GREEN}[OK]${NC}\n"
else
printf "${RED}Failure when tagging docker image ${SHA_IMAGE_NAME}${NC}\n"
printf "${RED}Failure when building docker image ${IMAGE_NAME}${NC}\n"
exit 1
fi

done
fi

if [[ -n $BUILD_PLATFORMS ]] && [[ $BUILDER == "podman" ]]; then
# Remove manifest list from local storage
${BUILDER} manifest rm ${IMAGE_MANIFEST}
fi

printf "${GREEN}Script run successfully: ${BLUE}${IMAGE_NAME}${NC}\n"
}

push_image() {
local image=$1
local tagged_image=$2

printf "Pushing manifest ${BLUE}${image} ${NC}\n"
if [[ -n $BUILD_PLATFORMS ]] && [[ $BUILDER == "podman" ]]; then
${BUILDER} manifest push ${IMAGE_MANIFEST} docker://${tagged_image}
DOCKER_STATUS=$?
if [ ! $DOCKER_STATUS -eq 0 ]; then
printf "${RED}Failure when pushing image ${image}${NC}\n"
exit 1
fi
if [ ! -z "${IMAGE_ALIASES}" ]; then
for TMP_IMAGE_NAME in ${IMAGE_ALIASES}
do
"${BUILDER}" tag ${IMAGE_NAME} ${TMP_IMAGE_NAME}:${TAG}
DOCKER_TAG_STATUS=$?
if [ $DOCKER_TAG_STATUS -eq 0 ]; then
printf " /alias ${BLUE}${TMP_IMAGE_NAME}:${TAG}${NC} ${GREEN}[OK]${NC}\n"
else
printf "${RED}Failure when building docker image ${IMAGE_NAME}${NC}\n"
exit 1
fi

done
fi
printf "${GREEN}Script run successfully: ${BLUE}${IMAGE_NAME}${NC}\n"
else
printf "${RED}Failure when building docker image ${IMAGE_NAME}${NC}\n"
exit 1
${BUILDER} tag ${image} ${tagged_image}
DOCKER_STATUS=$?
if [ ! $DOCKER_STATUS -eq 0 ]; then
printf "${RED}Failure when tagging image ${tagged_image}${NC}\n"
exit 1
fi

${BUILDER} push ${image}
DOCKER_STATUS=$?
if [ ! $DOCKER_STATUS -eq 0 ]; then
printf "${RED}Failure when pushing image ${image}${NC}\n"
exit 1
fi
fi
printf "Push of ${BLUE}${tagged_image} ${GREEN}[OK]${NC}\n"
}

get_full_path() {
Expand Down
34 changes: 7 additions & 27 deletions make-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -262,45 +263,26 @@ releaseTypescriptDto() {
popd >/dev/null
}

buildImages() {
export BUILDER="docker"
buildAndPushImages() {
echo "Going to build docker images"
set -e
set -o pipefail
TAG=$1

# stop / rm all containers
if [[ $(docker ps -aq) != "" ]];then
docker rm -f "$(docker ps -aq)"
if [[ $(podman ps -aq) != "" ]];then
podman rm -f "$(podman ps -aq)"
fi

# BUILD IMAGES
bash "$(pwd)/che-server/build/build.sh" --tag:${TAG}
# BUILD AND PUSH IMAGES
bash "$(pwd)/che-server/build/build.sh" --tag:${TAG} --latest-tag --build-platforms:${BUILD_PLATFORMS} --builder:podman --push-image
if [[ $? -ne 0 ]]; then
echo "ERROR:"
echo "build of che-server image $TAG is failed!"
exit 1
fi
}

tagLatestImages() {
echo y | docker tag "${IMAGE}:$1" "${IMAGE}:latest"
if [[ $? -ne 0 ]]; then
die_with "docker tag of '${IMAGE}' image is failed!"
fi
}

pushImagesOnQuay() {
#PUSH THE IMAGE
echo y | docker push "${IMAGE}:$1"
if [[ $2 == "pushLatest" ]]; then
echo y | docker push "${IMAGE}:latest"
fi
if [[ $? -ne 0 ]]; then
die_with "docker push of '${IMAGE}' image is failed!"
fi
}

bumpVersions() {
# infer project version + commit change into ${BASEBRANCH} branch
echo "${BASEBRANCH} ${BRANCH}"
Expand Down Expand Up @@ -404,7 +386,5 @@ releaseCheServer
releaseTypescriptDto

if [[ "${BUILD_AND_PUSH_IMAGES}" = "true" ]]; then
buildImages ${CHE_VERSION}
tagLatestImages ${CHE_VERSION}
pushImagesOnQuay ${CHE_VERSION} pushLatest
buildAndPushImages ${CHE_VERSION}
fi

0 comments on commit 1a3d96b

Please sign in to comment.