From 2fff68b0143b14fc1f6fccdccf3f3f6c69fc79e4 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 18 Sep 2023 14:21:09 +0300 Subject: [PATCH] Modify the build.sh script to work with podman --- .github/workflows/build-pr-check.yml | 10 ++--- .github/workflows/next-build.yml | 10 ++--- build/build.sh | 63 +++++++++++++++------------- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build-pr-check.yml b/.github/workflows/build-pr-check.yml index d2eaf447d3..ea75d678bf 100644 --- a/.github/workflows/build-pr-check.yml +++ b/.github/workflows/build-pr-check.yml @@ -31,23 +31,23 @@ jobs: cache: 'maven' - name: Login to docker.io if: github.event_name == 'pull_request' - uses: docker/login-action@v2 + uses: redhat-actions/podman-login@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} registry: docker.io - name: Login to quay.io if: github.event_name == 'pull_request' - uses: docker/login-action@v2 + uses: redhat-actions/podman-login@v1 with: username: ${{ secrets.QUAY_USERNAME }} password: ${{ secrets.QUAY_PASSWORD }} registry: quay.io - name: Build with Maven run: mvn -B clean install -U -Pintegration - - name: Build docker images + - name: Build images if: github.event_name == 'pull_request' run: ./build/build.sh --tag:${{ env.PR_IMAGE_TAG }} - - name: Push docker images + - name: Push images if: github.event_name == 'pull_request' - run: docker push quay.io/eclipse/che-server:${{ env.PR_IMAGE_TAG }} + run: podman push quay.io/eclipse/che-server:${{ env.PR_IMAGE_TAG }} diff --git a/.github/workflows/next-build.yml b/.github/workflows/next-build.yml index 2a6a464cc0..b95aa18644 100644 --- a/.github/workflows/next-build.yml +++ b/.github/workflows/next-build.yml @@ -29,28 +29,28 @@ jobs: java-version: '11' cache: 'maven' - name: Login to docker.io - uses: docker/login-action@v2 + uses: redhat-actions/podman-login@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} registry: docker.io - name: Login to quay.io - uses: docker/login-action@v2 + uses: redhat-actions/podman-login@v1 with: username: ${{ secrets.QUAY_USERNAME }} password: ${{ secrets.QUAY_PASSWORD }} registry: quay.io - name: Build with Maven run: mvn -B clean install -U -Pintegration - - name: Build docker images + - name: Build 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: | - docker push quay.io/eclipse/che-server:next - docker push quay.io/eclipse/che-server:${{ steps.build.outputs.short_sha1 }} + podman push quay.io/eclipse/che-server:next + podman push quay.io/eclipse/che-server:${{ steps.build.outputs.short_sha1 }} - name: Create failure MM message if: ${{ failure() }} run: | diff --git a/build/build.sh b/build/build.sh index 63b872faac..9c9fbc9fe4 100755 --- a/build/build.sh +++ b/build/build.sh @@ -15,6 +15,7 @@ IMAGE_ALIASES=${IMAGE_ALIASES:-} ERROR=${ERROR:-} DIR=${DIR:-} SHA_TAG=${SHA_TAG:-} +BUILDER=${BUILDER:-} skip_tests() { if [ $SKIP_TESTS = "true" ]; then @@ -104,6 +105,36 @@ build() { DIR=$(cd "$(dirname "$0")"; pwd) fi + if [ -z $BUILDER ]; then + echo "BUILDER is not specified, trying with podman" + BUILDER=$(command -v podman || true) + if [[ ! -x $BUILDER ]]; then + echo "[WARNING] podman is not installed, trying with buildah" + BUILDER=$(command -v buildah || true) + if [[ ! -x $BUILDER ]]; then + echo "[WARNING] buildah is not installed, trying with docker" + BUILDER=$(command -v docker || true) + if [[ ! -x $BUILDER ]]; then + echo "[ERROR] neither docker, buildah, nor podman are installed. Aborting"; exit 1 + fi + else + BUILD_COMMAND="bud" + fi + fi + else + if [[ ! -x $(command -v "$BUILDER" || true) ]]; then + echo "Builder $BUILDER is missing. Aborting."; exit 1 + fi + if [[ $BUILDER =~ "docker" || $BUILDER =~ "podman" ]]; then + if [[ ! $($BUILDER ps) ]]; then + echo "Builder $BUILDER is not functioning. Aborting."; exit 1 + fi + fi + if [[ $BUILDER =~ "buildah" ]]; then + BUILD_COMMAND="bud" + fi + fi + # If Dockerfile is empty, build all Dockerfiles if [ -z ${DOCKERFILE} ]; then DOCKERFILES_TO_BUILD="$(ls ${DIR}/Dockerfile*)" @@ -138,14 +169,14 @@ build_image() { -e "s;\${BUILD_PREFIX};${PREFIX};" \ -e "s;\${BUILD_TAG};${TAG};" \ > ${DIR}/.Dockerfile - cd "${DIR}" && docker build -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} . + cd "${DIR}" && "${BUILDER}" build -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" if [ ! -z "${SHA_TAG}" ]; then SHA_IMAGE_NAME=${ORGANIZATION}/${PREFIX}-${NAME}:${SHA_TAG} - docker tag ${IMAGE_NAME} ${SHA_IMAGE_NAME} + "${BUILDER}" tag ${IMAGE_NAME} ${SHA_IMAGE_NAME} 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" @@ -157,7 +188,7 @@ build_image() { if [ ! -z "${IMAGE_ALIASES}" ]; then for TMP_IMAGE_NAME in ${IMAGE_ALIASES} do - docker tag ${IMAGE_NAME} ${TMP_IMAGE_NAME}:${TAG} + "${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" @@ -175,32 +206,6 @@ build_image() { fi } -check_docker() { - if ! docker ps > /dev/null 2>&1; then - output=$(docker ps) - printf "${RED}Docker not installed properly: ${output}${NC}\n" - exit 1 - fi -} - -docker_exec() { - if has_docker_for_windows_client; then - MSYS_NO_PATHCONV=1 docker.exe "$@" - else - "$(which docker)" "$@" - fi -} - -has_docker_for_windows_client() { - GLOBAL_HOST_ARCH=$(docker version --format {{.Client}}) - - if [[ "${GLOBAL_HOST_ARCH}" = *"windows"* ]]; then - return 0 - else - return 1 - fi -} - get_full_path() { echo "$(cd "$(dirname "${1}")"; pwd)/$(basename "$1")" }