Skip to content

Commit da0ed1e

Browse files
author
Joseph Hamman
committed
Merge branch 'master' of github.com:jupyter/repo2docker into feature/launch_script
2 parents 907732c + dd563b2 commit da0ed1e

26 files changed

+896
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ MANIFEST
99

1010
.DS_Store
1111
.cache
12+
.pytest_cache
1213
.coverage
1314
htmlcov
1415

.travis.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ install:
1515
script:
1616
# cd into tests so CWD being repo2docker does not hide
1717
# possible issues with MANIFEST.in
18-
- if [ ${REPO_TYPE} == "r" ]; then cd tests && travis_wait pytest --cov repo2docker
19-
-v ${REPO_TYPE}; else cd tests && travis_retry pytest --cov repo2docker -v ${REPO_TYPE};
20-
fi
18+
- pushd tests;
19+
if [ ${REPO_TYPE} == "r" ]; then
20+
travis_wait pytest --cov repo2docker -v ${REPO_TYPE};
21+
else
22+
travis_retry pytest --cov repo2docker -v ${REPO_TYPE};
23+
fi;
24+
popd;
25+
- pip install -r docs/doc-requirements.txt
26+
- pushd docs;
27+
make html;
28+
popd;
2129
after_success:
2230
- pip install codecov
2331
- codecov
@@ -35,8 +43,10 @@ jobs:
3543
branch: master
3644
env:
3745
matrix:
46+
- REPO_TYPE=base
3847
- REPO_TYPE=conda
3948
- REPO_TYPE=venv
49+
- REPO_TYPE=stencila
4050
- REPO_TYPE=julia
4151
- REPO_TYPE=r
4252
- REPO_TYPE=dockerfile

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33

44
# You can set these variables from the command line.
5-
SPHINXOPTS =
5+
SPHINXOPTS = -W
66
SPHINXBUILD = python3 -msphinx
77
SPHINXPROJ = repo2docker
88
SOURCEDIR = source

docs/source/config_files.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
.. NOTE: the header characters are different in this file because it is 'included' in another site
2+
.. see https://raw.githubusercontent.com/jupyterhub/binder/master/doc/using.rst
13
.. _config-files:
24

35
Configuration Files
4-
~~~~~~~~~~~~~~~~~~~
6+
-------------------
57

68
``repo2docker`` looks for configuration files in the repository being built
79
to determine how to build it. In general, ``repo2docker`` uses the same
@@ -31,7 +33,7 @@ Below is a list of supported configuration files (roughly in the order of build
3133
:depth: 1
3234

3335
``Dockerfile``
34-
^^^^^^^^^^^^^^
36+
~~~~~~~~~~~~~~
3537

3638
In the majority of cases, providing your own Dockerfile is not necessary as the base
3739
images provide core functionality, compact image sizes, and efficient builds. We recommend
@@ -46,7 +48,7 @@ best-practices with Dockerfiles.
4648
.. _environment-yml:
4749

4850
``environment.yml``
49-
^^^^^^^^^^^^^^^^^^^
51+
~~~~~~~~~~~~~~~~~~~
5052

5153
``environment.yml`` is the standard configuration file used by Anaconda, conda,
5254
and miniconda that lets you install Python packages.
@@ -63,31 +65,31 @@ a Python version in a ``runtime.txt`` file in addition to your
6365
``environment.yml``, your ``runtime.txt`` **will be ignored**.
6466

6567
``requirements.txt``
66-
^^^^^^^^^^^^^^^^^^^^
68+
~~~~~~~~~~~~~~~~~~~~
6769

6870
This specifies a list of Python packages that should be installed in your
6971
environment. Our
7072
`requirements.txt example <https://github.com/binder-examples/requirements/blob/master/requirements.txt>`_
7173
on GitHub shows a typical requirements file.
7274

7375
``REQUIRE``
74-
^^^^^^^^^^^
76+
~~~~~~~~~~~
7577

7678
This specifies a list of Julia packages. Repositories with a ``REQUIRE`` file
7779
**must also contain an** ``environment.yml`` **file**. To see an example of a
7880
Julia repository with ``REQUIRE`` and ``environment.yml``,
7981
visit `binder-examples/julia-python <https://github.com/binder-examples/julia-python>`_.
8082

8183
``install.R``
82-
^^^^^^^^^^^^^
84+
~~~~~~~~~~~~~
8385

8486
This is used to install R libraries pinned to a specific snapshot on
8587
`MRAN <https://mran.microsoft.com/documents/rro/reproducibility>`_.
8688
To set the date of the snapshot add a runtime.txt_.
8789
For an example ``install.R`` file, visit our `example install.R file <https://github.com/binder-examples/r/blob/master/install.R>`_.
8890

8991
``apt.txt``
90-
^^^^^^^^^^^
92+
~~~~~~~~~~~
9193

9294
A list of Debian packages that should be installed. The base image used is usually the latest released
9395
version of Ubuntu.
@@ -97,7 +99,7 @@ We use ``apt.txt``, for example, to install LaTeX in our
9799

98100

99101
``setup.py``
100-
^^^^^^^^^^^^
102+
~~~~~~~~~~~~
101103

102104
To install your repository like a Python package, you may include a
103105
``setup.py`` file. repo2docker installs ``setup.py`` files by running
@@ -110,7 +112,7 @@ repo2docker **requires configuration files such as** ``environment.yml`` or
110112
.. _postBuild:
111113

112114
``postBuild``
113-
^^^^^^^^^^^^^
115+
~~~~~~~~~~~~~
114116

115117
A script that can contain arbitrary commands to be run after the whole repository has been built. If you
116118
want this to be a shell script, make sure the first line is ```#!/bin/bash``.
@@ -136,7 +138,7 @@ equivalent.
136138
.. _runtime.txt:
137139

138140
``runtime.txt``
139-
^^^^^^^^^^^^^^^
141+
~~~~~~~~~~~~~~~
140142

141143
This allows you to control the runtime of Python or R.
142144

docs/source/deploy.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
.. _usage:
1+
.. _deploy:
22

33
Using ``repo2docker`` as part of your Continuous Integration
44
============================================================
55

6-
We've created for you the `continuous-build <https://www.github.com/binder-examples/continuous-build/>`_
7-
repository so that you can push a `Docker <https://docs.docker.com/>`_ container
6+
We've created for you the `continuous-build <https://www.github.com/binder-examples/continuous-build/>`_
7+
repository so that you can push a `Docker <https://docs.docker.com/>`_ container
88
to `Docker Hub <https://hub.docker.com/>`_ directly from a Github repository
99
that has a Jupyter notebook. Here are instructions to do this.
1010

@@ -25,7 +25,7 @@ to pull from Docker Hub.
2525
Step 1. Clone the Repository
2626
............................
2727
First, fork the `continuous-build <https://www.github.com/binder-examples/continuous-build/>`_ Github
28-
repository to your account, and clone the branch.
28+
repository to your account, and clone the branch.
2929

3030
git clone https://www.github.com/<username>/continuous-build
3131
# or
@@ -35,17 +35,17 @@ repository to your account, and clone the branch.
3535
Step 2. Choose your Configuration
3636
.................................
3737

38-
The hidden folder `.circleci/config.yml` has instructions for `CircleCI <https://circleci.com/dashboard/>`_
38+
The hidden folder `.circleci/config.yml` has instructions for `CircleCI <https://circleci.com/dashboard/>`_
3939
to automatically discover and build your repo2docker jupyter notebook container.
40-
The default template provided in the repository in this folder will do the most basic steps,
40+
The default template provided in the repository in this folder will do the most basic steps,
4141
including:
4242

4343
1. clone of the repository with the notebook that you specify
4444
2. build
4545
3. push to Docker Hub
4646

4747
This repository aims to provide templates for your use.
48-
If you have a request for a new template, please
48+
If you have a request for a new template, please
4949
`let us know <https://www.github.com/binder-examples/continuous-build/issues/>`_.
5050
We will add templates as they are requested to do additional tasks like test containers, run
5151
nbconvert, etc.
@@ -57,7 +57,7 @@ creating a new folder called "myrepo" and then copying the entire folder there.
5757
mkdir -p myrepo
5858
cp -R continuous-build/.circleci myrepo/
5959

60-
You would then logically create a Github repository in the "myrepo" folder,
60+
You would then logically create a Github repository in the "myrepo" folder,
6161
add the circleci configuration folder, and continue on to the next steps.
6262

6363
cd myrepo
@@ -69,7 +69,7 @@ Step 3. Docker Hub
6969
..................
7070
Go to `Docker Hub <https://hub.docker.com/>`_, log in, and click the big blue
7171
button that says "create repository" (not an automated build). Choose an organization
72-
and name that you like (in the traditional format ``<ORG>/<NAME>``), and
72+
and name that you like (in the traditional format ``<ORG>/<NAME>``), and
7373
remember it! We will be adding it, along with your
7474
Docker credentials, to be encrypted CircleCI environment variables.
7575

@@ -78,12 +78,12 @@ Step 4. Connect to CircleCI
7878
...........................
7979
If you navigate to the main `app page <https://circleci.com/dashboard/>`_ you
8080
should be able to click "Add Projects" and then select your repository. If you don't
81-
see it on the list, then select a different organization in the top left. Once
81+
see it on the list, then select a different organization in the top left. Once
8282
you find the repository, you can click the button to "Start Building" adn accept
8383
the defaults.
8484

8585
Before you push or trigger a build, let's set up the following environment variables.
86-
Also in the project interface on CirleCi, click the gears icon next to the project
86+
Also in the project interface on CirleCi, click the gears icon next to the project
8787
name to get to your project settings. Under settings, click on the "Environment
8888
Variables" tab. In this section, you want to define the following:
8989

@@ -92,7 +92,7 @@ Variables" tab. In this section, you want to define the following:
9292
3. ``DOCKER_USER`` and ``DOCKER_PASS`` should be your credentials (to allowing pushing)
9393
4. ``REPO_NAME`` should be the full Github url (or other) of the repository with the notebook. This doesn't have to coincide with the repository you are using to do the build (e.g., "myrepo" in our example).
9494

95-
If you don't define the ``CONTAINER_NAME`` it will default to be the repository where it is
95+
If you don't define the ``CONTAINER_NAME`` it will default to be the repository where it is
9696
building from, which you should only do if the Docker Hub repository is named equivalently.
9797
If you don't define either of the variables from step 3. for the Docker credentials, your
9898
image will build but not be pushed to Docker Hub. Finally, if you don't define the ``REPO_NAME``
@@ -120,7 +120,7 @@ You should then be able to pull your new container, and run it! Here is an examp
120120

121121
docker pull <ORG>/<NAME>
122122
docker run -it --name repo2docker -p 8888:8888 <ORG>/<NAME> jupyter notebook --ip 0.0.0.0
123-
123+
124124

125125
For a pre-built working example, try the following:
126126

docs/source/install.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ Bash on Windows) provides additional information about Windows and docker.
5757

5858
.. _using Windows and the WSL: https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
5959

60-
.. _jupyterhub:
60+
.. _jupyterhub_ready:
6161

6262
JupyterHub-ready images
6363
-----------------------
6464

65-
`JupyterHub <https://jupyterhub.readthedocs.io/en/stable/>`_ allows multiple
65+
JupyterHub_ allows multiple
6666
users to collaborate on a shared Jupyter server. ``repo2docker`` can build
6767
Docker images that can be shared within a JupyterHub deployment. For example,
6868
`mybinder.org <https://mybinder.org>`_ uses JupyterHub and ``repo2docker``
6969
to allow anyone to build a Docker image of a git repository online and
7070
share an executable version of the repository with a URL to the built image.
7171

72-
To build `JupyterHub <https://github.com/jupyterhub/jupyterhub>`_-ready
72+
To build JupyterHub_-ready
7373
Docker images with ``repo2docker``, the version of your JupterHub deployment
7474
must be included in the ``environment.yml`` or ``requiements.txt`` of the
7575
git repositories you build.
@@ -79,3 +79,5 @@ command to run ``jupyterhub-singleuser`` by adding this line in your
7979
configuration file::
8080

8181
c.DockerSpawner.cmd = ['jupyterhub-singleuser']
82+
83+
.. _JupyterHub: https://github.com/jupyterhub/jupyterhub

docs/source/usage.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repo2docker is called with this command::
2121
where ``<URL-or-path to repo>`` is a URL or path to the source repository.
2222

2323
For example, use the following to build an image of Peter Norvig's
24-
`Pytudes <https://github.com/norvig/pytudes/>`_::
24+
Pytudes_::
2525

2626
jupyter-repo2docker https://github.com/norvig/pytudes
2727

@@ -47,12 +47,14 @@ Python 3.6 unless you include the version of Python in your
4747
Python 2.7, 3.5, and 3.6. In the case of this repo, a Python version is not
4848
specified in their configuation files and Python 3.6 is installed.
4949

50-
`Pytudes <https://github.com/norvig/pytudes>`_
50+
Pytudes_
5151
uses a `requirements.txt file <https://github.com/norvig/pytudes/blob/master/requirements.txt>`_
5252
to specify its Python environment. ``repo2docker`` uses ``pip`` to install
5353
dependencies listed in the ``requirement.txt`` in the image. To learn more about
5454
configuration files in ``repo2docker`` visit :ref:`config-files`.
5555

56+
.. _Pytudes: https://github.com/norvig/pytudes
57+
5658
When the image is built, a message will be output to your terminal::
5759

5860
Copy/paste this URL into your browser when you connect for the first time,

repo2docker/app.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import time
1919

2020
import docker
21+
from urllib.parse import urlparse
2122
from docker.utils import kwargs_from_env
2223
from docker.errors import DockerException
2324
import escapism
@@ -520,11 +521,26 @@ def start_container(self):
520521
Returns running container
521522
"""
522523
client = docker.from_env(version='auto')
524+
525+
docker_host = os.environ.get('DOCKER_HOST')
526+
if docker_host:
527+
host_name = urlparse(docker_host).hostname
528+
else:
529+
host_name = '127.0.0.1'
530+
self.hostname = host_name
531+
523532
if not self.run_cmd:
524533
port = str(self._get_free_port())
525534
self.port = port
526-
run_cmd = ['jupyter', 'notebook', '--ip', '0.0.0.0',
527-
'--port', port]
535+
# To use the option --NotebookApp.custom_display_url
536+
# make sure the base-notebook image is updated:
537+
# docker pull jupyter/base-notebook
538+
run_cmd = [
539+
'jupyter', 'notebook',
540+
'--ip', '0.0.0.0',
541+
'--port', port,
542+
"--NotebookApp.custom_display_url=http://{}:{}".format(host_name, port),
543+
]
528544
ports = {'%s/tcp' % port: port}
529545
else:
530546
# run_cmd given by user, if port is also given then pass it on
@@ -535,6 +551,7 @@ def start_container(self):
535551
ports = {}
536552
# store ports on self so they can be retrieved in tests
537553
self.ports = ports
554+
538555
container_volumes = {}
539556
if self.volumes:
540557
api_client = docker.APIClient(

0 commit comments

Comments
 (0)