Publish images to Docker Hub (#5264)

This commit enables the images publishing to Docker Hub in Drone CI. Every pull request merging will trigger this process.
This commit is contained in:
Wenkai Yin 2018-07-09 11:03:51 +08:00 committed by Yan
parent ad7a85da51
commit fd5c17bced
2 changed files with 16 additions and 1 deletions

View File

@ -50,6 +50,8 @@ pipeline:
- mail_pwd
- npm_password
- npm_username
- docker_hub_username
- docker_hub_password
commands:
- export DOMAIN=${CI_DOMAIN}
- export HOST_CONTAINER_ID=$(hostname)

View File

@ -115,6 +115,18 @@ function package_offline_installer {
du -ks $harbor_build_bundle | awk '{print $1 / 1024}' | { read x; echo $x MB; }
}
# publish images to Docker Hub
function publishImage {
echo "Publishing images to Docker Hub..."
echo "The images on the host:"
docker images
docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
# rename the images with tag "dev" and push to Docker Hub
docker images | sed -n "s|\(vmware/[-._a-z0-9]*\)\s*\(.*$Harbor_Assets_Version\).*|docker tag \1:\2 \1:dev;docker push \1:dev|p" | bash
echo "Images are published successfully"
docker images
}
## --------------------------------------------- Run Test Case ---------------------------------------------
echo "--------------------------------------------------"
echo "Running CI for $DRONE_BUILD_EVENT on $DRONE_BRANCH"
@ -128,7 +140,7 @@ echo "--------------------------------------------------"
if [[ $DRONE_BRANCH == "master" || $DRONE_BRANCH == *"refs/tags"* || $DRONE_BRANCH == "release-"* ]]; then
if [[ $DRONE_BUILD_EVENT == "push" ]]; then
package_offline_installer
upload_latest_build=true
upload_latest_build=true
fi
fi
@ -187,6 +199,7 @@ if [ $upload_build == true ] && [ $rc -eq 0 ]; then
uploader $harbor_build_bundle $harbor_target_bucket
uploader harbor-offline-installer-latest.tgz $harbor_target_bucket
upload_bundle_success=true
publishImage
fi
## --------------------------------------------- Upload Harbor Latest Build File ----------------------------------