Skip to content
This repository has been archived by the owner on Jun 10, 2019. It is now read-only.

Commit

Permalink
docker: Fix dockerfile creation
Browse files Browse the repository at this point in the history
  • Loading branch information
andsens committed Jun 5, 2016
1 parent 0d54ad6 commit 49ddd38
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
8 changes: 4 additions & 4 deletions bootstrapvz/providers/docker/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Name
Provider
~~~~~~~~

- ``dockerfile``: Inline dockerfile that should be appended to
the one created by the bootstrapper.
- ``dockerfile``: List of Dockerfile instructions that should be appended to
the ones created by the bootstrapper.
``optional``

- ``labels``: Labels that should be added to the dockerfile.
Expand All @@ -49,8 +49,8 @@ Example:
name: bootstrap-vz:latest
provider:
name: docker
dockerfile: >
CMD /bin/bash
dockerfile:
- CMD /bin/bash
labels:
name: debian-{system.release}-{system.architecture}-{%y}{%m}{%d}
description: Debian {system.release} {system.architecture}
6 changes: 5 additions & 1 deletion bootstrapvz/providers/docker/manifest-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ properties:
patternProperties:
^.+$: {type: string}
dockerfile:
type: string
type: array
items:
# https://github.com/turtlebender/docker/blob/6e2662b3bad319679e17fe25d410f246820ab0e9/builder/job.go#L27
type: string
pattern: '^(ENTRYPOINT|CMD|USER|WORKDIR|ENV|VOLUME|EXPOSE|ONBUILD|LABEL|MAINTAINER)'
system:
type: object
properties:
Expand Down
15 changes: 8 additions & 7 deletions bootstrapvz/providers/docker/tasks/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CreateDockerfileEntry(Task):

@classmethod
def run(cls, info):
info._docker['dockerfile'] = ''
info._docker['dockerfile'] = []


class CreateImage(Task):
Expand All @@ -21,8 +21,10 @@ def run(cls, info):
from pipes import quote
tar_cmd = ['tar', '--create', '--numeric-owner',
'--directory', info.volume.path, '.']
docker_cmd = ['docker', 'import', '--change', info._docker['dockerfile'], '-',
info.manifest.name.format(**info.manifest_vars)]
docker_cmd = ['docker', 'import']
for instruction in info._docker['dockerfile']:
docker_cmd.extend(['--change', instruction])
docker_cmd.extend(['-', info.manifest.name.format(**info.manifest_vars)])
cmd = ' '.join(map(quote, tar_cmd)) + ' | ' + ' '.join(map(quote, docker_cmd))
[info._docker['image_id']] = log_check_call([cmd], shell=True)

Expand Down Expand Up @@ -55,9 +57,8 @@ def escape(value):
value = value.replace('\n', '\\\n')
value = '"' + value + '"'
return value
kv_pairs = [label + '=' + escape(value) for label, value in labels.items()]
# Add some nice newlines and indentation
info._docker['dockerfile'] += 'LABEL ' + ' \\\n '.join(kv_pairs) + '\n'
for label, value in labels.items():
info._docker['dockerfile'].append('LABEL {}={}'.format(label, escape(value)))


class AppendManifestDockerfile(Task):
Expand All @@ -68,4 +69,4 @@ class AppendManifestDockerfile(Task):

@classmethod
def run(cls, info):
info._docker['dockerfile'] += info.manifest.provider['dockerfile'] + '\n'
info._docker['dockerfile'].extend(info.manifest.provider['dockerfile'])
4 changes: 2 additions & 2 deletions manifests/examples/docker/jessie-minimized.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ provider:
name: docker
labels:
description: Debian {system.release} {system.architecture}
dockerfile: >
CMD /bin/bash
dockerfile:
- CMD /bin/bash
bootstrapper:
workspace: /target
variant: minbase
Expand Down

0 comments on commit 49ddd38

Please sign in to comment.