Skip to content

Commit 12b8f1d

Browse files
authored
Merge pull request #363 from jhamman/feature/launch_script
Add launch script
2 parents dd563b2 + 915fc8d commit 12b8f1d

File tree

8 files changed

+68
-1
lines changed

8 files changed

+68
-1
lines changed

docs/source/config_files.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ An example usecase of ``postBuild`` file is JupyterLab's demo on mybinder.org.
121121
It uses a ``postBuild`` file in a folder called ``binder`` to `prepare
122122
their demo for binder <https://github.com/jupyterlab/jupyterlab-demo/blob/master/binder/postBuild>`_.
123123

124+
.. _start:
125+
126+
``start``
127+
^^^^^^^^^
128+
129+
A script that can contain arbitrary commands to be run at runtime (as an
130+
`ENTRYPOINT <https://docs.docker.com/engine/reference/builder/#entrypoint>`
131+
to the docker container). If you want this to be a shell script, make sure the
132+
first line is ```#!/bin/bash``. The last line must be ```exec "$@"```
133+
equivalent.
134+
135+
.. TODO: Discuss runtime limits, best practices, etc.
136+
Also, point to an example.
137+
124138
.. _runtime.txt:
125139

126140
``runtime.txt``

docs/source/dev_newbuildpack.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Note that this doesn't apply to adding additional libraries / UI to existing
2323
buildpacks. For example, if we had an R buildpack and it supported IRKernel,
2424
it is much easier to
2525
just support RStudio / Shiny with it, since those are library additions than entirely
26-
new buildpacks.
26+
new buildpacks.

repo2docker/buildpacks/base.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@
131131
{% endfor %}
132132
{% endif -%}
133133
134+
# Add start script
135+
{% if start_script -%}
136+
RUN chmod +x "{{ start_script }}"
137+
ENTRYPOINT ["{{ start_script }}"]
138+
{% endif -%}
139+
134140
# Specify the default command to run
135141
CMD ["jupyter", "notebook", "--ip", "0.0.0.0"]
136142
@@ -333,6 +339,21 @@ def get_post_build_scripts(self):
333339
"""
334340
return []
335341

342+
def get_start_script(self):
343+
"""
344+
An ordered list of executable scripts to be executated at runtime.
345+
These scripts are added as an `ENTRYPOINT` to the container.
346+
347+
Is run as a non-root user, and must be executable. Used for doing
348+
things that are currently not supported by other means and need to be
349+
applied at runtime (set environment variables).
350+
351+
The scripts should be as deterministic as possible - running it twice
352+
should not produce different results.
353+
354+
"""
355+
return ''
356+
336357
def binder_path(self, path):
337358
"""Locate a file"""
338359
if os.path.exists('binder'):
@@ -380,6 +401,7 @@ def render(self):
380401
build_script_files=self.get_build_script_files(),
381402
base_packages=sorted(self.get_base_packages()),
382403
post_build_scripts=self.get_post_build_scripts(),
404+
start_script=self.get_start_script(),
383405
appendix=self.appendix,
384406
)
385407

@@ -519,3 +541,9 @@ def get_post_build_scripts(self):
519541
if os.path.exists(post_build):
520542
return [post_build]
521543
return []
544+
545+
def get_start_script(self):
546+
start = self.binder_path('start')
547+
if os.path.exists(start):
548+
return start
549+
return ''
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
System - Post-build scripts
2+
---------------------------
3+
4+
It is possible to run scripts after you've built the environment specified in
5+
your other files. This could be used to, for example, download data or run
6+
some configuration scripts.
7+
8+
In this example, we download and install a Jupyter Notebook extension.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
jupyter nbextension enable --py --sys-prefix ipyleaflet
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ipyleaflet

tests/venv/start/postBuild/start

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
export TEST_START_VAR="var is set"
4+
5+
exec "$@"

tests/venv/start/postBuild/verify

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
jupyter nbextension list | grep 'jupyter-leaflet' | grep enabled
4+
5+
if [ "$TEST_START_VAR" != "var is set" ]
6+
then
7+
echo "TEST_START_VAR is not set"
8+
exit 1
9+
fi

0 commit comments

Comments
 (0)