From 5f713f22fd70c011f5aa9b159206c8dcb1be6fcd Mon Sep 17 00:00:00 2001 From: danfengliu Date: Mon, 11 Jan 2021 18:17:07 +0800 Subject: [PATCH] Push harbor build images to docker-hub in build workflow Signed-off-by: danfengliu --- .github/workflows/build-package.yml | 3 +++ tests/ci/build_util.sh | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/.github/workflows/build-package.yml b/.github/workflows/build-package.yml index cc88789ef..07a448288 100644 --- a/.github/workflows/build-package.yml +++ b/.github/workflows/build-package.yml @@ -96,6 +96,9 @@ jobs: uploader harbor-offline-installer-latest.tgz $harbor_target_bucket uploader harbor-offline-installer-latest.tgz.asc $harbor_target_bucket echo "BUILD_BUNDLE=$harbor_offline_build_bundle" >> $GITHUB_ENV + + publishImage $target_branch $Harbor_Assets_Version + - name: Slack Notification uses: sonots/slack-notice-action@v3 with: diff --git a/tests/ci/build_util.sh b/tests/ci/build_util.sh index 1eb3561ff..9036c58c7 100644 --- a/tests/ci/build_util.sh +++ b/tests/ci/build_util.sh @@ -6,4 +6,23 @@ set -e function uploader { gsutil cp $1 gs://$2/$1 gsutil -D setacl public-read gs://$2/$1 &> /dev/null +} + +function publishImage { + echo "Publishing images to Docker Hub..." + echo "The images on the host:" + # for master, will use 'dev' as the tag name + # for release-*, will use 'release-*-dev' as the tag name, like release-v1.8.0-dev + if [[ $1 == "master" ]]; then + image_tag=dev + fi + if [[ $1 == "release-"* ]]; then + image_tag=$2-dev + fi + # rename the images with tag "dev" and push to Docker Hub + docker images + docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD + docker images | grep goharbor | grep -v "\-base" | sed -n "s|\(goharbor/[-._a-z0-9]*\)\s*\(.*$2\).*|docker tag \1:\2 \1:$image_tag;docker push \1:$image_tag|p" | bash + echo "Images are published successfully" + docker images } \ No newline at end of file