Skip to content

Commit 9a82af2

Browse files
authored
Merge pull request #1381 from Athishpranav2003/extra-hosts
Added support to parse extra hosts
2 parents 0beb67a + b85fa9e commit 9a82af2

File tree

6 files changed

+56
-0
lines changed

6 files changed

+56
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the bug in parsing to add identify `extra-hosts` field in build parameters.

podman_compose.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,6 +3122,8 @@ def cleanup_temp_dockfile() -> None:
31223122
build_args.extend(["--platform", cnt["platform"]])
31233123
for secret in build_desc.get("secrets", []):
31243124
build_args.extend(get_secret_args(compose, cnt, secret, podman_is_building=True))
3125+
for i in build_desc.get("extra_hosts", []):
3126+
build_args.extend(["--add-host", i])
31253127
for tag in build_desc.get("tags", []):
31263128
build_args.extend(["-t", tag])
31273129
labels = build_desc.get("labels", [])

tests/integration/extra_hosts/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM nopush/podman-compose-test
2+
3+
RUN getent hosts example.internal
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "3"
2+
services:
3+
web1:
4+
build:
5+
context: ./context
6+
dockerfile: Dockerfile
7+
extra_hosts:
8+
- "example.internal:127.0.0.1"
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
import os
4+
import unittest
5+
6+
from tests.integration.test_utils import RunSubprocessMixin
7+
from tests.integration.test_utils import podman_compose_path
8+
from tests.integration.test_utils import test_path
9+
10+
11+
def compose_yaml_path() -> str:
12+
"""Returns the path to the compose file used for this test module"""
13+
base_path = os.path.join(test_path(), "extra_hosts")
14+
return os.path.join(base_path, "docker-compose.yml")
15+
16+
17+
class TestComposeExtraHosts(unittest.TestCase, RunSubprocessMixin):
18+
def test_extra_hosts(self) -> None:
19+
try:
20+
self.run_subprocess_assert_returncode([
21+
podman_compose_path(),
22+
"-f",
23+
compose_yaml_path(),
24+
"build",
25+
"--no-cache",
26+
])
27+
28+
self.run_subprocess_assert_returncode([
29+
podman_compose_path(),
30+
"-f",
31+
compose_yaml_path(),
32+
"up",
33+
"-d",
34+
])
35+
36+
finally:
37+
self.run_subprocess_assert_returncode([
38+
podman_compose_path(),
39+
"-f",
40+
compose_yaml_path(),
41+
"down",
42+
])

0 commit comments

Comments
 (0)