Skip to content

Commit cb4621f

Browse files
authored
Merge pull request #987 from betatim/stream-logs
[MRG] Stream jupyter server logs to a file
2 parents 1140dd1 + f2ed09b commit cb4621f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

repo2docker/buildpacks/repo2docker-entrypoint

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22
# lightest possible entrypoint that ensures that
33
# we use a login shell to get a fully configured shell environment
44
# (e.g. sourcing /etc/profile.d, ~/.bashrc, and friends)
5+
6+
# Setup a file descriptor (FD) that is connected to a tee process which
7+
# writes its input to $REPO_DIR/.jupyter-server-log.txt
8+
# We later use this FD as a place to redirect the output of the actual
9+
# command to. We can't add `tee` to the command directly as that will prevent
10+
# the container from exiting when `docker stop` is run.
11+
# See https://stackoverflow.com/a/55678435
12+
exec {log_fd}> >(exec tee $REPO_DIR/.jupyter-server-log.txt)
13+
514
if [[ ! -z "${R2D_ENTRYPOINT:-}" ]]; then
615
if [[ ! -x "$R2D_ENTRYPOINT" ]]; then
716
chmod u+x "$R2D_ENTRYPOINT"
817
fi
9-
exec "$R2D_ENTRYPOINT" "$@"
18+
exec "$R2D_ENTRYPOINT" "$@" >&"$log_fd"
1019
else
11-
exec "$@"
20+
exec "$@" >&"$log_fd"
1221
fi
22+
23+
# Close the logging output again
24+
#exec {log_fd}>&-

tests/unit/test_env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def test_env():
5858

5959
# all docker output is returned by repo2docker on stderr
6060
# extract just the declare for better failure message formatting
61+
# stdout should be empty
62+
assert not result.stdout
63+
64+
# stderr should contain lines of output
6165
declares = [x for x in result.stderr.split("\n") if x.startswith("declare")]
6266
assert 'declare -x FOO="{}"'.format(ts) in declares
6367
assert 'declare -x BAR="baz"' in declares

0 commit comments

Comments
 (0)