Skip to content

Commit

Permalink
docker compat: use hyphens to join container names
Browse files Browse the repository at this point in the history
docker-compose uses - not _ to join container names to project.
not a huge thing, but for services making assumptions based on this
it can catch off guard, and is easy to make the same.

Signed-off-by: Matt Phillips <mphillips81@bloomberg.net>
  • Loading branch information
mattp- committed Nov 29, 2024
1 parent 626e278 commit 226c9d6
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ def _parse_compose_file(self):

container_names_by_service[service_name] = []
for num in range(1, replicas + 1):
name0 = f"{project_name}_{service_name}_{num}"
name0 = f"{project_name}-{service_name}-{num}"
if num == 1:
name = service_desc.get("container_name", name0)
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_podman_compose_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_deps(self):
"wget -O - http://web:8000/hosts",
])
self.assertIn(b"HTTP request sent, awaiting response... 200 OK", output)
self.assertIn(b"deps_web_1", output)
self.assertIn(b"deps-web-1", output)
finally:
self.run_subprocess_assert_returncode([
podman_compose_path(),
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_podman_compose_extends_w_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_extends_w_file(self): # when file is Dockerfile for building the image
compose_yaml_path(),
"ps",
])
self.assertIn("extends_w_file_web_1", str(output))
self.assertIn("extends_w_file_important_web_1", str(output))
self.assertIn("extends_w_file-web-1", str(output))
self.assertIn("extends_w_file-important_web-1", str(output))
finally:
self.run_subprocess_assert_returncode([
podman_compose_path(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_extends_w_file_subdir(self): # when file is Dockerfile for building th
compose_yaml_path(),
"ps",
])
self.assertIn("extends_w_file_subdir_web_1", str(output))
self.assertIn("extends_w_file_subdir-web-1", str(output))
finally:
self.run_subprocess_assert_returncode([
podman_compose_path(),
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_podman_compose_ipam_default.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
# SPDt-License-Identifier: GPL-2.0

import json
import os
Expand Down Expand Up @@ -34,7 +34,7 @@ def test_ipam_default(self):
[
"podman",
"inspect",
"ipam_default_testipam_1",
"ipam_default-testipam-1",
],
)
network_info = json.loads(output.decode('utf-8'))[0]
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_podman_compose_multicompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ def test_multicompose(self):
os.path.join(os.path.join(test_path(), "multicompose"), "d2/docker-compose.yml"),
"ps",
])
self.assertIn(b"d1_web1_1", output)
self.assertIn(b"d1_web2_1", output)
self.assertIn(b"d1-web1-1", output)
self.assertIn(b"d1-web2-1", output)

output, _ = self.run_subprocess_assert_returncode([
"podman",
"exec",
"-ti",
"d1_web1_1",
"d1-web1-1",
"sh",
"-c",
"set",
Expand All @@ -58,7 +58,7 @@ def test_multicompose(self):
"podman",
"exec",
"-ti",
"d1_web2_1",
"d1-web2-1",
"sh",
"-c",
"set",
Expand All @@ -70,7 +70,7 @@ def test_multicompose(self):
"podman",
"exec",
"-ti",
"d1_web1_1",
"d1-web1-1",
"sh",
"-c",
"cat /var/www/html/index.txt",
Expand All @@ -82,7 +82,7 @@ def test_multicompose(self):
"podman",
"exec",
"-ti",
"d1_web2_1",
"d1-web2-1",
"sh",
"-c",
"cat /var/www/html/index.txt",
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_podman_compose_nets_test1.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def test_nets_test1(self):
compose_yaml_path(),
"ps",
])
self.assertIn(b"nets_test1_web1_1", output)
self.assertIn(b"nets_test1_web2_1", output)
self.assertIn(b"nets_test1-web1-1", output)
self.assertIn(b"nets_test1-web2-1", output)

response = requests.get('http://localhost:8001/index.txt')
self.assertTrue(response.ok)
Expand All @@ -49,7 +49,7 @@ def test_nets_test1(self):
output, _ = self.run_subprocess_assert_returncode([
"podman",
"inspect",
"nets_test1_web1_1",
"nets_test1-web1-1",
])
container_info = json.loads(output.decode('utf-8'))[0]

Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_podman_compose_nets_test2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def test_nets_test2(self):
compose_yaml_path(),
"ps",
])
self.assertIn(b"nets_test2_web1_1", output)
self.assertIn(b"nets_test2_web2_1", output)
self.assertIn(b"nets_test2-web1-1", output)
self.assertIn(b"nets_test2-web2-1", output)

response = requests.get('http://localhost:8001/index.txt')
self.assertTrue(response.ok)
Expand All @@ -49,13 +49,13 @@ def test_nets_test2(self):
output, _ = self.run_subprocess_assert_returncode([
"podman",
"inspect",
"nets_test2_web1_1",
"nets_test2-web1-1",
])
container_info = json.loads(output.decode('utf-8'))[0]

# check if network got specific name from networks top-level element
self.assertEqual(
list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2_mystack"
list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2-mystack"
)

# check if Host port is the same as prodvided by the service port
Expand All @@ -70,12 +70,12 @@ def test_nets_test2(self):
output, _ = self.run_subprocess_assert_returncode([
"podman",
"inspect",
"nets_test2_web2_1",
"nets_test2-web2-1",
])
container_info = json.loads(output.decode('utf-8'))[0]

self.assertEqual(
list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2_mystack"
list(container_info["NetworkSettings"]["Networks"].keys())[0], "nets_test2-mystack"
)

self.assertEqual(
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_podman_compose_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def test_networks(self):
'"{{.Names}}"',
]
out, _ = self.run_subprocess_assert_returncode(check_cmd)
self.assertIn(b"nets_test_ip_web1_1", out)
self.assertIn(b"nets_test_ip_web2_1", out)
self.assertIn(b"nets_test_ip-web1-1", out)
self.assertIn(b"nets_test_ip-web2-1", out)

expected_wget = {
"172.19.1.10": "test1",
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_podman_compose_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_down_with_network(self):
"-d",
])
output, _, _ = self.run_subprocess(["podman", "network", "ls"])
self.assertIn("network_mystack", output.decode())
self.assertIn("network-mystack", output.decode())
finally:
self.run_subprocess_assert_returncode([
"coverage",
Expand All @@ -211,4 +211,4 @@ def test_down_with_network(self):
"down",
])
output, _, _ = self.run_subprocess(["podman", "network", "ls"])
self.assertNotIn("network_mystack", output.decode())
self.assertNotIn("network-mystack", output.decode())

0 comments on commit 226c9d6

Please sign in to comment.