Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dockerize/dockerize.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ def __init__(self,
runtime=None,
buildcmd=None,
symlinks=SymlinkOptions.PRESERVE,
envs=None,
workdir=None,
build=True):

self.docker = {}
self.docker['runtime'] = runtime if runtime else 'docker'
self.docker['buildcmd'] = buildcmd if buildcmd else 'build'
self.docker['envs'] = envs if envs else []
self.docker['workdir'] = workdir

if cmd:
self.docker['cmd'] = json.dumps(shlex.split(cmd))
Expand Down Expand Up @@ -230,7 +234,7 @@ def copy_files(self):
self.copy_file(srcitem, dst)

def build_image(self):
cmd = [self.docker['runtime'], self.docker['buildcmd']]
cmd = [self.docker['runtime']] + shlex.split(self.docker['buildcmd'])
if 'tag' in self.docker:
cmd += ['-t', self.docker['tag']]
cmd += [self.targetdir]
Expand Down
13 changes: 12 additions & 1 deletion dockerize/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def parse_args():
default=[],
help='Add file <src> to image at <dst>')

parser.add_argument('--env',
action='append',
default=[],
help='Add ENV={arg} in Dockerfile')

parser.add_argument('--workdir',
default=None,
help='Add WORKDIR={arg} in Dockerfile')

parser.add_argument('--symlinks', '-L',
default='copy-unsafe',
help='One of preserve, copy-unsafe, '
Expand Down Expand Up @@ -114,7 +123,9 @@ def main():
tag=args.tag,
targetdir=args.output_dir,
build=not args.no_build,
symlinks=args.symlinks)
symlinks=args.symlinks,
envs=args.env,
workdir=args.workdir)

for path in args.paths:
app.add_file(path)
Expand Down
8 changes: 8 additions & 0 deletions dockerize/templates/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ ENTRYPOINT {{docker.entrypoint}}
{% if docker.cmd -%}
CMD {{docker.cmd}}
{% endif -%}

{% if docker.workdir is not none %}
WORKDIR {{docker.workdir}}
{% endif %}

{% for env in docker.envs %}
ENV {{env}}
{% endfor %}