From f6d8b8e08fc7b5e39f611d39c5643beecf6a3874 Mon Sep 17 00:00:00 2001 From: Vitaliy Gulyy Date: Wed, 8 Nov 2023 18:41:07 +0200 Subject: [PATCH] fix: revert back PR-ceck actions to build images (#296) Signed-off-by: vitaliy-guliy --- .../pr-check-build-che-code-image.yaml | 155 ------------------ .github/workflows/pr-check-image-publish.yml | 111 +++++++++++++ .github/workflows/pr-check.yml | 92 +++++++++++ 3 files changed, 203 insertions(+), 155 deletions(-) delete mode 100644 .github/workflows/pr-check-build-che-code-image.yaml create mode 100644 .github/workflows/pr-check-image-publish.yml create mode 100644 .github/workflows/pr-check.yml diff --git a/.github/workflows/pr-check-build-che-code-image.yaml b/.github/workflows/pr-check-build-che-code-image.yaml deleted file mode 100644 index 7ebb8470bf2..00000000000 --- a/.github/workflows/pr-check-build-che-code-image.yaml +++ /dev/null @@ -1,155 +0,0 @@ -# -# Copyright (c) 2023 Red Hat, Inc. -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# -# Contributors: -# Red Hat, Inc. - initial API and implementation -# - -name: Pull Request Check - -# Trigger the workflow on pull request -on: [pull_request] - -jobs: - build: - name: build - runs-on: ubuntu-22.04 - strategy: - fail-fast: false - matrix: - dist: [ 'musl', 'libc' ] - arch: ['amd64'] - steps: - - - name: Checkout che-code source code - uses: actions/checkout@v3 - - - name: Compile che-code - run: | - docker buildx build \ - --platform linux/${{matrix.arch}} \ - --progress=plain \ - -f build/dockerfiles/linux-${{matrix.dist}}.Dockerfile \ - -t linux-${{matrix.dist}}-${{matrix.arch}} . - - - name: Upload image - uses: ishworkh/docker-image-artifact-upload@v1 - with: - image: "linux-${{matrix.dist}}-${{matrix.arch}}" - - assemble: - name: assemble - runs-on: ubuntu-22.04 - needs: build - steps: - - - name: Checkout che-code source code - uses: actions/checkout@v3 - - - name: Cleanup docker images - run: | - docker system prune -af - - - name: Download linux-libc-amd64 image - uses: ishworkh/docker-image-artifact-download@v1 - with: - image: "linux-libc-amd64" - - - name: Download linux-musl-amd64 image - uses: ishworkh/docker-image-artifact-download@v1 - with: - image: "linux-musl-amd64" - - - name: Login to Quay.io - uses: docker/login-action@v2 - with: - registry: quay.io - username: ${{ secrets.QUAY_PULL_REQUESTS_USERNAME }} - password: ${{ secrets.QUAY_PULL_REQUESTS_PASSWORD }} - - - name: Display docker images - run: | - docker images - - - name: Assemble che-code - run: | - PR_NUMBER="${{ github.event.number }}" - echo "Pull request $PR_NUMBER" - - IMAGE_NAME="quay.io/che-incubator-pull-requests/che-code:pr-$PR_NUMBER-amd64" - echo "_IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV - - docker buildx build \ - --platform linux/amd64 \ - --progress=plain \ - --push \ - -f build/dockerfiles/assembly.Dockerfile \ - -t ${IMAGE_NAME} . - - - name: Display docker images (final) - run: | - docker images - - - name: 'Comment PR' - uses: actions/github-script@v6 - with: - script: | - const { repo: { owner, repo } } = context; - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: `Pull Request Che-Code image published:\nšŸ‘‰ [${process.env._IMAGE_NAME}](https://${process.env._IMAGE_NAME})` - }) - - dev: - name: dev - runs-on: ubuntu-22.04 - steps: - - - name: Checkout che-code source code - uses: actions/checkout@v2 - - - name: Login to Quay.io - uses: docker/login-action@v2 - with: - registry: quay.io - username: ${{ secrets.QUAY_PULL_REQUESTS_USERNAME }} - password: ${{ secrets.QUAY_PULL_REQUESTS_PASSWORD }} - - - name: Build Che-Code Docker image - run: | - PR_NUMBER="${{ github.event.number }}" - echo "Pull request $PR_NUMBER" - - DEV_IMAGE_NAME="quay.io/che-incubator-pull-requests/che-code-dev:pr-$PR_NUMBER-dev-amd64" - echo "Dev image $DEV_IMAGE_NAME" - echo "_DEV_IMAGE_NAME=${DEV_IMAGE_NAME}" >> $GITHUB_ENV - - docker buildx build \ - --platform linux/amd64 \ - --progress=plain \ - --push \ - -f build/dockerfiles/dev.Dockerfile \ - -t ${DEV_IMAGE_NAME} . - - - name: Display docker images - run: | - docker images - - - name: 'Comment PR' - uses: actions/github-script@v6 - with: - script: | - const { repo: { owner, repo } } = context; - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: `Pull Request Dev image published:\nšŸ‘‰ [${process.env._DEV_IMAGE_NAME}](https://${process.env._DEV_IMAGE_NAME})` - }) diff --git a/.github/workflows/pr-check-image-publish.yml b/.github/workflows/pr-check-image-publish.yml new file mode 100644 index 00000000000..e3b883a7c0b --- /dev/null +++ b/.github/workflows/pr-check-image-publish.yml @@ -0,0 +1,111 @@ +# +# Copyright (c) 2021 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# + +name: Publish Image PR check + +on: + workflow_run: + workflows: ["Pull Request Check"] + types: + - completed + +jobs: + publish-image-pull-request: + name: publish image from the pull request + runs-on: ubuntu-22.04 + steps: + - name: PR number + uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: pull-request-number + - name: Grab pull request number + run: | + pr_number=$(cat "PR_NUMBER") + if ! [[ "$pr_number" =~ ^[0-9]+$ ]]; then + echo "pr number invalid" + exit 1 + fi + echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV + - name: PR sha + uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: pull-request-sha + - name: Grab pull request sha1 + run: | + pr_sha=$(cat "PR_SHA") + echo "PR_SHA=$pr_sha" >> $GITHUB_ENV + - name: Login to Quay.io + uses: docker/login-action@v2 + with: + registry: quay.io + username: ${{ secrets.QUAY_PULL_REQUESTS_USERNAME }} + password: ${{ secrets.QUAY_PULL_REQUESTS_PASSWORD }} + - name: Increase Swap Space # implemented for the Linux system only + if: runner.os == 'Linux' + shell: bash + run: | + echo "Current swap area:" + sudo swapon --show + + export SWAP_SIZE=7 + export SWAP_FILE_PATH=$(swapon --show=NAME | tail -n 1) + + sudo swapoff $SWAP_FILE_PATH + sudo rm $SWAP_FILE_PATH + + sudo fallocate -l ${SWAP_SIZE}G $SWAP_FILE_PATH + sudo chmod 600 $SWAP_FILE_PATH + sudo mkswap $SWAP_FILE_PATH + sudo swapon $SWAP_FILE_PATH + + echo "Updated swap area:" + sudo swapon --show + - name: Download assembly image + uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: action_image_artifact_assembly-pr + path: assembly-image/ + - name: Load docker image + run: | + ls -la assembly-image/ + docker load -i assembly-image/assembly-pr + - name: Docker Push + run: | + export IMAGE_NAME=quay.io/che-incubator-pull-requests/che-code:pr-${{env.PR_NUMBER}}-amd64 + docker tag assembly-pr ${IMAGE_NAME} + docker push ${IMAGE_NAME} + echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV + - name: Download dev image + uses: dawidd6/action-download-artifact@v2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: dev-image + - name: Load dev Docker image + run: | + docker load -i dev-pr.tgz + - name: Docker Push + run: | + export DEV_IMAGE_NAME=quay.io/che-incubator-pull-requests/che-code-dev:pr-${{env.PR_NUMBER}}-dev-amd64 + docker tag dev-pr ${DEV_IMAGE_NAME} + docker push ${DEV_IMAGE_NAME} + echo "DEV_IMAGE_NAME=${DEV_IMAGE_NAME}" >> $GITHUB_ENV + - name: 'Comment PR' + uses: actions/github-script@v6 + with: + script: | + const { repo: { owner, repo } } = context; + await github.rest.issues.createComment({ + issue_number: process.env.PR_NUMBER, + owner: context.repo.owner, + repo: context.repo.repo, + body: `Pull Request images published āœØ\nimage: ${process.env.IMAGE_NAME}\n Dev image: ${process.env.DEV_IMAGE_NAME}` + }) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml new file mode 100644 index 00000000000..1b31e5c4ad2 --- /dev/null +++ b/.github/workflows/pr-check.yml @@ -0,0 +1,92 @@ +# +# Copyright (c) 2021 Red Hat, Inc. +# This program and the accompanying materials are made +# available under the terms of the Eclipse Public License 2.0 +# which is available at https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# + +name: Pull Request Check + +# Trigger the workflow on pull request +on: [pull_request] + +jobs: + + build: + name: build + strategy: + fail-fast: false + matrix: + dist: [ 'musl', 'libc' ] + arch: ['amd64'] + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Docker Build + env: + # https://github.com/microsoft/vscode-ripgrep#github-api-limit-note + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + docker buildx build --memory-swap -1 --memory 10g --platform linux/${{matrix.arch}} -f build/dockerfiles/linux-${{matrix.dist}}.Dockerfile --load -t linux-${{matrix.dist}}-${{matrix.arch}} . + - name: Upload image + uses: ishworkh/docker-image-artifact-upload@v1 + with: + image: "linux-${{matrix.dist}}-${{matrix.arch}}" + assemble: + name: assemble + needs: build + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Download linux-libc-amd64 image + uses: ishworkh/docker-image-artifact-download@v1 + with: + image: "linux-libc-amd64" + - name: Download linux-musl image + uses: ishworkh/docker-image-artifact-download@v1 + with: + image: "linux-musl-amd64" + - name: Display docker images + run: | + docker images + - name: Docker Build + run: | + docker buildx build --platform linux/amd64 -f build/dockerfiles/assembly.Dockerfile --load -t assembly-pr . + - name: Upload assembly image + uses: ishworkh/docker-image-artifact-upload@v1 + with: + image: "assembly-pr" + - name: Store PR info + run: | + echo "${{ github.event.number }}" > PR_NUMBER + echo "${{ github.event.pull_request.head.sha }}" > PR_SHA + - uses: actions/upload-artifact@v3 + with: + name: pull-request-number + path: PR_NUMBER + - uses: actions/upload-artifact@v3 + with: + name: pull-request-sha + path: PR_SHA + dev: + name: dev + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Docker Build + run: | + docker buildx build --platform linux/amd64 -f build/dockerfiles/dev.Dockerfile --load -t dev-pr . + docker save dev-pr | gzip > dev-pr.tgz + - uses: actions/upload-artifact@v3 + with: + name: dev-image + path: dev-pr.tgz