Skip to content

Commit e8c40f0

Browse files
authored
Ensure built image is fully qualified (#499)
1 parent d697ae0 commit e8c40f0

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

.config/requirements-test.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pre-commit
88
pydoclint
99
pylint
1010
pytest
11+
pytest-instafail
1112
pytest-xdist
1213
requests
1314
ruff

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,4 @@ devspaces/context/*.whl
184184
devspaces/context/setup-image.sh
185185
final/context/setup-image.sh
186186
final/setup-image.sh
187+
image.tar

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ addopts = "-ra --showlocals --durations=10 -p no:pytest-ansible"
329329
cache_dir = "./.cache/.pytest"
330330
log_cli = true
331331
log_cli_level = "WARNING"
332-
showlocals = true
333332
testpaths = "tests"
334333
tmp_path_retention_policy = "failed"
335334
verbosity_assertions = 2

tests/conftest.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,12 @@ def _start_container() -> None:
289289
Raises:
290290
ValueError: If the container engine is not podman or docker.
291291
"""
292+
engine = INFRASTRUCTURE.container_engine
292293
cmd = (
293-
f"{INFRASTRUCTURE.container_engine} kill {INFRASTRUCTURE.container_name};"
294-
f"{INFRASTRUCTURE.container_engine} rm {INFRASTRUCTURE.container_name}"
294+
f'{engine} ps -q --filter "name={INFRASTRUCTURE.container_name}" | xargs -r {engine} stop;'
295+
f'{engine} ps -aq --filter "name=$name" | xargs -r {engine} rm'
295296
)
296-
subprocess.run(cmd, check=False, capture_output=True, shell=True, text=True)
297+
subprocess.run(cmd, check=True, capture_output=False, shell=True, text=True)
297298

298299
auth_file = "$XDG_RUNTIME_DIR/containers/auth.json"
299300
auth_mount = ""
@@ -321,21 +322,12 @@ def _start_container() -> None:
321322
err = f"Failed to start container:\ncmd: {cmd}\nstdout: {exc.stdout}\nstderr: {exc.stderr}"
322323
pytest.fail(err)
323324

324-
# image is local, can't be pulled, use default
325-
if INFRASTRUCTURE.image_name.startswith("localhost"):
326-
nav_ee = get_nav_default_ee_in_container()
327-
warning = f"localhost in image name, pulling default {nav_ee} for navigator"
328-
# dots and slashes in image name, use it
329-
elif "/" in INFRASTRUCTURE.image_name and "." in INFRASTRUCTURE.image_name:
330-
nav_ee = INFRASTRUCTURE.image_name
331-
warning = f"/ and . in image name, pulling {nav_ee} for navigator"
332-
# otherwise, use default
325+
if INFRASTRUCTURE.image_name:
326+
INFRASTRUCTURE.navigator_ee = INFRASTRUCTURE.image_name
327+
_proc = _exec_container(command="podman load < image.tar")
333328
else:
334329
nav_ee = get_nav_default_ee_in_container()
335-
warning = f"localhost / . not in image name, pulling default {nav_ee} for navigator"
336-
LOGGER.warning(warning)
337-
INFRASTRUCTURE.navigator_ee = nav_ee
338-
_proc = _exec_container(command=f"podman pull {nav_ee}")
330+
_proc = _exec_container(command=f"podman pull {nav_ee}")
339331

340332

341333
def get_nav_default_ee_in_container() -> str:

tests/integration/test_container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_user_shell(exec_container: Callable[[str], subprocess.CompletedProcess[
109109

110110

111111
@pytest.mark.container
112-
def test_navigator_simple_c_in_c(
112+
def test_navigator_2_c_in_c(
113113
exec_container: Callable[[str], subprocess.CompletedProcess[str]],
114114
test_fixture_dir_container: Path,
115115
tmp_path: Path,
@@ -134,7 +134,7 @@ def test_navigator_simple_c_in_c(
134134

135135

136136
@pytest.mark.container
137-
def test_navigator_simple(
137+
def test_navigator_1(
138138
cmd_in_tty: Callable[[str], tuple[str, str, int]],
139139
infrastructure: Infrastructure,
140140
test_fixture_dir: Path,

tools/ee.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ fi
2020
REPO_DIR=$(git rev-parse --show-toplevel)
2121

2222
TAG_BASE=community-ansible-dev-tools-base:latest
23-
IMAGE_NAME=community-ansible-dev-tools:test
23+
# keep the localhost/ prefix on image name all the time or we will face various
24+
# problems related to docker/podman differences when this is missing.
25+
IMAGE_NAME=localhost/community-ansible-dev-tools:test
2426

2527
# BUILD_CMD="podman build --squash-all"
2628
BUILD_CMD="${ADT_CONTAINER_ENGINE} buildx build --progress=plain"
@@ -64,11 +66,15 @@ $BUILD_CMD -f context/Containerfile context/ --tag "${TAG_BASE}"
6466
cp tools/setup-image.sh final/
6567
$BUILD_CMD -f final/Containerfile final/ --tag "${IMAGE_NAME}"
6668

69+
# We save local image in order to import it inside the container later for c-in-c testing
70+
# Do not try to gzip the image because there is no notable change in size and
71+
# it seems to add ~20% more in total test execution time.
72+
$ADT_CONTAINER_ENGINE save $IMAGE_NAME > image.tar
73+
6774
# Check container size and layers
6875
mk containers check "$IMAGE_NAME" --engine="${ADT_CONTAINER_ENGINE}" --max-size=1500 --max-layers=22
6976

70-
pytest -v --only-container --container-engine="${ADT_CONTAINER_ENGINE}" --image-name "${IMAGE_NAME}"
71-
# -k test_navigator_simple
77+
pytest -v --include-container --container-engine="${ADT_CONTAINER_ENGINE}" --image-name "${IMAGE_NAME}"
7278
# Test the build of example execution environment to avoid regressions
7379
pushd docs/examples
7480
ansible-builder build

0 commit comments

Comments
 (0)