From 75c2cfcefd407be4896fdb8ad790e6776f3853ea Mon Sep 17 00:00:00 2001 From: Prabhav Thali Date: Fri, 20 Aug 2021 18:21:28 +0530 Subject: [PATCH] Draft: Add Travis CI support (#162) * feat(CI): Adds Travis CI support Signed-off-by: Prabhav Thali * Adds travis suffix and removes workflows handled on GA * changes to sync with PR #170 --- .github/workflows/gh_actions_pr.yaml | 25 +++++ .github/workflows/next-build.yaml | 20 ++++ .github/workflows/release.yml | 26 +++++ .travis.yml | 154 +++++++++++++++++++++++++++ .travis/build_image.sh | 27 +++++ .travis/publish_multiarch.sh | 39 +++++++ 6 files changed, 291 insertions(+) create mode 100644 .travis.yml create mode 100755 .travis/build_image.sh create mode 100755 .travis/publish_multiarch.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..7dbe6c05c 100644 --- a/.github/workflows/next-build.yaml +++ b/.github/workflows/next-build.yaml @@ -43,3 +43,23 @@ jobs: tags: | quay.io/eclipse/che-machine-exec:next quay.io/eclipse/che-machine-exec:${{ steps.vars.outputs.sha_short }} + + # 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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 21c87988d..758ee9171 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -94,3 +94,29 @@ jobs: MATTERMOST_CHANNEL: eclipse-che-releases MATTERMOST_USERNAME: che-bot + # 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 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..4fb0d645b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,154 @@ +# +# 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' +os: linux +dist: focal +git: + depth: false + +install: + # 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 + include: + - 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 new file mode 100755 index 000000000..575480b52 --- /dev/null +++ b/.travis/build_image.sh @@ -0,0 +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 + +#shellcheck disable=SC1073 disable=SC2066 disable=SC2153 +for image in ${IMAGE}; do + the_image="${REGISTRY}/${ORGANIZATION}/${image}" + + # 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 new file mode 100755 index 000000000..28f8a932d --- /dev/null +++ b/.travis/publish_multiarch.sh @@ -0,0 +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 + +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 + eval docker manifest create "${the_image}:${TAG}" "$AMEND" + docker manifest push "${the_image}:${TAG}" + + 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