Skip to content

Commit

Permalink
docker_image: add network parameter (ansible#50313)
Browse files Browse the repository at this point in the history
* docker_image: add network parameter

Add a network parameter to the docker_image module to specify the
network to use for RUN commands.

Called it network instead of network_mode as the latter seems like a
legacy of when there were just a few default options to choose from,
while now the name of an arbitrary network can be specified.

Fixes ansible#21433

* Format description

* Update docker_image option_minimal_versions

* Ensure network_mode param optional
  • Loading branch information
ushuz authored and kbreit committed Jan 11, 2019
1 parent 7493f72 commit 7af2558
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/ansible/modules/cloud/docker/docker_image.py
Expand Up @@ -94,6 +94,11 @@
required: false
version_added: "2.1"
type: bool
network:
description:
- The network to use for C(RUN) build instructions.
required: false
version_added: "2.8"
nocache:
description:
- Do not use cache when building an image.
Expand Down Expand Up @@ -299,6 +304,7 @@ def __init__(self, client, results):
self.force = parameters.get('force')
self.load_path = parameters.get('load_path')
self.name = parameters.get('name')
self.network = parameters.get('network')
self.nocache = parameters.get('nocache')
self.path = parameters.get('path')
self.pull = parameters.get('pull')
Expand Down Expand Up @@ -552,6 +558,8 @@ def build_image(self):
params['buildargs'] = self.buildargs
if self.cache_from:
params['cache_from'] = self.cache_from
if self.network:
params['network_mode'] = self.network

for line in self.client.build(**params):
# line = json.loads(line)
Expand Down Expand Up @@ -613,6 +621,7 @@ def main():
http_timeout=dict(type='int'),
load_path=dict(type='path'),
name=dict(type='str', required=True),
network=dict(type='str'),
nocache=dict(type='bool', default=False),
path=dict(type='path', aliases=['build_path']),
pull=dict(type='bool', default=True),
Expand All @@ -627,6 +636,7 @@ def main():

option_minimal_versions = dict(
cache_from=dict(docker_py_version='2.1.0', docker_api_version='1.25'),
network=dict(docker_py_version='2.4.0', docker_api_version='1.25'),
)

client = AnsibleDockerClient(
Expand Down

0 comments on commit 7af2558

Please sign in to comment.