Skip to content

Commit

Permalink
Fix parsing host and container ports in docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Simon committed Sep 20, 2024
1 parent c37f64a commit 4d1da5e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ docs/api-docs/*
docs/_build/*
.cfgnet
.idea/*
.vscode
.vscode
env/*
10 changes: 5 additions & 5 deletions src/cfgnet/plugins/concept/docker_compose_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class DockerComposePlugin(YAMLPlugin):
file_name = re.compile(r"docker-compose(.\w+)?.yml")
ports = re.compile(r"(?P<in>[0-9]{4}):(?P<out>[0-9]{4})")
ports = re.compile(r"(?P<host>[0-9]{4}):(?P<container>[0-9]{4})")

def __init__(self):
super().__init__("docker-compose")
Expand All @@ -36,13 +36,13 @@ def _parse_scalar_node(self, node, parent):
if node.value != "":
match = DockerComposePlugin.ports.match(node.value)
if match is not None:
port_in = ValueNode(name=match.group("in"))
port_out = ValueNode(name=match.group("out"))
port_in = ValueNode(name=match.group("host"))
port_out = ValueNode(name=match.group("container"))
option_port_in = OptionNode(
"in", node.start_mark.line + 1, ConfigType.PORT
"host", node.start_mark.line + 1, ConfigType.PORT
)
option_port_out = OptionNode(
"out", node.start_mark.line + 1, ConfigType.PORT
"container", node.start_mark.line + 1, ConfigType.PORT
)
parent.add_child(option_port_in)
parent.add_child(option_port_out)
Expand Down
6 changes: 3 additions & 3 deletions tests/cfgnet/plugins/concept/test_docker_compose_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ def test_parse_docker_compose_file(get_plugin):
assert make_id("docker-compose.yml", "file", "docker-compose.yml") in ids
assert make_id("docker-compose.yml", "version", "version:3.9") in ids
assert (
make_id("docker-compose.yml", "services", "web", "ports", "in", "5000")
make_id("docker-compose.yml", "services", "web", "ports", "host", "8000")
in ids
)
assert (
make_id(
"docker-compose.yml", "services", "web", "ports", "out", "5000"
"docker-compose.yml", "services", "web", "ports", "container", "5000"
)
in ids
)
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_config_types(get_plugin):
"services",
"web",
"ports",
"in",
"container",
"5000",
),
nodes,
Expand Down
2 changes: 1 addition & 1 deletion tests/files/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9" # optional since v1.27.0
services:
web:
ports:
- "5000:5000"
- "8000:5000"
init: true
backend:
image: /test
Expand Down

0 comments on commit 4d1da5e

Please sign in to comment.