From 16976f9220906cb385f5b51f13fcd0b35c6e7035 Mon Sep 17 00:00:00 2001 From: Jeremy Fee <jmfee@usgs.gov> Date: Mon, 1 Feb 2021 14:01:55 -0700 Subject: [PATCH] Change how docker python dependencies are installed (into system environment) --- Dockerfile | 26 ++++++++++++-------------- Pipfile | 1 + Pipfile.lock | 10 +++++++++- docker-entrypoint.sh | 6 ++---- docs/install_docker.md | 5 ----- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index d78f30c1c..17ee426a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,24 +13,22 @@ ENV GIT_BRANCH_NAME=${GIT_BRANCH_NAME} \ WEBSERVICE=${WEBSERVICE} -RUN useradd \ - -c 'Docker image user' \ - -m \ - -r \ - -s /sbin/nologin \ - geomag_user \ - && mkdir -p /data \ - && chown -R geomag_user:geomag_user /data +# install packages into system python, when Pipfile changes +COPY Pipfile Pipfile.lock /geomag-algorithms/ +RUN cd /geomag-algorithms \ + && pipenv install --dev --pre --system -USER geomag_user +# install rest of library as editable +COPY . /geomag-algorithms +RUN cd /geomag-algorithms \ + && pip install -e . \ + # add data directory owned by usgs-user + && mkdir -p /data \ + && chown -R usgs-user:usgs-user /data -# install dependencies via pipenv +USER usgs-user WORKDIR /data -COPY Pipfile /data/ -RUN pipenv --site-packages install --dev --skip-lock -# copy library (ignores set in .dockerignore) -COPY . /geomag-algorithms # entrypoint needs double quotes ENTRYPOINT [ "/geomag-algorithms/docker-entrypoint.sh" ] diff --git a/Pipfile b/Pipfile index 074a95e9e..c3750f0e9 100644 --- a/Pipfile +++ b/Pipfile @@ -29,6 +29,7 @@ openpyxl = "*" pydantic = "*" sqlalchemy = "*" sqlalchemy-utc = "*" +typer = "*" typing = "*" typing-extensions = "*" uvicorn = {extras=["standard"], version="*"} diff --git a/Pipfile.lock b/Pipfile.lock index ecc8b256a..365431ebc 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b6b3f6007a0217e08bc3edc72ea081fac5139bbe48974af84faac7d7993b2ef5" + "sha256": "65a11d9d155cdecca0ed4d14ceead8df52ac6adff775f439b151f6ff7a1063ee" }, "pipfile-spec": 6, "requires": {}, @@ -727,6 +727,14 @@ "markers": "python_version >= '3.6'", "version": "==0.13.6" }, + "typer": { + "hashes": [ + "sha256:5455d750122cff96745b0dec87368f56d023725a7ebc9d2e54dd23dc86816303", + "sha256:ba58b920ce851b12a2d790143009fa00ac1d05b3ff3257061ff69dbdfc3d161b" + ], + "index": "pypi", + "version": "==0.3.2" + }, "typing": { "hashes": [ "sha256:1187fb9c82fd670d10aa07bbb6cfcfe4bdda42d6fab8d5134f04e8c4d0b71cc9", diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 665e82ecd..7c05ad6ed 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,18 +1,16 @@ #! /bin/bash + # Environment variable to determine whether to start webservice export WEBSERVICE=${WEBSERVICE:-false} -# add geomagio to notebook path -export PYTHONPATH=/geomag-algorithms - if [ "${WEBSERVICE}" = "false" ]; then # run arguments as command, or bash prompt if no arguments exec "${@:-/bin/bash}" else # run gunicorn server for web service - exec pipenv run gunicorn \ + exec gunicorn \ --access-logfile - \ --bind 0.0.0.0:8000 \ --threads 2 \ diff --git a/docs/install_docker.md b/docs/install_docker.md index 02beede91..f87b9193f 100644 --- a/docs/install_docker.md +++ b/docs/install_docker.md @@ -25,13 +25,8 @@ The following command creates and starts a container in the background. - Run an interactive python prompt - docker exec -it geomagio python -- Use the Jupyter Notebook server - - Check the output for a URL like this, that can be opened in a web browser: `http://127.0.0.1:8000/?token=...` - - Use the `geomag.py` command line interface docker exec -it geomagio geomag.py \ -- GitLab