From 135214b9a3beaa93b01b0277e49028eb98ed0735 Mon Sep 17 00:00:00 2001 From: Prabhav Thali Date: Wed, 12 May 2021 18:06:18 +0530 Subject: [PATCH 1/3] feat(CI): Adds Travis CI support Signed-off-by: Prabhav Thali --- .travis.yml | 147 +++++++++++++++++++++++++++++++++++ .travis/build_image.sh | 12 +++ .travis/pr_check.sh | 11 +++ .travis/publish_multiarch.sh | 18 +++++ make-release.sh | 30 ++----- 5 files changed, 195 insertions(+), 23 deletions(-) create mode 100644 .travis.yml create mode 100755 .travis/build_image.sh create mode 100755 .travis/pr_check.sh create mode 100755 .travis/publish_multiarch.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..e86fc6b76 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,147 @@ +language: go + +go: +- 1.12.8 + +os: linux +dist: focal + +git: + depth: false + +services: + - docker + +env: + global: + - TAG=nightly + - RECREATE_TAGS=false + - NO_COMMIT='' + - REGISTRY=quay.io + - ORGANIZATION=eclipse + - IMAGE=che-machine-exec + +install: + - git remote set-url origin https://$GITHUB_TOKEN@github.com/eclipse-che/che-machine-exec.git + - export SHORT_SHA=$(git rev-parse --short HEAD) + - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + - echo "$QUAY_PASSWORD" | docker login quay.io -u "$QUAY_USERNAME " --password-stdin + +jobs: + include: + - stage: Code Coverage Report + if: type = push + arch: amd64 + install: + - export GO111MODULE="on" + - go get ${gobuild_args} ./... + script: + - | + echo "" > coverage.txt + export CHE_WORKSPACE_ID=test_id; go test -v ./... -coverprofile coverage.txt + bash <(curl -s https://codecov.io/bash) + + - &unit-test + stage: Unit tests and Docker build PR + if: type = pull_request + install: + - export GO111MODULE="on" + - go get ${gobuild_args} ./... + script: bash .travis/pr_check.sh + name: PR check on amd64 + arch: amd64 + - <<: *unit-test + name: PR check on arm64 + arch: arm64 + - <<: *unit-test + name: PR check on ppc64le + arch: ppc64le + - <<: *unit-test + name: PR check on s390x + arch: s390x + + - &nightly-build + stage: Build and push both short SHA tag and nightly tag + if: type = push AND branch = main AND env(TAG) = "nightly" + script: + - bash .travis/build_image.sh + name: Build image on amd64 + arch: amd64 + + - <<: *nightly-build + name: Build image on arm64 + arch: arm64 + + - <<: *nightly-build + name: Build image on ppc64le + arch: ppc64le + + - <<: *nightly-build + name: Build image on s390x + arch: s390x + + - stage: Publish multiarch image with nightly & short_sha tag + if: type = push AND branch = main AND env(TAG) = "nightly" + script: bash .travis/publish_multiarch.sh + + - stage: Check existing tags + if: type = api AND env(TAG) != "nightly" + arch: amd64 + script: + - | + set +e + VERSION=$TAG + EXISTING_TAG=$(git ls-remote --exit-code origin refs/tags/${VERSION}) + if [[ -n ${EXISTING_TAG} ]]; then + if [[ ${RECREATE_TAGS} == "true" ]]; then + echo "[INFO] Removing tag for ${VERSION} version. New tag will be recreated during release." + git push origin :$VERSION + else + echo "[ERROR] Cannot proceed with release - tag ${EXISTING_TAG} already exists." + exit 1 + fi + else + echo "[INFO] No existing tags detected for $VERSION" + fi + + - &release-build + stage: Build images for release version + if: type = api AND env(TAG) != "nightly" + script: + - bash .travis/build_image.sh + name: Build image on amd64 + arch: amd64 + + - <<: *release-build + name: Build image on arm64 + arch: arm64 + + - <<: *release-build + name: Build image on ppc64le + arch: ppc64le + + - <<: *release-build + name: Build image on s390x + arch: s390x + + - stage: Publish multiarch image with release tag + if: type = api AND env(TAG) != "nightly" + script: bash .travis/publish_multiarch.sh + + - stage: Tag release and notify on mattermost + if: type = api AND env(TAG) != "nightly" + script: + - git config --global user.name "Mykhailo Kuznietsov" + - git config --global user.email "mkuznets@redhat.com" + - bash make-release.sh --version $TAG --tag-release $NO_COMMIT + after_success: + - | + set -e + echo "{\"username\":\"che-bot\",\"channel\":\"eclipse-che-releases\",\"text\":\":white_check_mark: Che Machine Exec ${TAG} has been released: https://quay.io/eclipse/che-machine-exec:${TAG}\"}" > mattermost.json + curl -i -X POST -H 'Content-Type: application/json' -d @mattermost.json $MATTERMOST_WEBHOOK_URL + + after_failure: + - | + set -e + echo "{\"username\":\"che-bot\",\"channel\":\"eclipse-che-releases\",\"text\":\":no_entry_sign: Che Machine Exec ${TAG} release has failed: https://github.com/eclipse-che/che-machine-exec/actions/workflows/release.yml\"}" > mattermost.json + curl -i -X POST -H 'Content-Type: application/json' -d @mattermost.json $MATTERMOST_WEBHOOK_URL diff --git a/.travis/build_image.sh b/.travis/build_image.sh new file mode 100755 index 000000000..8a8778acb --- /dev/null +++ b/.travis/build_image.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +# Build images +docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-${TRAVIS_CPU_ARCH}" . +docker push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-${TRAVIS_CPU_ARCH}" + +# Tag image with short_sha in case of nightly build +if [[ "$TAG" == "nightly" ]]; then + docker tag "${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-${TRAVIS_CPU_ARCH}" "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_CPU_ARCH}" + docker push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_CPU_ARCH}" +fi diff --git a/.travis/pr_check.sh b/.travis/pr_check.sh new file mode 100755 index 000000000..3d30daee3 --- /dev/null +++ b/.travis/pr_check.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +# Build che-machine-exec binary and execute unit tests +CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags '-w -s' -a -installsuffix cgo -o che-machine-exec . +export CHE_WORKSPACE_ID=test_id +go test ./... -test.v + +# Build image with pr-check tag +docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:pr-check-${TRAVIS_CPU_ARCH}" . diff --git a/.travis/publish_multiarch.sh b/.travis/publish_multiarch.sh new file mode 100755 index 000000000..dca0ca5aa --- /dev/null +++ b/.travis/publish_multiarch.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e + +# Create amend with images built on individual architectures +AMEND="" +AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-amd64"; +AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-arm64"; +AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-ppc64le"; +AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-s390x"; + +# Create manifest and push multiarch image +docker manifest create "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}" $AMEND +docker manifest push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}" + +if [[ "$TAG" == "nightly" ]]; then + docker manifest create "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}" $AMEND + docker manifest push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}" +fi diff --git a/make-release.sh b/make-release.sh index d1231a172..f22937393 100755 --- a/make-release.sh +++ b/make-release.sh @@ -12,20 +12,15 @@ # Release process automation script. # Used to create branch/tag, update VERSION files -# and and trigger release by force pushing changes to the release branch +# and trigger release by force pushing changes to the release branch -# set to 1 to actually trigger changes in the release branch -TRIGGER_RELEASE=0 +# set to 1 to actually tag changes +TAG_RELEASE=0 NOCOMMIT=0 -REGISTRY="quay.io" -DOCKERFILE="build/dockerfiles/Dockerfile" -ORGANIZATION="eclipse" -IMAGE="che-machine-exec" - while [[ "$#" -gt 0 ]]; do case $1 in - '-t'|'--trigger-release') TRIGGER_RELEASE=1; shift 0;; + '-t'|'--tag-release') TAG_RELEASE=1; shift 0;; '-v'|'--version') VERSION="$2"; shift 1;; '-n'|'--no-commit') NOCOMMIT=1; shift 0;; esac @@ -34,8 +29,8 @@ done usage () { - echo "Usage: $0 --version [VERSION TO RELEASE] [--trigger-release]" - echo "Example: $0 --version 7.7.0 --trigger-release"; echo + echo "Usage: $0 --version [VERSION TO RELEASE] [--tag-release]" + echo "Example: $0 --version 7.7.0 --tag-release"; echo } if [[ ! ${VERSION} ]]; then @@ -43,14 +38,6 @@ if [[ ! ${VERSION} ]]; then exit 1 fi -releaseMachineExec() { - # docker buildx includes automated push to registry, so build using tag we want published, not just local ${IMAGE} - docker buildx build \ - --tag "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${VERSION}" --push \ - -f ./${DOCKERFILE} . --platform "linux/amd64,linux/ppc64le,linux/arm64" | cat - echo "Pushed ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${VERSION}" -} - # derive branch from version BRANCH=${VERSION%.*}.x @@ -84,10 +71,7 @@ if [[ ${NOCOMMIT} -eq 0 ]]; then git push origin "${BRANCH}" fi -if [[ $TRIGGER_RELEASE -eq 1 ]]; then - # push new branch to release branch to trigger CI build - releaseMachineExec - +if [[ $TAG_RELEASE -eq 1 ]]; then # tag the release git checkout "${BRANCH}" git tag "${VERSION}" From a299ff4f8c0f125b00b0f3a2d6dc598c0c913d33 Mon Sep 17 00:00:00 2001 From: Prabhav Thali Date: Wed, 23 Jun 2021 19:59:08 +0530 Subject: [PATCH 2/3] Adds travis suffix and removes workflows handled on GA --- .github/workflows/gh_actions_pr.yaml | 25 +++++ .github/workflows/next-build.yaml | 19 ++++ .github/workflows/release.yml | 25 +++++ .travis.yml | 145 +++++++++++---------------- .travis/build_image.sh | 12 +-- .travis/pr_check.sh | 11 -- .travis/publish_multiarch.sh | 18 ++-- make-release.sh | 30 ++++-- 8 files changed, 167 insertions(+), 118 deletions(-) delete mode 100755 .travis/pr_check.sh diff --git a/.github/workflows/gh_actions_pr.yaml b/.github/workflows/gh_actions_pr.yaml index eec45fa13..e37e8e05f 100644 --- a/.github/workflows/gh_actions_pr.yaml +++ b/.github/workflows/gh_actions_pr.yaml @@ -29,3 +29,28 @@ jobs: platforms: linux/amd64,linux/ppc64le,linux/arm64 push: false tags: quay.io/eclipse/che-machine-exec:pr-check + + travis-build: + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Trigger build on Travis CI + run: | + body="{ + \"request\":{ + \"config\": { + \"env\": { + \"global\": [ + \"PR_NUMBER=${{ github.event.pull_request.number }}\" + ] + } + } + }}" + + curl -s -X POST \ + -H "Content-Type: application/json" \ + -H "Accept: application/json" \ + -H "Travis-API-Version: 3" \ + -H "Authorization: token ${{ secrets.TRAVIS_TOKEN }}" \ + -d "$body" \ + https://api.travis-ci.com/repo/eclipse-che%2Fche-machine-exec/requests diff --git a/.github/workflows/next-build.yaml b/.github/workflows/next-build.yaml index b6ce90fb3..af365cb7d 100644 --- a/.github/workflows/next-build.yaml +++ b/.github/workflows/next-build.yaml @@ -43,3 +43,22 @@ jobs: tags: | quay.io/eclipse/che-machine-exec:next quay.io/eclipse/che-machine-exec:${{ steps.vars.outputs.sha_short }} + + travis-build: + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Trigger build on Travis CI + run: | + body="{ + \"request\":{ + \"branch\":\"main\" + }}" + + curl -s -X POST \ + -H "Content-Type: application/json" \ + -H "Accept: application/json" \ + -H "Travis-API-Version: 3" \ + -H "Authorization: token ${{ secrets.TRAVIS_TOKEN }}" \ + -d "$body" \ + https://api.travis-ci.com/repo/eclipse-che%2Fche-machine-exec/requests diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 21c87988d..158add8c0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -94,3 +94,28 @@ jobs: MATTERMOST_CHANNEL: eclipse-che-releases MATTERMOST_USERNAME: che-bot + travis-build: + needs: build + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Trigger build on Travis CI + run: | + body="{ + \"request\":{ + \"config\": { + \"env\": { + \"global\": [ + \"TAG=${{ github.event.inputs.version }}\" + ] + } + } + }}" + + curl -s -X POST \ + -H "Content-Type: application/json" \ + -H "Accept: application/json" \ + -H "Travis-API-Version: 3" \ + -H "Authorization: token ${{ secrets.TRAVIS_TOKEN }}" \ + -d "$body" \ + https://api.travis-ci.com/repo/eclipse-che%2Fche-machine-exec/requests diff --git a/.travis.yml b/.travis.yml index e86fc6b76..fd0bf8521 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: -- 1.12.8 +- "1.15" os: linux dist: focal @@ -9,139 +9,114 @@ dist: focal git: depth: false -services: - - docker - env: global: - - TAG=nightly - - RECREATE_TAGS=false - - NO_COMMIT='' + - TAG=next + - TRAVIS_TAG=travis - REGISTRY=quay.io - ORGANIZATION=eclipse - IMAGE=che-machine-exec + - PR_NUMBER= install: - - git remote set-url origin https://$GITHUB_TOKEN@github.com/eclipse-che/che-machine-exec.git - export SHORT_SHA=$(git rev-parse --short HEAD) - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - echo "$QUAY_PASSWORD" | docker login quay.io -u "$QUAY_USERNAME " --password-stdin jobs: + fast_finish: true + allow_failures: + - if: env(PR_NUMBER) IS present + arch: arm64 + - if: env(PR_NUMBER) IS present + arch: ppc64le + - if: env(PR_NUMBER) IS present + arch: s390x include: - - stage: Code Coverage Report - if: type = push + - &docker-build-pr + stage: PR Check + if: env(PR_NUMBER) IS present + name: Check docker build on amd64 arch: amd64 - install: - - export GO111MODULE="on" - - go get ${gobuild_args} ./... - script: - - | - echo "" > coverage.txt - export CHE_WORKSPACE_ID=test_id; go test -v ./... -coverprofile coverage.txt - bash <(curl -s https://codecov.io/bash) + install: + - git fetch origin +refs/pull/${PR_NUMBER}/merge + - git checkout -qf FETCH_HEAD + script: docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:pr-check-${TRAVIS_CPU_ARCH}" . + - <<: *docker-build-pr + name: Check docker build on arm64 + arch: arm64 + - <<: *docker-build-pr + name: Check docker build on ppc64le + arch: ppc64le + - <<: *docker-build-pr + name: check docker build PR on s390x + arch: s390x - &unit-test - stage: Unit tests and Docker build PR - if: type = pull_request + if: env(PR_NUMBER) IS present + name: Run unit tests on amd64 + arch: amd64 install: + - git fetch origin +refs/pull/${PR_NUMBER}/merge + - git checkout -qf FETCH_HEAD - export GO111MODULE="on" - go get ${gobuild_args} ./... - script: bash .travis/pr_check.sh - name: PR check on amd64 - arch: amd64 + script: + - | + CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags '-w -s' -a -installsuffix cgo -o che-machine-exec . + export CHE_WORKSPACE_ID=test_id + go test ./... -test.v - <<: *unit-test - name: PR check on arm64 + name: Run unit tests on arm64 arch: arm64 - <<: *unit-test - name: PR check on ppc64le + name: Run unit tests on ppc64le arch: ppc64le - <<: *unit-test - name: PR check on s390x + name: Run unit tests on s390x arch: s390x - - &nightly-build - stage: Build and push both short SHA tag and nightly tag - if: type = push AND branch = main AND env(TAG) = "nightly" - script: - - bash .travis/build_image.sh + - &next-build + stage: Build and push both short SHA tag and next tag + if: type = api AND branch = main AND env(TAG) = "next" name: Build image on amd64 arch: amd64 - - - <<: *nightly-build + script: + - bash .travis/build_image.sh + - <<: *next-build name: Build image on arm64 arch: arm64 - - - <<: *nightly-build + - <<: *next-build name: Build image on ppc64le arch: ppc64le - - - <<: *nightly-build + - <<: *next-build name: Build image on s390x arch: s390x - - stage: Publish multiarch image with nightly & short_sha tag - if: type = push AND branch = main AND env(TAG) = "nightly" + - stage: Publish multiarch image with next & short_sha tag + if: type = api AND branch = main AND env(TAG) = "next" script: bash .travis/publish_multiarch.sh - - stage: Check existing tags - if: type = api AND env(TAG) != "nightly" - arch: amd64 - script: - - | - set +e - VERSION=$TAG - EXISTING_TAG=$(git ls-remote --exit-code origin refs/tags/${VERSION}) - if [[ -n ${EXISTING_TAG} ]]; then - if [[ ${RECREATE_TAGS} == "true" ]]; then - echo "[INFO] Removing tag for ${VERSION} version. New tag will be recreated during release." - git push origin :$VERSION - else - echo "[ERROR] Cannot proceed with release - tag ${EXISTING_TAG} already exists." - exit 1 - fi - else - echo "[INFO] No existing tags detected for $VERSION" - fi - - &release-build - stage: Build images for release version - if: type = api AND env(TAG) != "nightly" - script: - - bash .travis/build_image.sh + stage: Release che-machine-exec + if: type = api AND env(TAG) IS present AND env(TAG) != "next" name: Build image on amd64 arch: amd64 - + script: + - | + BRANCH=${TAG%.*}.x + git checkout "${BRANCH}" + bash .travis/build_image.sh - <<: *release-build name: Build image on arm64 arch: arm64 - - <<: *release-build name: Build image on ppc64le arch: ppc64le - - <<: *release-build name: Build image on s390x arch: s390x - stage: Publish multiarch image with release tag - if: type = api AND env(TAG) != "nightly" + if: type = api AND env(TAG) IS present AND env(TAG) != "next" script: bash .travis/publish_multiarch.sh - - - stage: Tag release and notify on mattermost - if: type = api AND env(TAG) != "nightly" - script: - - git config --global user.name "Mykhailo Kuznietsov" - - git config --global user.email "mkuznets@redhat.com" - - bash make-release.sh --version $TAG --tag-release $NO_COMMIT - after_success: - - | - set -e - echo "{\"username\":\"che-bot\",\"channel\":\"eclipse-che-releases\",\"text\":\":white_check_mark: Che Machine Exec ${TAG} has been released: https://quay.io/eclipse/che-machine-exec:${TAG}\"}" > mattermost.json - curl -i -X POST -H 'Content-Type: application/json' -d @mattermost.json $MATTERMOST_WEBHOOK_URL - - after_failure: - - | - set -e - echo "{\"username\":\"che-bot\",\"channel\":\"eclipse-che-releases\",\"text\":\":no_entry_sign: Che Machine Exec ${TAG} release has failed: https://github.com/eclipse-che/che-machine-exec/actions/workflows/release.yml\"}" > mattermost.json - curl -i -X POST -H 'Content-Type: application/json' -d @mattermost.json $MATTERMOST_WEBHOOK_URL diff --git a/.travis/build_image.sh b/.travis/build_image.sh index 8a8778acb..bf269fbf4 100755 --- a/.travis/build_image.sh +++ b/.travis/build_image.sh @@ -2,11 +2,11 @@ set -e # Build images -docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-${TRAVIS_CPU_ARCH}" . -docker push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-${TRAVIS_CPU_ARCH}" +docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-${TRAVIS_CPU_ARCH}" . +docker push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-${TRAVIS_CPU_ARCH}" -# Tag image with short_sha in case of nightly build -if [[ "$TAG" == "nightly" ]]; then - docker tag "${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-${TRAVIS_CPU_ARCH}" "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_CPU_ARCH}" - docker push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_CPU_ARCH}" +# Tag image with short_sha in case of next build +if [[ "$TAG" == "next" ]]; then + docker tag "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-${TRAVIS_CPU_ARCH}" "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_TAG}-${TRAVIS_CPU_ARCH}" + docker push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_TAG}-${TRAVIS_CPU_ARCH}" fi diff --git a/.travis/pr_check.sh b/.travis/pr_check.sh deleted file mode 100755 index 3d30daee3..000000000 --- a/.travis/pr_check.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -set -e - -# Build che-machine-exec binary and execute unit tests -CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags '-w -s' -a -installsuffix cgo -o che-machine-exec . -export CHE_WORKSPACE_ID=test_id -go test ./... -test.v - -# Build image with pr-check tag -docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:pr-check-${TRAVIS_CPU_ARCH}" . diff --git a/.travis/publish_multiarch.sh b/.travis/publish_multiarch.sh index dca0ca5aa..39eec45ab 100755 --- a/.travis/publish_multiarch.sh +++ b/.travis/publish_multiarch.sh @@ -3,16 +3,16 @@ set -e # Create amend with images built on individual architectures AMEND="" -AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-amd64"; -AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-arm64"; -AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-ppc64le"; -AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:$TAG-s390x"; +AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-amd64"; +AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-arm64"; +AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-ppc64le"; +AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-s390x"; # Create manifest and push multiarch image -docker manifest create "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}" $AMEND -docker manifest push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}" +docker manifest create "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}" $AMEND +docker manifest push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}" -if [[ "$TAG" == "nightly" ]]; then - docker manifest create "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}" $AMEND - docker manifest push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}" +if [[ "$TAG" == "next" ]]; then + docker manifest create "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_TAG}" $AMEND + docker manifest push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_TAG}" fi diff --git a/make-release.sh b/make-release.sh index f22937393..d1231a172 100755 --- a/make-release.sh +++ b/make-release.sh @@ -12,15 +12,20 @@ # Release process automation script. # Used to create branch/tag, update VERSION files -# and trigger release by force pushing changes to the release branch +# and and trigger release by force pushing changes to the release branch -# set to 1 to actually tag changes -TAG_RELEASE=0 +# set to 1 to actually trigger changes in the release branch +TRIGGER_RELEASE=0 NOCOMMIT=0 +REGISTRY="quay.io" +DOCKERFILE="build/dockerfiles/Dockerfile" +ORGANIZATION="eclipse" +IMAGE="che-machine-exec" + while [[ "$#" -gt 0 ]]; do case $1 in - '-t'|'--tag-release') TAG_RELEASE=1; shift 0;; + '-t'|'--trigger-release') TRIGGER_RELEASE=1; shift 0;; '-v'|'--version') VERSION="$2"; shift 1;; '-n'|'--no-commit') NOCOMMIT=1; shift 0;; esac @@ -29,8 +34,8 @@ done usage () { - echo "Usage: $0 --version [VERSION TO RELEASE] [--tag-release]" - echo "Example: $0 --version 7.7.0 --tag-release"; echo + echo "Usage: $0 --version [VERSION TO RELEASE] [--trigger-release]" + echo "Example: $0 --version 7.7.0 --trigger-release"; echo } if [[ ! ${VERSION} ]]; then @@ -38,6 +43,14 @@ if [[ ! ${VERSION} ]]; then exit 1 fi +releaseMachineExec() { + # docker buildx includes automated push to registry, so build using tag we want published, not just local ${IMAGE} + docker buildx build \ + --tag "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${VERSION}" --push \ + -f ./${DOCKERFILE} . --platform "linux/amd64,linux/ppc64le,linux/arm64" | cat + echo "Pushed ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${VERSION}" +} + # derive branch from version BRANCH=${VERSION%.*}.x @@ -71,7 +84,10 @@ if [[ ${NOCOMMIT} -eq 0 ]]; then git push origin "${BRANCH}" fi -if [[ $TAG_RELEASE -eq 1 ]]; then +if [[ $TRIGGER_RELEASE -eq 1 ]]; then + # push new branch to release branch to trigger CI build + releaseMachineExec + # tag the release git checkout "${BRANCH}" git tag "${VERSION}" From 3edfc83f194390d91c5150aec763c7376905c814 Mon Sep 17 00:00:00 2001 From: Prabhav Thali Date: Fri, 20 Aug 2021 17:41:32 +0530 Subject: [PATCH 3/3] changes to sync with PR #170 --- .github/workflows/next-build.yaml | 35 +++-- .github/workflows/release.yml | 49 +++--- .travis.yml | 250 +++++++++++++++++------------- .travis/build_image.sh | 31 +++- .travis/publish_multiarch.sh | 47 ++++-- 5 files changed, 241 insertions(+), 171 deletions(-) diff --git a/.github/workflows/next-build.yaml b/.github/workflows/next-build.yaml index af365cb7d..7dbe6c05c 100644 --- a/.github/workflows/next-build.yaml +++ b/.github/workflows/next-build.yaml @@ -44,21 +44,22 @@ jobs: quay.io/eclipse/che-machine-exec:next quay.io/eclipse/che-machine-exec:${{ steps.vars.outputs.sha_short }} - travis-build: - runs-on: ubuntu-latest - continue-on-error: true - steps: - - name: Trigger build on Travis CI - run: | - body="{ - \"request\":{ - \"branch\":\"main\" - }}" + # TODO: uncomment this when we're happy that travis is working for PRs + # travis-build: + # runs-on: ubuntu-latest + # continue-on-error: true + # steps: + # - name: Trigger build on Travis CI + # run: | + # body="{ + # \"request\":{ + # \"branch\":\"main\" + # }}" - curl -s -X POST \ - -H "Content-Type: application/json" \ - -H "Accept: application/json" \ - -H "Travis-API-Version: 3" \ - -H "Authorization: token ${{ secrets.TRAVIS_TOKEN }}" \ - -d "$body" \ - https://api.travis-ci.com/repo/eclipse-che%2Fche-machine-exec/requests + # curl -s -X POST \ + # -H "Content-Type: application/json" \ + # -H "Accept: application/json" \ + # -H "Travis-API-Version: 3" \ + # -H "Authorization: token ${{ secrets.TRAVIS_TOKEN }}" \ + # -d "$body" \ + # https://api.travis-ci.com/repo/eclipse-che%2Fche-machine-exec/requests diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 158add8c0..758ee9171 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -94,28 +94,29 @@ jobs: MATTERMOST_CHANNEL: eclipse-che-releases MATTERMOST_USERNAME: che-bot - travis-build: - needs: build - runs-on: ubuntu-latest - continue-on-error: true - steps: - - name: Trigger build on Travis CI - run: | - body="{ - \"request\":{ - \"config\": { - \"env\": { - \"global\": [ - \"TAG=${{ github.event.inputs.version }}\" - ] - } - } - }}" + # TODO: uncomment this when we're happy that travis is working for PRs and :next builds + # travis-build: + # needs: build + # runs-on: ubuntu-latest + # continue-on-error: true + # steps: + # - name: Trigger build on Travis CI + # run: | + # body="{ + # \"request\":{ + # \"config\": { + # \"env\": { + # \"global\": [ + # \"TAG=${{ github.event.inputs.version }}\" + # ] + # } + # } + # }}" - curl -s -X POST \ - -H "Content-Type: application/json" \ - -H "Accept: application/json" \ - -H "Travis-API-Version: 3" \ - -H "Authorization: token ${{ secrets.TRAVIS_TOKEN }}" \ - -d "$body" \ - https://api.travis-ci.com/repo/eclipse-che%2Fche-machine-exec/requests + # curl -s -X POST \ + # -H "Content-Type: application/json" \ + # -H "Accept: application/json" \ + # -H "Travis-API-Version: 3" \ + # -H "Authorization: token ${{ secrets.TRAVIS_TOKEN }}" \ + # -d "$body" \ + # https://api.travis-ci.com/repo/eclipse-che%2Fche-machine-exec/requests diff --git a/.travis.yml b/.travis.yml index fd0bf8521..4fb0d645b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,122 +1,154 @@ -language: go +# +# 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 +# +# Contributors: +# Red Hat, Inc. - initial API and implementation +language: go go: -- "1.15" - +- '1.15' os: linux dist: focal - git: depth: false -env: - global: - - TAG=next - - TRAVIS_TAG=travis - - REGISTRY=quay.io - - ORGANIZATION=eclipse - - IMAGE=che-machine-exec - - PR_NUMBER= - install: - - export SHORT_SHA=$(git rev-parse --short HEAD) - - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - echo "$QUAY_PASSWORD" | docker login quay.io -u "$QUAY_USERNAME " --password-stdin + # TODO when we're confident that sha-tagged travis-built images won't collide with GHA built ones, we can remove the -travis suffix here + - export SHORT_SHA=$(git rev-parse --short HEAD)-travis + - export GITHUB_TOKEN="$CHE_BOT_GITHUB_TOKEN" + - echo "$RH_CHE_AUTOMATION_DOCKERHUB_PASSWORD" | docker login -u "$RH_CHE_AUTOMATION_DOCKERHUB_USERNAME" --password-stdin + - echo "$QUAY_ECLIPSE_CHE_PASSWORD" | docker login quay.io -u "$QUAY_ECLIPSE_CHE_USERNAME" --password-stdin + +env: + global: + - TAG=next-travis + - REGISTRY=quay.io + - ORGANIZATION=eclipse + - IMAGE=che-machine-exec + - PR_NUMBER= jobs: fast_finish: true allow_failures: - - if: env(PR_NUMBER) IS present - arch: arm64 - - if: env(PR_NUMBER) IS present - arch: ppc64le - - if: env(PR_NUMBER) IS present - arch: s390x + - if: env(PR_NUMBER) IS present + arch: arm64 + - if: env(PR_NUMBER) IS present + arch: ppc64le + - if: env(PR_NUMBER) IS present + arch: s390x include: - - &docker-build-pr - stage: PR Check - if: env(PR_NUMBER) IS present - name: Check docker build on amd64 - arch: amd64 - install: - - git fetch origin +refs/pull/${PR_NUMBER}/merge - - git checkout -qf FETCH_HEAD - script: docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:pr-check-${TRAVIS_CPU_ARCH}" . - - <<: *docker-build-pr - name: Check docker build on arm64 - arch: arm64 - - <<: *docker-build-pr - name: Check docker build on ppc64le - arch: ppc64le - - <<: *docker-build-pr - name: check docker build PR on s390x - arch: s390x - - - &unit-test - if: env(PR_NUMBER) IS present - name: Run unit tests on amd64 - arch: amd64 - install: - - git fetch origin +refs/pull/${PR_NUMBER}/merge - - git checkout -qf FETCH_HEAD - - export GO111MODULE="on" - - go get ${gobuild_args} ./... - script: - - | - CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags '-w -s' -a -installsuffix cgo -o che-machine-exec . - export CHE_WORKSPACE_ID=test_id - go test ./... -test.v - - <<: *unit-test - name: Run unit tests on arm64 - arch: arm64 - - <<: *unit-test - name: Run unit tests on ppc64le - arch: ppc64le - - <<: *unit-test - name: Run unit tests on s390x - arch: s390x - - - &next-build - stage: Build and push both short SHA tag and next tag - if: type = api AND branch = main AND env(TAG) = "next" - name: Build image on amd64 - arch: amd64 - script: - - bash .travis/build_image.sh - - <<: *next-build - name: Build image on arm64 - arch: arm64 - - <<: *next-build - name: Build image on ppc64le - arch: ppc64le - - <<: *next-build - name: Build image on s390x - arch: s390x - - - stage: Publish multiarch image with next & short_sha tag - if: type = api AND branch = main AND env(TAG) = "next" - script: bash .travis/publish_multiarch.sh - - - &release-build - stage: Release che-machine-exec - if: type = api AND env(TAG) IS present AND env(TAG) != "next" - name: Build image on amd64 - arch: amd64 - script: - - | - BRANCH=${TAG%.*}.x - git checkout "${BRANCH}" - bash .travis/build_image.sh - - <<: *release-build - name: Build image on arm64 - arch: arm64 - - <<: *release-build - name: Build image on ppc64le - arch: ppc64le - - <<: *release-build - name: Build image on s390x - arch: s390x - - - stage: Publish multiarch image with release tag - if: type = api AND env(TAG) IS present AND env(TAG) != "next" - script: bash .travis/publish_multiarch.sh + - stage: PR Check + if: env(PR_NUMBER) IS present + name: Check docker build on amd64 + arch: amd64 + install: &1 + - git fetch origin +refs/pull/${PR_NUMBER}/merge + - git checkout -qf FETCH_HEAD + script: docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:pr-check-${TRAVIS_CPU_ARCH}" + . + - stage: PR Check + if: env(PR_NUMBER) IS present + name: Check docker build on arm64 + arch: arm64 + install: *1 + script: docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:pr-check-${TRAVIS_CPU_ARCH}" + . + - stage: PR Check + if: env(PR_NUMBER) IS present + name: Check docker build on ppc64le + arch: ppc64le + install: *1 + script: docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:pr-check-${TRAVIS_CPU_ARCH}" + . + - stage: PR Check + if: env(PR_NUMBER) IS present + name: check docker build PR on s390x + arch: s390x + install: *1 + script: docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:pr-check-${TRAVIS_CPU_ARCH}" + . + - if: env(PR_NUMBER) IS present + name: Run unit tests on amd64 + arch: amd64 + install: &2 + - git fetch origin +refs/pull/${PR_NUMBER}/merge + - git checkout -qf FETCH_HEAD + - export GO111MODULE="on" + - go get ${gobuild_args} ./... + script: &3 + - | + CGO_ENABLED=0 GOOS=linux go build -mod=vendor -a -ldflags '-w -s' -a -installsuffix cgo -o che-machine-exec . + export CHE_WORKSPACE_ID=test_id + go test ./... -test.v + - if: env(PR_NUMBER) IS present + name: Run unit tests on arm64 + arch: arm64 + install: *2 + script: *3 + - if: env(PR_NUMBER) IS present + name: Run unit tests on ppc64le + arch: ppc64le + install: *2 + script: *3 + - if: env(PR_NUMBER) IS present + name: Run unit tests on s390x + arch: s390x + install: *2 + script: *3 + - stage: Build and push both short SHA tag and next-travis tag + if: type = api AND branch = main AND env(TAG) = "next-travis" AND env(PR_NUMBER) IS blank + name: Build image on amd64 + arch: amd64 + script: &4 + - .travis/build_image.sh + - stage: Build and push both short SHA tag and next-travis tag + if: type = api AND branch = main AND env(TAG) = "next-travis" AND env(PR_NUMBER) IS blank + name: Build image on arm64 + arch: arm64 + script: *4 + - stage: Build and push both short SHA tag and next-travis tag + if: type = api AND branch = main AND env(TAG) = "next-travis" AND env(PR_NUMBER) IS blank + name: Build image on ppc64le + arch: ppc64le + script: *4 + - stage: Build and push both short SHA tag and next-travis tag + if: type = api AND branch = main AND env(TAG) = "next-travis" AND env(PR_NUMBER) IS blank + name: Build image on s390x + arch: s390x + script: *4 + - stage: Publish multiarch image with next-travis & short_sha tag + if: type = api AND branch = main AND env(TAG) = "next-travis" AND env(PR_NUMBER) IS blank + script: .travis/publish_multiarch.sh + - stage: Release che-machine-exec + if: type = api AND env(TAG) IS present AND env(TAG) != "next-travis" + name: Build image on amd64 + arch: amd64 + script: &5 + - | + BRANCH=${TAG%.*}.x + git checkout "${BRANCH}" + TAG=${TAG}-travis + .travis/build_image.sh + - stage: Release che-machine-exec + if: type = api AND env(TAG) IS present AND env(TAG) != "next-travis" + name: Build image on arm64 + arch: arm64 + script: *5 + - stage: Release che-machine-exec + if: type = api AND env(TAG) IS present AND env(TAG) != "next-travis" + name: Build image on ppc64le + arch: ppc64le + script: *5 + - stage: Release che-machine-exec + if: type = api AND env(TAG) IS present AND env(TAG) != "next-travis" + name: Build image on s390x + arch: s390x + script: *5 + - stage: Publish multiarch image with release tag + if: type = api AND env(TAG) IS present AND env(TAG) != "next-travis" + script: TAG=$TAG-travis .travis/publish_multiarch.sh diff --git a/.travis/build_image.sh b/.travis/build_image.sh index bf269fbf4..575480b52 100755 --- a/.travis/build_image.sh +++ b/.travis/build_image.sh @@ -1,12 +1,27 @@ #!/bin/bash +# +# 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 +# +# Contributors: +# Red Hat, Inc. - initial API and implementation set -e -# Build images -docker build -f build/dockerfiles/Dockerfile -t "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-${TRAVIS_CPU_ARCH}" . -docker push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-${TRAVIS_CPU_ARCH}" +#shellcheck disable=SC1073 disable=SC2066 disable=SC2153 +for image in ${IMAGE}; do + the_image="${REGISTRY}/${ORGANIZATION}/${image}" -# Tag image with short_sha in case of next build -if [[ "$TAG" == "next" ]]; then - docker tag "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-${TRAVIS_CPU_ARCH}" "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_TAG}-${TRAVIS_CPU_ARCH}" - docker push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_TAG}-${TRAVIS_CPU_ARCH}" -fi + # Build images + docker build -f build/dockerfiles/Dockerfile -t "${the_image}:${TAG}-${TRAVIS_CPU_ARCH}" . + docker push "${the_image}:${TAG}-${TRAVIS_CPU_ARCH}" + + # Tag image with short_sha in case of next build + if [[ "$TAG" == "next-travis" ]]; then + docker tag "${the_image}:${TAG}-${TRAVIS_CPU_ARCH}" "${the_image}:${SHORT_SHA}-${TRAVIS_CPU_ARCH}" + docker push "${the_image}:${SHORT_SHA}-${TRAVIS_CPU_ARCH}" + fi +done diff --git a/.travis/publish_multiarch.sh b/.travis/publish_multiarch.sh index 39eec45ab..28f8a932d 100755 --- a/.travis/publish_multiarch.sh +++ b/.travis/publish_multiarch.sh @@ -1,18 +1,39 @@ #!/bin/bash +# +# 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 +# +# Contributors: +# Red Hat, Inc. - initial API and implementation +# +# Create amend with images built on individual architectures + set -e -# Create amend with images built on individual architectures -AMEND="" -AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-amd64"; -AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-arm64"; -AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-ppc64le"; -AMEND+=" --amend ${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}-s390x"; +PUBLISH_IMAGES_LIST=( + che-machine-exec +) +for image in "${PUBLISH_IMAGES_LIST[@]}"; do + the_image="${REGISTRY}/${ORGANIZATION}/${image}" + AMEND="" + AMEND+=" --amend ${the_image}:${TAG}-amd64"; + AMEND+=" --amend ${the_image}:${TAG}-arm64"; + AMEND+=" --amend ${the_image}:${TAG}-ppc64le"; + AMEND+=" --amend ${the_image}:${TAG}-s390x"; -# Create manifest and push multiarch image -docker manifest create "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}" $AMEND -docker manifest push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${TAG}-${TRAVIS_TAG}" + # Create manifest and push multiarch image + eval docker manifest create "${the_image}:${TAG}" "$AMEND" + docker manifest push "${the_image}:${TAG}" -if [[ "$TAG" == "next" ]]; then - docker manifest create "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_TAG}" $AMEND - docker manifest push "${REGISTRY}/${ORGANIZATION}/${IMAGE}:${SHORT_SHA}-${TRAVIS_TAG}" -fi + if [[ "${TAG}" == "next-travis" ]]; then + eval docker manifest create "${the_image}:${SHORT_SHA}" "$AMEND" + docker manifest push "${the_image}:${SHORT_SHA}" + else + eval docker manifest create "${the_image}:latest-travis" "$AMEND" + docker manifest push "${the_image}:latest-travis" + fi +done