Make docker_swarm_service option publish.published_port optional (#101)

* Change docker_swarm_service option publish.published_port from required to optional. If not specified random high port is assigned by docker.

* Update changelogs/fragments/101-make-service-published-port-optional.yaml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
sgpinkus
2021-03-13 23:37:56 +11:00
committed by GitHub
parent b42b76fc45
commit 5b74313023
2 changed files with 8 additions and 4 deletions
+5 -4
View File
@@ -365,7 +365,7 @@ options:
description:
- The port to make externally available.
type: int
required: yes
required: no
target_port:
description:
- The port inside the container to expose.
@@ -2066,9 +2066,10 @@ class DockerService(DockerBaseClass):
for port in self.publish:
port_spec = {
'Protocol': port['protocol'],
'PublishedPort': port['published_port'],
'TargetPort': port['target_port']
}
if port.get('published_port'):
port_spec['PublishedPort'] = port['published_port']
if port.get('mode'):
port_spec['PublishMode'] = port['mode']
ports.append(port_spec)
@@ -2214,7 +2215,7 @@ class DockerServiceManager(object):
ds.publish.append({
'protocol': port['Protocol'],
'mode': port.get('PublishMode', None),
'published_port': int(port['PublishedPort']),
'published_port': port.get('PublishedPort', None),
'target_port': int(port['TargetPort'])
})
@@ -2618,7 +2619,7 @@ def main():
options=dict(type='dict'),
)),
publish=dict(type='list', elements='dict', options=dict(
published_port=dict(type='int', required=True),
published_port=dict(type='int', required=False),
target_port=dict(type='int', required=True),
protocol=dict(type='str', default='tcp', choices=['tcp', 'udp']),
mode=dict(type='str', choices=['ingress', 'host']),