Skip to content

Commit 697ae22

Browse files
author
Matthew Fisher
authored
Merge pull request #101 from clearbit/allow-private-base-image
feat(registry): Allow FROM to refer to the off-cluster docker registry.
2 parents 070d5cb + e8763ba commit 697ae22

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

rootfs/deploy.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import subprocess
77

88
DEBUG = 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

1212
def log_output(stream, decode):
@@ -39,7 +39,7 @@ def log(msg):
3939
def 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-
7461
def 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/")
10592
log("extracting tar file complete")
10693
client = 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)
10799
registry = get_registry_name()
108100
imageName, imageTag = os.getenv('IMG_NAME').split(":", 1)
109101
repo = registry + "/" + os.getenv('IMG_NAME')
110102
stream = client.build(tag=repo, stream=True, decode=True, rm=True, path='/app')
111103
log_output(stream, True)
112104
print("Pushing to registry")
113-
stream = docker_push(client, registry+'/'+imageName, imageTag)
105+
stream = client.push(registry+'/'+imageName, tag=imageTag, stream=True)
114106
log_output(stream, False)

0 commit comments

Comments
 (0)