Skip to content

Commit b8d8206

Browse files
authored
Merge pull request #375 from betatim/start-script-docs
Split out tests, tweak docs, and a style change
2 parents 12b8f1d + 286f56c commit b8d8206

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

docs/source/config_files.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ repo2docker **requires configuration files such as** ``environment.yml`` or
117117
A script that can contain arbitrary commands to be run after the whole repository has been built. If you
118118
want this to be a shell script, make sure the first line is ```#!/bin/bash``.
119119

120-
An example usecase of ``postBuild`` file is JupyterLab's demo on mybinder.org.
120+
An example use-case 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

@@ -126,12 +126,18 @@ their demo for binder <https://github.com/jupyterlab/jupyterlab-demo/blob/master
126126
``start``
127127
^^^^^^^^^
128128

129-
A script that can contain arbitrary commands to be run at runtime (as an
129+
A script that can contain simple commands to be run at runtime (as an
130130
`ENTRYPOINT <https://docs.docker.com/engine/reference/builder/#entrypoint>`
131131
to the docker container). If you want this to be a shell script, make sure the
132132
first line is ```#!/bin/bash``. The last line must be ```exec "$@"```
133133
equivalent.
134134

135+
Use this to set environment variables that software installed in your container
136+
expects to be set. This script is executed each time your binder is started and
137+
should at most take a few seconds to run.
138+
139+
If you only need to run things once during the build phase use :ref:`postBuild`.
140+
135141
.. TODO: Discuss runtime limits, best practices, etc.
136142
Also, point to an example.
137143

repo2docker/buildpacks/base.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
{% endif -%}
133133
134134
# Add start script
135-
{% if start_script -%}
135+
{% if start_script is not none -%}
136136
RUN chmod +x "{{ start_script }}"
137137
ENTRYPOINT ["{{ start_script }}"]
138138
{% endif -%}
@@ -331,8 +331,8 @@ def get_post_build_scripts(self):
331331
"""
332332
An ordered list of executable scripts to execute after build.
333333
334-
Is run as a non-root user, and must be executable. Used for doing
335-
things that are currently not supported by other means!
334+
Is run as a non-root user, and must be executable. Used for performing
335+
build time steps that can not be perfomed with standard tools.
336336
337337
The scripts should be as deterministic as possible - running it twice
338338
should not produce different results!
@@ -341,18 +341,18 @@ def get_post_build_scripts(self):
341341

342342
def get_start_script(self):
343343
"""
344-
An ordered list of executable scripts to be executated at runtime.
345-
These scripts are added as an `ENTRYPOINT` to the container.
344+
The path to a script to be executated at container start up.
346345
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).
346+
This script is added as the `ENTRYPOINT` to the container.
350347
351-
The scripts should be as deterministic as possible - running it twice
352-
should not produce different results.
348+
It is run as a non-root user, and must be executable. Used for performing
349+
run time steps that can not be perfomed with standard tools. For example
350+
setting environment variables for your repository.
353351
352+
The script should be as deterministic as possible - running it twice
353+
should not produce different results.
354354
"""
355-
return ''
355+
return None
356356

357357
def binder_path(self, path):
358358
"""Locate a file"""
@@ -546,4 +546,4 @@ def get_start_script(self):
546546
start = self.binder_path('start')
547547
if os.path.exists(start):
548548
return start
549-
return ''
549+
return None
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
System - launch scripts
2+
-----------------------
3+
4+
It is possible to run `start` scripts before your notebook server starts.
5+
This is useful to set environment variables or perform last minute
6+
configurations.
7+
8+
In this example we set a environment variable in the `start` script.
File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
if [ "$TEST_START_VAR" != "var is set" ]
5+
then
6+
echo "TEST_START_VAR is not set"
7+
exit 1
8+
fi

0 commit comments

Comments
 (0)