mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-17 15:02:57 +00:00
Test run_hooks when executables fail (#1987)
This commit is contained in:
@@ -24,11 +24,19 @@ for f in "${1}/"*; do
|
|||||||
echo "Sourcing shell script: ${f}"
|
echo "Sourcing shell script: ${f}"
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "${f}"
|
source "${f}"
|
||||||
|
# shellcheck disable=SC2181
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo "${f} has failed, continuing execution"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ -x "${f}" ] ; then
|
if [ -x "${f}" ] ; then
|
||||||
echo "Running executable: ${f}"
|
echo "Running executable: ${f}"
|
||||||
"${f}"
|
"${f}"
|
||||||
|
# shellcheck disable=SC2181
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
echo "${f} has failed, continuing execution"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "Ignoring non-executable: ${f}"
|
echo "Ignoring non-executable: ${f}"
|
||||||
fi
|
fi
|
||||||
|
11
tests/docker-stacks-foundation/run-hooks-failures/a.sh
Normal file
11
tests/docker-stacks-foundation/run-hooks-failures/a.sh
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright (c) Jupyter Development Team.
|
||||||
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
|
echo "Started: a.sh"
|
||||||
|
|
||||||
|
export OTHER_VAR=456
|
||||||
|
|
||||||
|
run-unknown-command
|
||||||
|
|
||||||
|
echo "Finished: a.sh"
|
12
tests/docker-stacks-foundation/run-hooks-failures/b.py
Executable file
12
tests/docker-stacks-foundation/run-hooks-failures/b.py
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# Copyright (c) Jupyter Development Team.
|
||||||
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
print("Started: b.py")
|
||||||
|
print(f"OTHER_VAR={os.environ['OTHER_VAR']}")
|
||||||
|
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print("Finished: b.py")
|
7
tests/docker-stacks-foundation/run-hooks-failures/c.sh
Normal file
7
tests/docker-stacks-foundation/run-hooks-failures/c.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright (c) Jupyter Development Team.
|
||||||
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
|
echo "Started: c.sh"
|
||||||
|
|
||||||
|
run-unknown-command
|
11
tests/docker-stacks-foundation/run-hooks-failures/d.sh
Normal file
11
tests/docker-stacks-foundation/run-hooks-failures/d.sh
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright (c) Jupyter Development Team.
|
||||||
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "Started: d.sh"
|
||||||
|
|
||||||
|
run-unknown-command
|
||||||
|
|
||||||
|
echo "Finished: d.sh"
|
@@ -93,3 +93,37 @@ def test_run_hooks_with_files(container: TrackedContainer) -> None:
|
|||||||
assert "Executable python file was successfully" in logs
|
assert "Executable python file was successfully" in logs
|
||||||
assert "Ignoring non-executable: /home/jovyan/data-copy//non_executable.py" in logs
|
assert "Ignoring non-executable: /home/jovyan/data-copy//non_executable.py" in logs
|
||||||
assert "SOME_VAR is 123" in logs
|
assert "SOME_VAR is 123" in logs
|
||||||
|
|
||||||
|
|
||||||
|
def test_run_hooks_with_failures(container: TrackedContainer) -> None:
|
||||||
|
host_data_dir = THIS_DIR / "run-hooks-failures"
|
||||||
|
cont_data_dir = "/home/jovyan/data"
|
||||||
|
# https://forums.docker.com/t/all-files-appear-as-executable-in-file-paths-using-bind-mount/99921
|
||||||
|
# Unfortunately, Docker treats all files in mounter dir as executable files
|
||||||
|
# So we make a copy of mounted dir inside a container
|
||||||
|
command = (
|
||||||
|
"cp -r /home/jovyan/data/ /home/jovyan/data-copy/ &&"
|
||||||
|
"source /usr/local/bin/run-hooks.sh /home/jovyan/data-copy/"
|
||||||
|
)
|
||||||
|
logs = container.run_and_wait(
|
||||||
|
timeout=5,
|
||||||
|
volumes={str(host_data_dir): {"bind": cont_data_dir, "mode": "ro"}},
|
||||||
|
tty=True,
|
||||||
|
no_failure=False,
|
||||||
|
command=["bash", "-c", command],
|
||||||
|
)
|
||||||
|
|
||||||
|
for file in ["a.sh", "b.py", "c.sh", "d.sh"]:
|
||||||
|
assert f"Started: {file}" in logs
|
||||||
|
|
||||||
|
for file in ["a.sh"]:
|
||||||
|
assert f"Finished: {file}" in logs
|
||||||
|
for file in ["b.py", "c.sh", "d.sh"]:
|
||||||
|
assert f"Finished: {file}" not in logs
|
||||||
|
|
||||||
|
for file in ["b.py", "c.sh"]:
|
||||||
|
assert (
|
||||||
|
f"/home/jovyan/data-copy//{file} has failed, continuing execution" in logs
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "OTHER_VAR=456" in logs
|
||||||
|
Reference in New Issue
Block a user