Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: Build server image for different platforms #728

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 5 additions & 1 deletion .github/workflows/next-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
37 changes: 36 additions & 1 deletion build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ init() {
ORGANIZATION="quay.io/eclipse"
PREFIX="che"
TAG="next"
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,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 ;;
Expand All @@ -89,6 +94,12 @@ init() {
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 Down Expand Up @@ -171,11 +182,35 @@ 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}"

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} docker://{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}
Expand Down
3 changes: 2 additions & 1 deletion 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 @@ -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!"
Expand Down
Loading