Add buildargs parameter to support Dockerfile ARG directive. (#4349)

* Add buildargs parameter to support Dockerfile ARG directive.

* Fix doc_strings. Doc string for load_path was completely missing.
This commit is contained in:
Chris Houseknecht
2016-08-05 18:14:31 -05:00
committed by Matt Clay
parent f6b126d412
commit 2514ec5056

View File

@@ -32,9 +32,14 @@ description:
options: options:
archive_path: archive_path:
description: description:
- Use with state C(presen) to archive an image to a .tar file. - Use with state C(present) to archive an image to a .tar file.
required: false required: false
version_added: "2.1" version_added: "2.1"
load_path:
description:
- Use with state C(present) to load an image from a .tar file.
required: false
version_added: "2.2"
dockerfile: dockerfile:
description: description:
- Use with state C(present) to provide an alternate name for the Dockerfile to use when building an image. - Use with state C(present) to provide an alternate name for the Dockerfile to use when building an image.
@@ -120,6 +125,14 @@ options:
- If C(name) parameter format is I(name:tag), then tag value from C(name) will take precedence. - If C(name) parameter format is I(name:tag), then tag value from C(name) will take precedence.
default: latest default: latest
required: false required: false
buildargs:
description:
- Provide a dictionary of C(key:value) build arguments that map to Dockerfile ARG directive.
- Docker expects the value to be a string. For convenience any non-string values will be converted to strings.
- Requires Docker API >= 1.21 and docker-py >= 1.7.0.
type: complex
required: false
version_added: "2.2"
container_limits: container_limits:
description: description:
- A dictionary of limits applied to each container created by the build process. - A dictionary of limits applied to each container created by the build process.
@@ -212,6 +225,14 @@ EXAMPLES = '''
push: yes push: yes
load_path: my_sinatra.tar load_path: my_sinatra.tar
push: True push: True
- name: Build image and with buildargs
docker_image:
path: /path/to/build/dir
name: myimage
buildargs:
log_volume: /var/log/myapp
listen_port: 8080
''' '''
RETURN = ''' RETURN = '''
@@ -258,6 +279,7 @@ class ImageManager(DockerBaseClass):
self.tag = parameters.get('tag') self.tag = parameters.get('tag')
self.http_timeout = parameters.get('http_timeout') self.http_timeout = parameters.get('http_timeout')
self.push = parameters.get('push') self.push = parameters.get('push')
self.buildargs = parameters.get('buildargs')
# If name contains a tag, it takes precedence over tag parameter. # If name contains a tag, it takes precedence over tag parameter.
repo, repo_tag = parse_repository_tag(self.name) repo, repo_tag = parse_repository_tag(self.name)
@@ -484,6 +506,12 @@ class ImageManager(DockerBaseClass):
params['tag'] = "%s:%s" % (self.name, self.tag) params['tag'] = "%s:%s" % (self.name, self.tag)
if self.container_limits: if self.container_limits:
params['container_limits'] = self.container_limits params['container_limits'] = self.container_limits
if self.buildargs:
for key, value in self.buildargs.iteritems():
if not isinstance(value, basestring):
self.buildargs[key] = str(value)
params['buildargs'] = self.buildargs
for line in self.client.build(**params): for line in self.client.build(**params):
# line = json.loads(line) # line = json.loads(line)
self.log(line, pretty_print=True) self.log(line, pretty_print=True)
@@ -540,7 +568,8 @@ def main():
rm=dict(type='bool', default=True), rm=dict(type='bool', default=True),
state=dict(type='str', choices=['absent', 'present', 'build'], default='present'), state=dict(type='str', choices=['absent', 'present', 'build'], default='present'),
tag=dict(type='str', default='latest'), tag=dict(type='str', default='latest'),
use_tls=dict(type='str', default='no', choices=['no', 'encrypt', 'verify']) use_tls=dict(type='str', default='no', choices=['no', 'encrypt', 'verify']),
buildargs=dict(type='dict', default=None),
) )
client = AnsibleDockerClient( client = AnsibleDockerClient(