66import subprocess
77
88DEBUG = os .environ .get ('DEIS_DEBUG' ) in ('true' , '1' )
9- regsitryLocation = os .getenv ('DEIS_REGISTRY_LOCATION' , 'on-cluster' )
9+ registryLocation = os .getenv ('DEIS_REGISTRY_LOCATION' , 'on-cluster' )
1010
1111
1212def log_output (stream , decode ):
@@ -39,7 +39,7 @@ def log(msg):
3939def get_registry_name ():
4040 hostname = os .getenv ('DEIS_REGISTRY_HOSTNAME' , "" )
4141 hostname = hostname .replace ("https://" , "" ).replace ("http://" , "" )
42- if regsitryLocation == "off-cluster" :
42+ if registryLocation == "off-cluster" :
4343 organization = os .getenv ('DEIS_REGISTRY_ORGANIZATION' )
4444 regName = ""
4545 # empty hostname means dockerhub and hence no need to prefix the image
@@ -50,27 +50,14 @@ def get_registry_name():
5050 if organization != "" :
5151 regName = regName + organization
5252 return regName
53- elif regsitryLocation == "ecr" :
53+ elif registryLocation == "ecr" :
5454 return hostname
55- elif regsitryLocation == "gcr" :
55+ elif registryLocation == "gcr" :
5656 return hostname + "/" + os .getenv ('DEIS_REGISTRY_GCS_PROJ_ID' )
5757 else :
5858 return os .getenv ("DEIS_REGISTRY_SERVICE_HOST" ) + ":" + os .getenv ("DEIS_REGISTRY_SERVICE_PORT" ) # noqa: E501
5959
6060
61- def docker_push (client , repo , tag ):
62- if regsitryLocation != "on-cluster" :
63- hostname = os .getenv ('DEIS_REGISTRY_HOSTNAME' , 'https://index.docker.io/v1/' )
64- auth_config = {
65- 'username' : os .getenv ('DEIS_REGISTRY_USERNAME' ),
66- 'password' : os .getenv ('DEIS_REGISTRY_PASSWORD' ),
67- 'serveraddress' : hostname ,
68- }
69- return client .push (repo , tag = tag , stream = True , auth_config = auth_config )
70- else :
71- return client .push (repo , tag = tag , stream = True )
72-
73-
7461def download_file (tar_path ):
7562 os .putenv ('BUCKET_FILE' , "/var/run/secrets/deis/objectstore/creds/builder-bucket" )
7663 if os .getenv ('BUILDER_STORAGE' ) == "minio" :
@@ -104,11 +91,16 @@ def download_file(tar_path):
10491 tar .extractall ("/app/" )
10592log ("extracting tar file complete" )
10693client = docker .Client (version = 'auto' )
94+ if registryLocation != "on-cluster" :
95+ registry = os .getenv ('DEIS_REGISTRY_HOSTNAME' , 'https://index.docker.io/v1/' )
96+ username = os .getenv ('DEIS_REGISTRY_USERNAME' )
97+ password = os .getenv ('DEIS_REGISTRY_PASSWORD' )
98+ client .login (username = username , password = password , registry = registry )
10799registry = get_registry_name ()
108100imageName , imageTag = os .getenv ('IMG_NAME' ).split (":" , 1 )
109101repo = registry + "/" + os .getenv ('IMG_NAME' )
110102stream = client .build (tag = repo , stream = True , decode = True , rm = True , path = '/app' )
111103log_output (stream , True )
112104print ("Pushing to registry" )
113- stream = docker_push ( client , registry + '/' + imageName , imageTag )
105+ stream = client . push ( registry + '/' + imageName , tag = imageTag , stream = True )
114106log_output (stream , False )
0 commit comments