From a1bbd1a146ce127ab9a973aaace28ba621cf284c Mon Sep 17 00:00:00 2001
From: danfengliu <danfengl@vmware.com>
Date: Thu, 28 Jan 2021 18:03:40 +0800
Subject: [PATCH] Reschedule docker login policy in base image build process

Signed-off-by: danfengliu <danfengl@vmware.com>
---
 Makefile          | 10 ++++++++--
 make/pushimage.sh | 28 ----------------------------
 2 files changed, 8 insertions(+), 30 deletions(-)

diff --git a/Makefile b/Makefile
index 969474c7108..f5d995022a5 100644
--- a/Makefile
+++ b/Makefile
@@ -251,8 +251,8 @@ HARBORPKG=harbor
 # pushimage
 PUSHSCRIPTPATH=$(MAKEPATH)
 PUSHSCRIPTNAME=pushimage.sh
-REGISTRYUSER=user
-REGISTRYPASSWORD=default
+REGISTRYUSER=
+REGISTRYPASSWORD=
 
 # cmds
 DOCKERSAVE_PARA=$(DOCKER_IMAGE_NAME_PREPARE):$(VERSIONTAG) \
@@ -411,8 +411,14 @@ build_standalone_db_migrator: compile_standalone_db_migrator
 	make -f $(MAKEFILEPATH_PHOTON)/Makefile _build_standalone_db_migrator -e BASEIMAGETAG=$(BASEIMAGETAG) -e VERSIONTAG=$(VERSIONTAG)
 
 build_base_docker:
+	if [ -n "$(REGISTRYUSER)" ] && [ -n "$(REGISTRYPASSWORD)" ] ; then \
+		docker login -u $(REGISTRYUSER) -p $(REGISTRYPASSWORD) ; \
+	else \
+		echo "No docker credentials provided, please make sure enough priviledges to access docker hub!" ; \
+	fi
 	@for name in chartserver trivy-adapter core db jobservice log nginx notary-server notary-signer portal prepare redis registry registryctl; do \
 		echo $$name ; \
+		sleep 30 ; \
 		$(DOCKERBUILD) --pull --no-cache -f $(MAKEFILEPATH_PHOTON)/$$name/Dockerfile.base -t $(BASEIMAGENAMESPACE)/harbor-$$name-base:$(BASEIMAGETAG) --label base-build-date=$(date +"%Y%m%d") . && \
 		if [ -n "$(PUSHBASEIMAGE)" ] ; then \
 			$(PUSHSCRIPTPATH)/$(PUSHSCRIPTNAME) $(BASEIMAGENAMESPACE)/harbor-$$name-base:$(BASEIMAGETAG) $(REGISTRYUSER) $(REGISTRYPASSWORD) || exit 1; \
diff --git a/make/pushimage.sh b/make/pushimage.sh
index 2cbab67b96f..6ea94663840 100755
--- a/make/pushimage.sh
+++ b/make/pushimage.sh
@@ -99,21 +99,6 @@ set -e
 #  - https://docs.docker.com/reference/commandline/cli/#logout
 # ---------------------------
 
-# Login to the registry
-h2 "Login to the Docker registry"
-
-DOCKER_LOGIN="docker login --username $USERNAME --password $PASSWORD $REGISTRY"
-info "docker login --username $USERNAME --password *******"
-DOCKER_LOGIN_OUTPUT=$($DOCKER_LOGIN)
-
-if [ $? -ne 0 ]; then
-  warn "$DOCKER_LOGIN_OUTPUT"
-  error "Login to Docker registry $REGISTRY failed"
-  exit 1
-else
-  success "Login to Docker registry $REGISTRY succeeded";
-fi
-
 # Push the docker image
 h2 "Pushing image to Docker registry"
 
@@ -127,16 +112,3 @@ if [ $? -ne 0 ];then
 else
   success "Pushing image $IMAGE succeeded";
 fi
-
-# Logout from the registry
-h2 "Logout from the docker registry"
-DOCKER_LOGOUT="docker logout $REGISTRY"
-DOCKER_LOGOUT_OUTPUT=$($DOCKER_LOGOUT)
-
-if [ $? -ne 0 ]; then
-  warn "$DOCKER_LOGOUT_OUTPUT"
-  error "Logout from Docker registry $REGISTRY failed"
-  exit 1
-else
-  success "Logout from Docker registry $REGISTRY succeeded"
-fi