diff --git a/.github/workflows/ci-all-in-one-build.yml b/.github/workflows/ci-all-in-one-build.yml index 1238c1936ad..8c07671f98c 100644 --- a/.github/workflows/ci-all-in-one-build.yml +++ b/.github/workflows/ci-all-in-one-build.yml @@ -26,20 +26,6 @@ jobs: with: node-version: '10' - - uses: docker/login-action@v1 - id: dockerhub-login - with: - username: jaegertracingbot - password: ${{ secrets.DOCKERHUB_TOKEN }} - env: - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - if: env.DOCKERHUB_TOKEN != null - - - name: Export DOCKERHUB_LOGIN variable - run: | - echo "DOCKERHUB_LOGIN=true" >> $GITHUB_ENV - if: steps.dockerhub-login.outcome == 'success' - - name: Export BRANCH variable uses: ./.github/actions/setup-branch @@ -48,3 +34,6 @@ jobs: - name: Build, test, and publish all-in-one image run: bash scripts/travis/build-all-in-one-image.sh + env: + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} diff --git a/.github/workflows/ci-crossdock.yml b/.github/workflows/ci-crossdock.yml index 7399eb92425..37628e00a78 100644 --- a/.github/workflows/ci-crossdock.yml +++ b/.github/workflows/ci-crossdock.yml @@ -30,20 +30,6 @@ jobs: with: go-version: ^1.15 - - uses: docker/login-action@v1 - id: dockerhub-login - with: - username: jaegertracingbot - password: ${{ secrets.DOCKERHUB_TOKEN }} - env: - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - if: env.DOCKERHUB_TOKEN != null - - - name: Export DOCKERHUB_LOGIN variable - run: | - echo "DOCKERHUB_LOGIN=true" >> $GITHUB_ENV - if: steps.dockerhub-login.outcome == 'success' - - name: Export BRANCH variable uses: ./.github/actions/setup-branch @@ -52,6 +38,9 @@ jobs: - name: Build, test, and publish ${{ matrix.steps.name }} image run: ${{ matrix.steps.cmd }} + env: + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} - name: Output crossdock logs run: make crossdock-logs diff --git a/.github/workflows/ci-docker-build.yml b/.github/workflows/ci-docker-build.yml index 071977351d0..ef5d49c1bf6 100644 --- a/.github/workflows/ci-docker-build.yml +++ b/.github/workflows/ci-docker-build.yml @@ -26,20 +26,6 @@ jobs: with: node-version: '10' - - uses: docker/login-action@v1 - id: dockerhub-login - with: - username: jaegertracingbot - password: ${{ secrets.DOCKERHUB_TOKEN }} - env: - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - if: env.DOCKERHUB_TOKEN != null - - - name: Export DOCKERHUB_LOGIN variable - run: | - echo "DOCKERHUB_LOGIN=true" >> $GITHUB_ENV - if: steps.dockerhub-login.outcome == 'success' - - name: Export BRANCH variable uses: ./.github/actions/setup-branch @@ -51,3 +37,6 @@ jobs: - name: Upload docker images run: bash scripts/travis/upload-all-docker-images.sh + env: + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} diff --git a/.github/workflows/ci-hotrod.yml b/.github/workflows/ci-hotrod.yml index e94e037026d..4c2d2defd3a 100644 --- a/.github/workflows/ci-hotrod.yml +++ b/.github/workflows/ci-hotrod.yml @@ -22,20 +22,6 @@ jobs: with: go-version: ^1.15 - - uses: docker/login-action@v1 - id: dockerhub-login - with: - username: jaegertracingbot - password: ${{ secrets.DOCKERHUB_TOKEN }} - env: - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - if: env.DOCKERHUB_TOKEN != null - - - name: Export DOCKERHUB_LOGIN variable - run: | - echo "DOCKERHUB_LOGIN=true" >> $GITHUB_ENV - if: steps.dockerhub-login.outcome == 'success' - - name: Export BRANCH variable uses: ./.github/actions/setup-branch @@ -44,3 +30,6 @@ jobs: - name: Build, test, and publish hotrod image run: bash scripts/travis/hotrod-integration-test.sh + env: + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index 9d187770e2a..4457fde1022 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -25,20 +25,6 @@ jobs: with: node-version: '10' - - uses: docker/login-action@v1 - id: dockerhub-login - with: - username: jaegertracingbot - password: ${{ secrets.DOCKERHUB_TOKEN }} - env: - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - if: env.DOCKERHUB_TOKEN != null - - - name: Export DOCKERHUB_LOGIN variable - run: | - echo "DOCKERHUB_LOGIN=true" >> $GITHUB_ENV - if: steps.dockerhub-login.outcome == 'success' - - name: Export BRANCH variable uses: ./.github/actions/setup-branch @@ -70,6 +56,12 @@ jobs: - name: Upload docker images run: bash scripts/travis/upload-all-docker-images.sh if: steps.build-images.outcome == 'success' + env: + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} - name: Build, test, and publish all-in-one image run: bash scripts/travis/build-all-in-one-image.sh + env: + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} diff --git a/scripts/travis/build-all-in-one-image.sh b/scripts/travis/build-all-in-one-image.sh index ea83296969b..a25e53c8633 100755 --- a/scripts/travis/build-all-in-one-image.sh +++ b/scripts/travis/build-all-in-one-image.sh @@ -7,7 +7,6 @@ BRANCH=${BRANCH:?'missing BRANCH env var'} # be overrided by passing architecture value to the script: # `GOARCH= ./scripts/travis/build-all-in-one-image.sh`. GOARCH=${GOARCH:-$(go env GOARCH)} -DOCKERHUB_LOGIN=${DOCKERHUB_LOGIN:-false} expected_version="v10" version=$(node --version) @@ -36,13 +35,13 @@ run_integration_test() { } upload_to_docker() { - # Only push the docker container to Docker Hub for master/release branch and when dockerhub login is done - if [[ ("$BRANCH" == "master" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$) && "$DOCKERHUB_LOGIN" == "true" ]]; then - echo "upload $1 to Docker Hub" - export REPO=$1 - bash ./scripts/travis/upload-to-docker.sh + # Only push the docker image to dockerhub/quay.io for master/release branch + if [[ "$BRANCH" == "master" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "upload $1 to dockerhub/quay.io" + REPO=$1 + bash scripts/travis/upload-to-registry.sh $REPO else - echo 'skip docker upload for PR' + echo 'skip docker images upload for PR' fi } diff --git a/scripts/travis/build-crossdock.sh b/scripts/travis/build-crossdock.sh index 6045a589c15..43c20aad081 100755 --- a/scripts/travis/build-crossdock.sh +++ b/scripts/travis/build-crossdock.sh @@ -3,20 +3,19 @@ set -euxf -o pipefail BRANCH=${BRANCH:?'missing BRANCH env var'} -DOCKERHUB_LOGIN=${DOCKERHUB_LOGIN:-false} COMMIT=${GITHUB_SHA::8} make build-and-run-crossdock -# Only push the docker container to Docker Hub for master branch and when dockerhub login is done -if [[ "$BRANCH" == "master" && "$DOCKERHUB_LOGIN" == "true" ]]; then - echo 'upload to Docker Hub' +# Only push images to dockerhub/quay.io for master branch +if [[ "$BRANCH" == "master" ]]; then + echo 'upload images to dockerhub/quay.io' else - echo 'skip docker upload for PR' + echo 'skip docker images upload for PR' exit 0 fi # docker image has been build when running the crossdock -export REPO=jaegertracing/test-driver +REPO=jaegertracing/test-driver docker tag $REPO:latest $REPO:$COMMIT -bash ./scripts/travis/upload-to-docker.sh +bash scripts/travis/upload-to-registry.sh $REPO diff --git a/scripts/travis/hotrod-integration-test.sh b/scripts/travis/hotrod-integration-test.sh index 43084cbb0f6..c3a3aae713b 100755 --- a/scripts/travis/hotrod-integration-test.sh +++ b/scripts/travis/hotrod-integration-test.sh @@ -3,7 +3,7 @@ set -euxf -o pipefail make docker-hotrod -export REPO=jaegertracing/example-hotrod +REPO=jaegertracing/example-hotrod export CID=$(docker run -d -p 8080:8080 $REPO:latest) i=0 while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8080)" != "200" && ${i} < 30 ]]; do @@ -18,14 +18,13 @@ fi docker rm -f $CID BRANCH=${BRANCH:?'missing BRANCH env var'} -DOCKERHUB_LOGIN=${DOCKERHUB_LOGIN:-false} -# Only push images to Docker Hub for master branch or for release tags vM.N.P and when dockerhub login is done -if [[ ("$BRANCH" == "master" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$) && "$DOCKERHUB_LOGIN" == "true" ]]; then - echo "upload to Docker Hub, BRANCH=$BRANCH" +# Only push images to dockerhub/quay.io for master branch or for release tags vM.N.P +if [[ "$BRANCH" == "master" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "upload to dockerhub/quay.io, BRANCH=$BRANCH" else - echo "skip Docker upload, only allowed for tagged releases or master (latest tag)" + echo "skip docker images upload, only allowed for tagged releases or master (latest tag)" exit 0 fi -bash ./scripts/travis/upload-to-docker.sh +bash scripts/travis/upload-to-registry.sh $REPO diff --git a/scripts/travis/upload-all-docker-images.sh b/scripts/travis/upload-all-docker-images.sh index 2fc33892c61..4b6eab8e54d 100755 --- a/scripts/travis/upload-all-docker-images.sh +++ b/scripts/travis/upload-all-docker-images.sh @@ -5,13 +5,12 @@ set -euxf -o pipefail BRANCH=${BRANCH:?'missing BRANCH env var'} -DOCKERHUB_LOGIN=${DOCKERHUB_LOGIN:-false} -# Only push images to Docker Hub for master branch or for release tags vM.N.P and when dockerhub login is done -if [[ ("$BRANCH" == "master" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$) && "$DOCKERHUB_LOGIN" == "true" ]]; then - echo "upload to Docker Hub, BRANCH=$BRANCH" +# Only push images to dockerhub/quay.io for master branch or for release tags vM.N.P +if [[ "$BRANCH" == "master" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "upload to dockerhub/quay.io, BRANCH=$BRANCH" else - echo 'skip Docker upload, only allowed for tagged releases or master (latest tag)' + echo 'skip docker images upload, only allowed for tagged releases or master (latest tag)' exit 0 fi @@ -38,6 +37,6 @@ jaeger_components=( for component in "${jaeger_components[@]}" do - export REPO="jaegertracing/jaeger-${component}" - bash ./scripts/travis/upload-to-docker.sh + REPO="jaegertracing/jaeger-${component}" + bash scripts/travis/upload-to-registry.sh $REPO done diff --git a/scripts/travis/upload-to-docker.sh b/scripts/travis/upload-to-docker.sh deleted file mode 100755 index 55fdcdb2dab..00000000000 --- a/scripts/travis/upload-to-docker.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -set -euxf -o pipefail - -BRANCH=${BRANCH:?'missing BRANCH env var'} -IMAGE="${REPO:?'missing REPO env var'}:latest" - -unset major minor patch -if [[ "$BRANCH" == "master" ]]; then - TAG="latest" -elif [[ $BRANCH =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then - major="${BASH_REMATCH[1]}" - minor="${BASH_REMATCH[2]}" - patch="${BASH_REMATCH[3]}" - TAG=${major}.${minor}.${patch} - echo "BRANCH is a release tag: major=$major, minor=$minor, patch=$patch" -else - TAG="${BRANCH}" -fi -echo "REPO=$REPO, BRANCH=$BRANCH, TAG=$TAG, IMAGE=$IMAGE" - -# add major, major.minor and major.minor.patch tags -if [[ -n ${major:-} ]]; then - docker tag $IMAGE $REPO:${major} - if [[ -n ${minor:-} ]]; then - docker tag $IMAGE $REPO:${major}.${minor} - if [[ -n ${patch:-} ]]; then - docker tag $IMAGE $REPO:${major}.${minor}.${patch} - fi - fi -fi - -if [[ "${REPO}" == "jaegertracing/jaeger-opentelemetry-collector" || "${REPO}" == "jaegertracing/jaeger-opentelemetry-agent" || "${REPO}" == "jaegertracing/jaeger-opentelemetry-ingester" || "${REPO}" == "jaegertracing/opentelemetry-all-in-one" ]]; then - # TODO remove once Jaeger OTEL collector is stable - docker push $REPO:latest -else - # push all tags, therefore push to repo - docker push $REPO -fi - -SNAPSHOT_IMAGE="$REPO-snapshot:$GITHUB_SHA" -echo "Pushing snapshot image $SNAPSHOT_IMAGE" -docker tag $IMAGE $SNAPSHOT_IMAGE -docker push $SNAPSHOT_IMAGE diff --git a/scripts/travis/upload-to-registry.sh b/scripts/travis/upload-to-registry.sh new file mode 100755 index 00000000000..5c1d8226ea6 --- /dev/null +++ b/scripts/travis/upload-to-registry.sh @@ -0,0 +1,113 @@ +#!/bin/bash + +set -euxf -o pipefail + +DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-"jaegertracingbot"} +DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-} +QUAY_USERNAME=${QUAY_USERNAME:-"jaegertracingbot+github_workflows"} +QUAY_TOKEN=${QUAY_TOKEN:-} + +usage() { + echo $"Usage: $0 " + exit 1 +} + +check_args() { + if [ ! $# -eq 1 ]; then + echo "ERROR: need exactly one argument" + usage + fi +} + +compute_image_tag() { + local branch=$1 + + if [[ "${branch}" == "master" ]]; then + local tag="latest" + echo ${tag} + elif [[ "${branch}" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then + local major="${BASH_REMATCH[1]}" + local minor="${BASH_REMATCH[2]}" + local patch="${BASH_REMATCH[3]}" + local tag=${major}.${minor}.${patch} + echo "${tag} ${major} ${minor} ${patch}" + else + local tag="${branch}" + echo ${tag} + fi +} + +label_release_tag() { + local registry=$1 + local image=$2 + local major=${3:-} + local minor=${4:-} + local patch=${5:-} + + docker tag ${image} ${registry}/${image} + if [[ -n ${major} ]]; then + docker tag ${image} ${registry}/${image}:${major} + if [[ -n ${minor} ]]; then + docker tag ${image} ${registry}/${image}:${major}.${minor} + if [[ -n ${patch} ]]; then + docker tag ${image} ${registry}/${image}:${major}.${minor}.${patch} + fi + fi + fi +} + +try_login() { + local registry=$1 + local user=$2 + local token=$3 + local marker=$4 + + if [ ! -f ${marker} ] && [ -v ${token} ]; then + printenv ${token} | docker login ${registry} --username ${user} --password-stdin + touch ${marker} + fi +} + +upload_images() { + local registry=$1 + local image=$2 + local user=$3 + local token=$4 + local marker=.${registry}.login + + try_login ${registry} ${user} ${token} ${marker} + + if [ ! -f ${marker} ]; then + echo "skipping upload to ${registry}, not logged in!" + else + case "$image" in + "jaegertracing/jaeger-opentelemetry-collector" | "jaegertracing/jaeger-opentelemetry-agent" | "jaegertracing/jaeger-opentelemetry-ingester" | "jaegertracing/opentelemetry-all-in-one" ) + docker push ${registry}/${image}:latest + ;; + *) + docker push ${registry}/${image} + ;; + esac + + local snapshot_image="${image}-snapshot:${GITHUB_SHA}" + echo "pushing snapshot image ${snapshot_image}" + docker tag ${image} ${registry}/${snapshot_image} + docker push ${registry}/${snapshot_image} + fi +} + +main() { + local registry=$1 + local image=$2 + local user=$3 + local token=$4 + + read -r tag major minor patch <<< "$(compute_image_tag ${BRANCH})" + label_release_tag ${registry} ${image} ${major} ${minor} ${patch} + upload_images ${registry} ${image} ${user} ${token} +} + +check_args "$@" + +main "docker.io" $1 ${DOCKERHUB_USERNAME} DOCKERHUB_TOKEN +main "quay.io" $1 ${QUAY_USERNAME} QUAY_TOKEN