|
131 | 131 | {% endfor %} |
132 | 132 | {% endif -%} |
133 | 133 |
|
| 134 | +# Add start script |
| 135 | +{% if start_script -%} |
| 136 | +RUN chmod +x "{{ start_script }}" |
| 137 | +ENTRYPOINT ["{{ start_script }}"] |
| 138 | +{% endif -%} |
| 139 | +
|
134 | 140 | # Specify the default command to run |
135 | 141 | CMD ["jupyter", "notebook", "--ip", "0.0.0.0"] |
136 | 142 |
|
@@ -333,6 +339,21 @@ def get_post_build_scripts(self): |
333 | 339 | """ |
334 | 340 | return [] |
335 | 341 |
|
| 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 | + |
336 | 357 | def binder_path(self, path): |
337 | 358 | """Locate a file""" |
338 | 359 | if os.path.exists('binder'): |
@@ -380,6 +401,7 @@ def render(self): |
380 | 401 | build_script_files=self.get_build_script_files(), |
381 | 402 | base_packages=sorted(self.get_base_packages()), |
382 | 403 | post_build_scripts=self.get_post_build_scripts(), |
| 404 | + start_script=self.get_start_script(), |
383 | 405 | appendix=self.appendix, |
384 | 406 | ) |
385 | 407 |
|
@@ -519,3 +541,9 @@ def get_post_build_scripts(self): |
519 | 541 | if os.path.exists(post_build): |
520 | 542 | return [post_build] |
521 | 543 | 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 '' |
0 commit comments