Skip to content

Commit 4090625

Browse files
authored
Merge pull request #81 from kmala/storage
feat(regsitry): Add support for private registry
2 parents b765485 + 7473e16 commit 4090625

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

rootfs/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM quay.io/deis/base:0.2.0
33
RUN apt-get update \
44
&& apt-get install -y \
55
gcc \
6+
git \
67
libffi6 \
78
libffi-dev \
89
libssl1.0.0 \
@@ -13,13 +14,14 @@ RUN apt-get update \
1314
python-dev \
1415
--no-install-recommends \
1516
&& curl -sSL https://bootstrap.pypa.io/get-pip.py | python - pip==8.1.2 \
16-
&& pip install --disable-pip-version-check --no-cache-dir docker-py==1.8.1 \
17+
&& pip install --disable-pip-version-check --no-cache-dir git+https://github.com/docker/docker-py.git@9b63bed6a0b5185b043e85df8c49d86d2c048aa1 \
1718
&& apt-get remove -y --auto-remove --purge \
1819
gcc \
1920
libffi-dev \
2021
libssl-dev \
2122
musl-dev \
2223
python-dev \
24+
git \
2325
&& apt-get clean \
2426
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/man /usr/share/doc
2527

rootfs/deploy.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import requests
66
import subprocess
77

8-
98
DEBUG = os.environ.get('DEIS_DEBUG') in ('true', '1')
9+
regsitryLocation = os.getenv('DEIS_REGISTRY_LOCATION', 'on-cluster')
1010

1111

1212
def log_output(stream, decode):
@@ -36,6 +36,40 @@ def log(msg):
3636
print(msg)
3737

3838

39+
def get_registry_name():
40+
hostname = os.getenv('DEIS_REGISTRY_HOSTNAME', "").replace("https://", "").replace("http://", "")
41+
if regsitryLocation == "off-cluster":
42+
organization = os.getenv('DEIS_REGISTRY_ORGANIZATION')
43+
regName = ""
44+
# empty hostname means dockerhub and hence no need to prefix the image
45+
if hostname != "":
46+
regName = hostname + "/"
47+
# Registries may have organizations/namespaces under them which needs to
48+
# be prefixed to the image
49+
if organization != "":
50+
regName = regName + organization
51+
return regName
52+
elif regsitryLocation == "ecr":
53+
return hostname
54+
elif regsitryLocation == "gcr":
55+
return hostname+"/"+os.getenv('DEIS_REGISTRY_GCS_PROJ_ID')
56+
else:
57+
return os.getenv("DEIS_REGISTRY_SERVICE_HOST") + ":" + os.getenv("DEIS_REGISTRY_SERVICE_PORT")
58+
59+
60+
def docker_push(client, repo, tag):
61+
if regsitryLocation != "on-cluster":
62+
hostname = os.getenv('DEIS_REGISTRY_HOSTNAME', 'https://index.docker.io/v1/')
63+
auth_config = {
64+
'username': os.getenv('DEIS_REGISTRY_USERNAME'),
65+
'password': os.getenv('DEIS_REGISTRY_PASSWORD'),
66+
'serveraddress': hostname,
67+
}
68+
return client.push(repo, tag=tag, stream=True, auth_config=auth_config)
69+
else:
70+
return client.push(repo, tag=tag, stream=True)
71+
72+
3973
def download_file(tar_path):
4074
os.putenv('BUCKET_FILE', "/var/run/secrets/deis/objectstore/creds/builder-bucket")
4175
if os.getenv('BUILDER_STORAGE') == "minio":
@@ -63,11 +97,11 @@ def download_file(tar_path):
6397
tar.extractall("/app/")
6498
log("extracting tar file complete")
6599
client = docker.Client(version='auto')
66-
registry = os.getenv("DEIS_REGISTRY_SERVICE_HOST") + ":" + os.getenv("DEIS_REGISTRY_SERVICE_PORT")
100+
registry = get_registry_name()
67101
imageName, imageTag = os.getenv('IMG_NAME').split(":", 1)
68102
repo = registry + "/" + os.getenv('IMG_NAME')
69103
stream = client.build(tag=repo, stream=True, decode=True, rm=True, path='/app')
70104
log_output(stream, True)
71105
print("Pushing to registry")
72-
stream = client.push(registry+'/'+imageName, tag=imageTag, stream=True)
106+
stream = docker_push(client, registry+'/'+imageName, imageTag)
73107
log_output(stream, False)

0 commit comments

Comments
 (0)