Skip to content

Commit

Permalink
Merge pull request #81 from kmala/storage
Browse files Browse the repository at this point in the history
feat(regsitry): Add support for private registry
  • Loading branch information
kmala authored Jul 29, 2016
2 parents b765485 + 7473e16 commit 4090625
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
4 changes: 3 additions & 1 deletion rootfs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM quay.io/deis/base:0.2.0
RUN apt-get update \
&& apt-get install -y \
gcc \
git \
libffi6 \
libffi-dev \
libssl1.0.0 \
Expand All @@ -13,13 +14,14 @@ RUN apt-get update \
python-dev \
--no-install-recommends \
&& curl -sSL https://bootstrap.pypa.io/get-pip.py | python - pip==8.1.2 \
&& pip install --disable-pip-version-check --no-cache-dir docker-py==1.8.1 \
&& pip install --disable-pip-version-check --no-cache-dir git+https://github.com/docker/docker-py.git@9b63bed6a0b5185b043e85df8c49d86d2c048aa1 \
&& apt-get remove -y --auto-remove --purge \
gcc \
libffi-dev \
libssl-dev \
musl-dev \
python-dev \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/man /usr/share/doc

Expand Down
40 changes: 37 additions & 3 deletions rootfs/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import requests
import subprocess


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


def log_output(stream, decode):
Expand Down Expand Up @@ -36,6 +36,40 @@ def log(msg):
print(msg)


def get_registry_name():
hostname = os.getenv('DEIS_REGISTRY_HOSTNAME', "").replace("https://", "").replace("http://", "")
if regsitryLocation == "off-cluster":
organization = os.getenv('DEIS_REGISTRY_ORGANIZATION')
regName = ""
# empty hostname means dockerhub and hence no need to prefix the image
if hostname != "":
regName = hostname + "/"
# Registries may have organizations/namespaces under them which needs to
# be prefixed to the image
if organization != "":
regName = regName + organization
return regName
elif regsitryLocation == "ecr":
return hostname
elif regsitryLocation == "gcr":
return hostname+"/"+os.getenv('DEIS_REGISTRY_GCS_PROJ_ID')
else:
return os.getenv("DEIS_REGISTRY_SERVICE_HOST") + ":" + os.getenv("DEIS_REGISTRY_SERVICE_PORT")


def docker_push(client, repo, tag):
if regsitryLocation != "on-cluster":
hostname = os.getenv('DEIS_REGISTRY_HOSTNAME', 'https://index.docker.io/v1/')
auth_config = {
'username': os.getenv('DEIS_REGISTRY_USERNAME'),
'password': os.getenv('DEIS_REGISTRY_PASSWORD'),
'serveraddress': hostname,
}
return client.push(repo, tag=tag, stream=True, auth_config=auth_config)
else:
return client.push(repo, tag=tag, stream=True)


def download_file(tar_path):
os.putenv('BUCKET_FILE', "/var/run/secrets/deis/objectstore/creds/builder-bucket")
if os.getenv('BUILDER_STORAGE') == "minio":
Expand Down Expand Up @@ -63,11 +97,11 @@ def download_file(tar_path):
tar.extractall("/app/")
log("extracting tar file complete")
client = docker.Client(version='auto')
registry = os.getenv("DEIS_REGISTRY_SERVICE_HOST") + ":" + os.getenv("DEIS_REGISTRY_SERVICE_PORT")
registry = get_registry_name()
imageName, imageTag = os.getenv('IMG_NAME').split(":", 1)
repo = registry + "/" + os.getenv('IMG_NAME')
stream = client.build(tag=repo, stream=True, decode=True, rm=True, path='/app')
log_output(stream, True)
print("Pushing to registry")
stream = client.push(registry+'/'+imageName, tag=imageTag, stream=True)
stream = docker_push(client, registry+'/'+imageName, imageTag)
log_output(stream, False)

0 comments on commit 4090625

Please sign in to comment.