Add docker-hub login in build package (#13528)

Signed-off-by: danfengliu <danfengl@vmware.com>
This commit is contained in:
danfengliu 2020-11-17 11:36:49 +08:00 committed by GitHub
parent 341b8f0c7e
commit 490042d8d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View File

@ -34,20 +34,18 @@ class DockerAPI(object):
_tag = "latest" _tag = "latest"
if expected_error_message is "": if expected_error_message is "":
expected_error_message = None expected_error_message = None
caught_err = False
ret = "" ret = ""
try: try:
self.DCLIENT.pull(r'{}:{}'.format(image, _tag)) ret = self.DCLIENT.pull(r'{}:{}'.format(image, _tag))
return ret return ret
except Exception as err: except Exception as err:
caught_err = True
if expected_error_message is not None: if expected_error_message is not None:
print( "docker image pull error:", str(err)) print( "docker image pull error:", str(err))
if str(err).lower().find(expected_error_message.lower()) < 0: if str(err).lower().find(expected_error_message.lower()) < 0:
raise Exception(r"Pull image: Return message {} is not as expected {}".format(str(err), expected_error_message)) raise Exception(r"Pull image: Return message {} is not as expected {}".format(str(err), expected_error_message))
else: else:
raise Exception(r" Docker pull image {} failed, error is [{}]".format (image, err.message)) raise Exception(r" Docker pull image {} failed, error is [{}]".format (image, err.message))
if caught_err == False: else:
if expected_error_message is not None: if expected_error_message is not None:
if str(ret).lower().find(expected_error_message.lower()) < 0: if str(ret).lower().find(expected_error_message.lower()) < 0:
raise Exception(r" Failed to catch error [{}] when pull image {}, return message: {}".format (expected_error_message, image, str(ret))) raise Exception(r" Failed to catch error [{}] when pull image {}, return message: {}".format (expected_error_message, image, str(ret)))

View File

@ -20,7 +20,8 @@ def push_image_to_project(project_name, registry, username, password, image, tag
time.sleep(2) time.sleep(2)
if expected_login_error_message != None: if expected_login_error_message != None:
return return
_docker_api.docker_image_pull(image, tag = tag) ret = _docker_api.docker_image_pull(image, tag = tag)
print("docker image pull ret:", ret)
time.sleep(2) time.sleep(2)
new_harbor_registry, new_tag = _docker_api.docker_image_tag(r'{}:{}'.format(image, tag), r'{}/{}/{}'.format(registry, project_name, image)) new_harbor_registry, new_tag = _docker_api.docker_image_tag(r'{}:{}'.format(image, tag), r'{}/{}/{}'.format(registry, project_name, image))
@ -147,4 +148,4 @@ class Repository(base.Base):
base._assert_status_code(expect_status_code, status_code) base._assert_status_code(expect_status_code, status_code)
base._assert_status_code(200, status_code) base._assert_status_code(200, status_code)
return data return data

View File

@ -55,7 +55,9 @@ Package Harbor Offline
[Arguments] ${with_notary}=true ${with_clair}=true ${with_migrator}=true ${with_chartmuseum}=true [Arguments] ${with_notary}=true ${with_clair}=true ${with_migrator}=true ${with_chartmuseum}=true
Log To Console \nStart Docker Daemon Log To Console \nStart Docker Daemon
Start Docker Daemon Locally Start Docker Daemon Locally
docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD ${rc} ${output}= Run And Return Rc And Output docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
Log ${rc}
Log ${output}
Log To Console \n\nmake package_offline BASEIMAGETAG=%{Harbor_Build_Base_Tag} NPM_REGISTRY=%{NPM_REGISTRY} VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} MIGRATORFLAG=${with_migrator} CHARTFLAG=${with_chartmuseum} HTTPPROXY= Log To Console \n\nmake package_offline BASEIMAGETAG=%{Harbor_Build_Base_Tag} NPM_REGISTRY=%{NPM_REGISTRY} VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} MIGRATORFLAG=${with_migrator} CHARTFLAG=${with_chartmuseum} HTTPPROXY=
${rc} ${output}= Run And Return Rc And Output make package_offline BASEIMAGETAG=%{Harbor_Build_Base_Tag} NPM_REGISTRY=%{NPM_REGISTRY} VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} MIGRATORFLAG=${with_migrator} CHARTFLAG=${with_chartmuseum} HTTPPROXY= ${rc} ${output}= Run And Return Rc And Output make package_offline BASEIMAGETAG=%{Harbor_Build_Base_Tag} NPM_REGISTRY=%{NPM_REGISTRY} VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} MIGRATORFLAG=${with_migrator} CHARTFLAG=${with_chartmuseum} HTTPPROXY=
Log To Console ${rc} Log To Console ${rc}
@ -66,7 +68,9 @@ Package Harbor Online
[Arguments] ${with_notary}=true ${with_clair}=true ${with_migrator}=false ${with_chartmuseum}=true [Arguments] ${with_notary}=true ${with_clair}=true ${with_migrator}=false ${with_chartmuseum}=true
Log To Console \nStart Docker Daemon Log To Console \nStart Docker Daemon
Start Docker Daemon Locally Start Docker Daemon Locally
docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD ${rc} ${output}= Run And Return Rc And Output docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD
Log ${rc}
Log ${output}
Log To Console \nmake package_online VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} MIGRATORFLAG=${with_migrator} CHARTFLAG=${with_chartmuseum} HTTPPROXY= Log To Console \nmake package_online VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} MIGRATORFLAG=${with_migrator} CHARTFLAG=${with_chartmuseum} HTTPPROXY=
${rc} ${output}= Run And Return Rc And Output make package_online VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} MIGRATORFLAG=${with_migrator} CHARTFLAG=${with_chartmuseum} HTTPPROXY= ${rc} ${output}= Run And Return Rc And Output make package_online VERSIONTAG=%{Harbor_Assets_Version} PKGVERSIONTAG=%{Harbor_Package_Version} NOTARYFLAG=${with_notary} CLAIRFLAG=${with_clair} MIGRATORFLAG=${with_migrator} CHARTFLAG=${with_chartmuseum} HTTPPROXY=
Log ${rc} Log ${rc}