aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/build_defs/docker/rewrite_json.py
diff options
context:
space:
mode:
authorGravatar Damien Martin-Guillerez <dmarting@google.com>2015-09-29 15:11:30 +0000
committerGravatar Florian Weikert <fwe@google.com>2015-09-30 09:35:22 +0000
commitb00b7ac4c16d5c9e2bab8bf7508bc64e188be861 (patch)
tree01676d1e46c186c731d39cf5108f0023147ec13b /tools/build_defs/docker/rewrite_json.py
parentd7b64bd03100300b79cd33d04904ce9b0e6a5332 (diff)
[docker] Add workdir attribute
The workdir attribute set the initial working directory when starting the docker container. Contrary to the WORKDIR directive (see https://docs.docker.com/reference/builder/#workdir), it only affects the entry point. -- MOS_MIGRATED_REVID=104201472
Diffstat (limited to 'tools/build_defs/docker/rewrite_json.py')
-rw-r--r--tools/build_defs/docker/rewrite_json.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/tools/build_defs/docker/rewrite_json.py b/tools/build_defs/docker/rewrite_json.py
index dd7d205bac..fe62a91149 100644
--- a/tools/build_defs/docker/rewrite_json.py
+++ b/tools/build_defs/docker/rewrite_json.py
@@ -50,6 +50,10 @@ gflags.DEFINE_list(
'volumes', None,
'Augment the "Volumes" of the previous layer')
+gflags.DEFINE_string(
+ 'workdir', None,
+ 'Set the working directory for the layer')
+
gflags.DEFINE_list(
'env', None,
'Augment the "Env" of the previous layer')
@@ -58,7 +62,8 @@ FLAGS = gflags.FLAGS
_MetadataOptionsT = namedtuple(
'MetadataOptionsT',
- ['name', 'parent', 'size', 'entrypoint', 'cmd', 'env', 'ports', 'volumes'])
+ ['name', 'parent', 'size', 'entrypoint', 'cmd', 'env', 'ports', 'volumes',
+ 'workdir'])
class MetadataOptions(_MetadataOptionsT):
@@ -66,12 +71,12 @@ class MetadataOptions(_MetadataOptionsT):
def __new__(cls, name=None, parent=None, size=None,
entrypoint=None, cmd=None, env=None,
- ports=None, volumes=None):
+ ports=None, volumes=None, workdir=None):
"""Constructor."""
return super(MetadataOptions, cls).__new__(
cls, name=name, parent=parent, size=size,
entrypoint=entrypoint, cmd=cmd, env=env,
- ports=ports, volumes=volumes)
+ ports=ports, volumes=volumes, workdir=workdir)
_DOCKER_VERSION = '1.5.0'
@@ -175,6 +180,9 @@ def RewriteMetadata(data, options):
for p in options.volumes:
output['config']['Volumes'][p] = {}
+ if options.workdir:
+ output['config']['WorkingDir'] = options.workdir
+
# TODO(mattmoor): comment, created, container_config
# container_config contains information about the container
@@ -263,7 +271,8 @@ def main(unused_argv):
cmd=FLAGS.command,
env=FLAGS.env,
ports=FLAGS.ports,
- volumes=FLAGS.volumes))
+ volumes=FLAGS.volumes,
+ workdir=FLAGS.workdir))
with open(FLAGS.output, 'w') as fp:
json.dump(output, fp, sort_keys=True)