Skip to content

Commit 09cbb00

Browse files
authored
Add oc command inside the containers (#439)
1 parent 337d82a commit 09cbb00

File tree

8 files changed

+45
-47
lines changed

8 files changed

+45
-47
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,6 @@ out
181181
docs/examples/context/_build
182182
docs/examples/context
183183
devspaces/context/*.whl
184+
devspaces/context/setup-image.sh
185+
final/context/setup-image.sh
186+
final/setup-image.sh

devspaces/context/setup.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# cspell: ignore makecache overlayfs libssh chgrp noplugins
33
set -eux pipefail
44

5-
set -e
5+
DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
6+
67
dnf --noplugins remove -y -q subscription-manager dnf-plugin-subscription-manager
78
dnf -y -q makecache
89
dnf -y -q update
@@ -40,3 +41,6 @@ chgrp -R 0 /home && chmod -R g=u /etc/passwd /etc/group /home
4041
cp podman.py /usr/bin/podman.wrapper
4142
chown 0:0 /usr/bin/podman.wrapper
4243
chmod +x /usr/bin/podman.wrapper
44+
45+
# shellcheck disable=SC1091
46+
source "$DIR/setup-image.sh"

final/context/setup.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

final/setup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# cspell: ignore onigurumacffi,makecache,euxo,libssh,overlayfs,setcaps,minrate,openh264,additionalimage,mountopt,nodev,iname,chsh,PIND
33
set -euxo pipefail
44

5+
DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
56
# When building for multiple-architectures in parallel using emulation
67
# it's really easy for one/more dnf processes to timeout or mis-count
78
# the minimum download rates. Bump both to be extremely forgiving of
@@ -115,6 +116,9 @@ activate-global-python-argcomplete
115116
# Install oh-my-zsh
116117
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
117118

119+
# shellcheck disable=SC1091
120+
source "$DIR/setup-image.sh"
121+
118122
# add some helpful CLI commands to check we do not remove them inadvertently and output some helpful version information at build time.
119123
set -ex
120124
ansible --version

tests/integration/test_container.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,28 @@ def test_container_in_container(
7272

7373

7474
@pytest.mark.container
75-
@pytest.mark.parametrize("app", ("nano", "tar", "vi"))
76-
def test_app(exec_container: Callable[[str], subprocess.CompletedProcess[str]], app: str) -> None:
75+
@pytest.mark.parametrize(
76+
("app", "command"),
77+
(
78+
pytest.param("nano", None, id="nano"),
79+
pytest.param("tar", None, id="tar"),
80+
pytest.param("vi", None, id="vi"),
81+
pytest.param("oc", "oc version --client=true", id="oc"),
82+
),
83+
)
84+
def test_app(
85+
exec_container: Callable[[str], subprocess.CompletedProcess[str]],
86+
app: str,
87+
command: str | None,
88+
) -> None:
7789
"""Test the presence of an app in the container.
7890
7991
Args:
8092
exec_container: The container executor.
8193
app: The app to test.
94+
command: Command used to test tool version and or presence.
8295
"""
83-
result = exec_container(f"{app} --version")
96+
result = exec_container(command if command else f"{app} --version")
8497
assert result.returncode == 0, f"{app} command failed"
8598

8699

@@ -203,7 +216,7 @@ def test_nav_collections(
203216
f"ansible-navigator collections --lf {tmp_path}/navigator.log"
204217
f" --pp never --eei {infrastructure.navigator_ee}"
205218
)
206-
stdout = container_tmux.send_and_wait(cmd=cmd, wait_for=":help help", timeout=10)
219+
stdout = container_tmux.send_and_wait(cmd=cmd, wait_for=":help help", timeout=15)
207220
assert any("ansible.builtin" in line for line in stdout)
208221
assert any("ansible.posix" in line for line in stdout)
209222
cmd = ":0"
@@ -247,7 +260,7 @@ def test_nav_playbook(
247260
infrastructure: The testing infrastructure
248261
"""
249262
cmd = f"ansible-creator init playbook test_ns.test_name {tmp_path}"
250-
stdout = container_tmux.send_and_wait(cmd=cmd, wait_for="created", timeout=10)
263+
stdout = container_tmux.send_and_wait(cmd=cmd, wait_for="created", timeout=15)
251264
output = "Note: playbook project created"
252265
assert any(output in line for line in stdout)
253266
cmd = (
@@ -295,5 +308,5 @@ def test_builder(
295308
tmp_path: The temporary directory.
296309
"""
297310
ee_file = test_fixture_dir_container / "execution-environment.yml"
298-
result = exec_container(f"ansible-builder build -f {ee_file} -c {tmp_path}")
311+
result = exec_container(f"ANSIBLE_NOCOLOR=1 ansible-builder build -f {ee_file} -c {tmp_path}")
299312
assert "Complete!" in result.stdout

tools/devspaces.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fi
1818
tox -e pkg
1919
rm -f devspaces/context/*.whl
2020
cp dist/*.whl devspaces/context
21+
cp tools/setup-image.sh devspaces/context
2122

2223
# we force use of linux/amd64 platform because source image supports only this
2324
# platform and without it, it will fail to cross-build when task runs on arm64.

tools/ee.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ fi
6161
python -m build --outdir "$REPO_DIR/final/dist/" --wheel "$REPO_DIR"
6262
ansible-builder create -f execution-environment.yml --output-filename Containerfile -v3
6363
$BUILD_CMD -f context/Containerfile context/ --tag "${TAG_BASE}"
64+
cp tools/setup-image.sh final/
6465
$BUILD_CMD -f final/Containerfile final/ --tag "${CONTAINER_NAME}"
6566

6667
# Check container size and layers
67-
mk containers check $CONTAINER_NAME --engine="${ADT_CONTAINER_ENGINE}" --max-size=1300 --max-layers=22
68+
mk containers check $CONTAINER_NAME --engine="${ADT_CONTAINER_ENGINE}" --max-size=1430 --max-layers=22
6869

6970
pytest -v --only-container --container-engine=docker --image-name "${CONTAINER_NAME}"
7071
# -k test_navigator_simple

tools/setup-image.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash -e
2+
# Script that is used to install the necessary dependencies for both container
3+
# images, devspaces and ee.
4+
# cspell: ignore exuo
5+
set -exuo pipefail
6+
7+
# Install oc client
8+
OC_VERSION=4.15
9+
curl -s -L "https://mirror.openshift.com/pub/openshift-v4/$(arch)/clients/ocp/stable-${OC_VERSION}/openshift-client-linux.tar.gz" | tar -C /usr/local/bin -xz --no-same-owner
10+
chmod +x /usr/local/bin/oc
11+
oc version --client=true

0 commit comments

Comments
 (0)