From a1d30e5152395a2e49084c46ac7bd14ee3221458 Mon Sep 17 00:00:00 2001 From: Greg Werner Date: Sat, 24 Oct 2020 18:54:12 -0400 Subject: [PATCH 1/6] lock from to image version and use tmp to copy/install packages Signed-off-by: Greg Werner --- Dockerfile | 19 +++++++++++++------ jupyter_notebook_config.py | 8 ++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index aad1e0b..2896d2a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,28 @@ -FROM jupyter/minimal-notebook:latest +FROM jupyter/minimal-notebook:45bfe5a474fa + +ARG PGWEB_VERSION=0.11.6 USER root RUN apt-get update \ + && apt-get upgrade -y \ && apt-get install -y \ curl \ unzip \ - wget + wget \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* # install pgweb -ENV PGWEB_VERSION=0.11.6 +ENV PGWEB_VERSION="${PGWEB_VERSION}" RUN wget -q "https://github.com/sosedoff/pgweb/releases/download/v${PGWEB_VERSION}/pgweb_linux_amd64.zip" \ && unzip pgweb_linux_amd64.zip -d /usr/bin \ && mv /usr/bin/pgweb_linux_amd64 /usr/bin/pgweb # setup package, enable classic extension, build lab extension USER "${NB_USER}" -COPY . "${HOME}"/ -COPY requirements.txt "${HOME}"/ -WORKDIR "${HOME}" +RUN mkdir -p "/${HOME}/jupyter-pgweb-proxy" +COPY . "/${HOME}/jupyter-pgweb-proxy" +WORKDIR "/${HOME}/jupyter-pgweb-proxy" RUN python3 -m pip install . RUN python3 -m pip install -r requirements.txt \ && jupyter serverextension enable --sys-prefix jupyter_server_proxy \ @@ -29,3 +34,5 @@ USER root RUN fix-permissions /etc/jupyter USER "${NB_USER}" + +WORKDIR "${HOME}" \ No newline at end of file diff --git a/jupyter_notebook_config.py b/jupyter_notebook_config.py index c6b3468..fa91a88 100644 --- a/jupyter_notebook_config.py +++ b/jupyter_notebook_config.py @@ -10,7 +10,15 @@ "headers": {"Content-Security-Policy": "frame-ancestors 'self' *"}, "cookie_options": {"SameSite": "None", "Secure": True}, } + +# allows running the notebook as root c.NotebookApp.allow_root = True + +# accepts any origin by default, change to add restrictions c.NotebookApp.allow_origin = '*' + +# add a token if you would like to run this notebook on a public network c.NotebookApp.token = '' + +# forward to jupyterlab by default c.NotebookApp.default_url = '/lab' From f2aae80298750e004f032f4ca000aa0b1afbca47 Mon Sep 17 00:00:00 2001 From: Greg Werner Date: Sat, 24 Oct 2020 19:13:12 -0400 Subject: [PATCH 2/6] clean up config Signed-off-by: Greg Werner --- jupyter_notebook_config.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/jupyter_notebook_config.py b/jupyter_notebook_config.py index 9f9d1d9..99a2625 100644 --- a/jupyter_notebook_config.py +++ b/jupyter_notebook_config.py @@ -13,7 +13,6 @@ # allows running the notebook as root c.NotebookApp.allow_root = True -<<<<<<< HEAD # accepts any origin by default, change to add restrictions c.NotebookApp.allow_origin = '*' @@ -23,8 +22,3 @@ # forward to jupyterlab by default c.NotebookApp.default_url = '/lab' -======= -c.NotebookApp.allow_origin = "*" -c.NotebookApp.token = "" -c.NotebookApp.default_url = "/lab" ->>>>>>> 7c4467fc3bba33a2b0621bfada4178706ff2c324 From ad0d5a00f59739c1279a9016d64203b5d5454ef4 Mon Sep 17 00:00:00 2001 From: Greg Werner Date: Sat, 24 Oct 2020 19:14:43 -0400 Subject: [PATCH 3/6] bump version Signed-off-by: Greg Werner --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bc71424..4a88002 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setuptools.setup( name="jupyter-pgweb-proxy", - version="0.2.0", + version="0.2.1", url="https://github.com/illumidesk/jupyter-pgweb-proxy", author="IllumiDesk Team", description="hello@illumidesk.com", From 923d1083a28456c02739ca69a3a05600f6ab988c Mon Sep 17 00:00:00 2001 From: Greg Werner Date: Sat, 24 Oct 2020 20:45:34 -0400 Subject: [PATCH 4/6] udpate tests and readme Signed-off-by: Greg Werner --- README.md | 13 +++++++---- tests/test_pgweb.py | 17 +++++++------- tests/test_pgweb_with_docker.py | 39 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 tests/test_pgweb_with_docker.py diff --git a/README.md b/README.md index 1f07d83..ca1ca83 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,16 @@ This package was built from the [`illumidesk/cookiecutter-jupyter-server-proxy`] ## Requirements -- Python 3.6+ -- Jupyter Notebook 6.0+ -- JupyterLab 2.1+ +- [Python 3.6+](https://www.python.org/downloads/) +- [Jupyter Notebook 6.0+](https://pypi.org/project/notebook/) +- [JupyterLab 2.1+](https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html) -This package executes the standard `pgweb` command. This command assumes the `pgweb` command is available in the environment's `PATH`. +(Optional) For testing: + +- [Docker](https://docs.docker.com/get-docker/) +- [docker-compose](https://docs.docker.com/compose/install/) + +This package executes the standard `pgweb` command. This command assumes the `pgweb` command is available in the environment's `PATH`. For convenience, the tests include cases that assert outputs when running the `pgweb` command from a docker container. If you don't need to run tests with this setup running in a docker container, then remove the `tests/test_pgweb_docker.py` file or comment out the code in the file. ## What? diff --git a/tests/test_pgweb.py b/tests/test_pgweb.py index 7e2c542..c5cfbc3 100644 --- a/tests/test_pgweb.py +++ b/tests/test_pgweb.py @@ -1,3 +1,5 @@ +import os + import docker from docker.errors import ContainerError @@ -10,7 +12,7 @@ @pytest.mark.parametrize( - "language,version_output", + "executable,version_output", [ ( "pgweb", @@ -21,12 +23,12 @@ ), ], ) -def test_pgweb_version(language, version_output): +def test_pgweb_version(executable, version_output): """Ensure pweb is available in the PATH and that it returns the correct version""" - LOGGER.info(f"Test that language {language} is correctly installed ...") - client = docker.from_env() - output = client.containers.run("illumidesk/pgweb:latest", f"{language} --version") - output_decoded = output.decode("utf-8").split(" ") + LOGGER.info(f"Test that language {executable} is correctly installed ...") + f = os.popen(f'{executable} --version') + output = f.read() + output_decoded = output.split(" ") assert output_decoded[0:2] == version_output LOGGER.info(f"Output from command: {output_decoded[0:3]}") @@ -35,5 +37,4 @@ def test_invalid_cmd(): """Ensure that an invalid command returns a docker.errors.ContainerError""" with pytest.raises(ContainerError): LOGGER.info("Test an invalid command ...") - client = docker.from_env() - client.containers.run("illumidesk/pgweb", "foo --version") + f = os.popen("foo --version") diff --git a/tests/test_pgweb_with_docker.py b/tests/test_pgweb_with_docker.py new file mode 100644 index 0000000..6f33df5 --- /dev/null +++ b/tests/test_pgweb_with_docker.py @@ -0,0 +1,39 @@ +import docker +from docker.errors import ContainerError + +import logging + +import pytest + + +LOGGER = logging.getLogger(__name__) + + +@pytest.mark.parametrize( + "language,version_output", + [ + ( + "pgweb", + [ + "Pgweb", + "v0.11.6", + ], + ), + ], +) +def test_pgweb_version_with_docker(language, version_output): + """Ensure pweb is available in the PATH and that it returns the correct version""" + LOGGER.info(f"Test that language {language} is correctly installed ...") + client = docker.from_env() + output = client.containers.run("illumidesk/pgweb:latest", f"{language} --version") + output_decoded = output.decode("utf-8").split(" ") + assert output_decoded[0:2] == version_output + LOGGER.info(f"Output from command: {output_decoded[0:3]}") + + +def test_invalid_cmd_with_docker(): + """Ensure that an invalid command returns a docker.errors.ContainerError""" + with pytest.raises(ContainerError): + LOGGER.info("Test an invalid command ...") + client = docker.from_env() + client.containers.run("illumidesk/pgweb", "foo --version") From 35c225e81143b622dffd7fc8e294d55ac38e09dd Mon Sep 17 00:00:00 2001 From: Greg Werner Date: Sat, 24 Oct 2020 21:47:48 -0400 Subject: [PATCH 5/6] fix tests Signed-off-by: Greg Werner --- .travis.yml | 1 + Dockerfile | 3 +-- README.md | 2 +- tests/test_pgweb.py | 13 +++++++++---- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 31cb359..d5e93da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ - make venv script: - set -e + - make build - make test stages: diff --git a/Dockerfile b/Dockerfile index d22a5c9..ff65b03 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,8 +23,7 @@ USER "${NB_USER}" RUN mkdir -p "/tmp/jupyter-pgweb-proxy" COPY . "/tmp/jupyter-pgweb-proxy" WORKDIR "/tmp/jupyter-pgweb-proxy" -RUN python3 -m pip install . -RUN python3 -m pip install -r requirements.txt \ +RUN python3 -m pip install . \ && jupyter serverextension enable --sys-prefix jupyter_server_proxy \ && jupyter labextension install @jupyterlab/server-proxy \ && jupyter lab build diff --git a/README.md b/README.md index ca1ca83..6229c7c 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ This test requires you to have a database instance available as a public endpoin make dev ``` -1. Open your browser: http://localhost:8889 +1. Open your browser: `http://localhost:8889` 1. Click the `pgweb` item from the `New` dropdown in `Jupyter Classic` or click on the green `pgweb` icon in the Notebooks section in `Jupyter Lab`. 1. Connect with the `Scheme` or `Standard` option. diff --git a/tests/test_pgweb.py b/tests/test_pgweb.py index c5cfbc3..25bf955 100644 --- a/tests/test_pgweb.py +++ b/tests/test_pgweb.py @@ -1,4 +1,5 @@ import os +import subprocess import docker from docker.errors import ContainerError @@ -31,10 +32,14 @@ def test_pgweb_version(executable, version_output): output_decoded = output.split(" ") assert output_decoded[0:2] == version_output LOGGER.info(f"Output from command: {output_decoded[0:3]}") - + def test_invalid_cmd(): """Ensure that an invalid command returns a docker.errors.ContainerError""" - with pytest.raises(ContainerError): - LOGGER.info("Test an invalid command ...") - f = os.popen("foo --version") + LOGGER.info("Test an invalid command ...") + f = os.popen(f'foo --version') + output = f.read() + output_decoded = output.split(" ") + assert output_decoded[0:1] != "pgweb" + LOGGER.info(f"Output from command: {output_decoded[0:3]}") + From 7fd160c7dc63782f4b3a9e10c76b5c018eed2276 Mon Sep 17 00:00:00 2001 From: Greg Werner Date: Sat, 24 Oct 2020 22:28:31 -0400 Subject: [PATCH 6/6] fix makefile Signed-off-by: Greg Werner --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6e28829..2d8f537 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ help: @grep -E '^[a-zA-Z0-9_%/-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' build: ## build the latest image for a stack - ${VENV_BIN}/jupyter-repo2docker --no-run --user-id 1000 --user-name jovyan --image-name $(OWNER)/pgweb:$(TAG) . + @docker build -t illumidesk/pgweb:latest . @echo -n "Built image size: " @docker images $(OWNER)/pgweb:$(TAG) --format "{{.Size}}"