From 8e2d690cb04a57d3e70c6e91d29a5a0b7fcd19a2 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Wed, 19 Aug 2015 13:43:32 -0700 Subject: [PATCH] Rework Dockerfile, setup.py to work with wheels for better cache use --- Dockerfile | 19 +++++++++++++------ requirements.txt | 4 ++++ setup.py | 15 +++++---------- test_requirements.txt | 2 ++ 4 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 requirements.txt create mode 100644 test_requirements.txt diff --git a/Dockerfile b/Dockerfile index 2a710d14..3b7282ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ RUN useradd docker \ RUN apt-get update && apt-get install -y --no-install-recommends \ bc \ curl \ + wget \ zlib1g-dev \ libjpeg-dev \ ghostscript \ @@ -23,13 +24,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ poppler-utils \ python3 \ python3-pip \ - python3-pil \ python3-pytest \ - python3-reportlab + python3-dev \ + gcc -RUN apt-get install -y wget - # Ubuntu 14.04's ensurepip is broken, so it cannot create py3 virtual envs # Use elaborate workaround: create a venv without pip, activate that environment, # download a script to install pip into the environment @@ -39,12 +38,20 @@ RUN python3 -m venv appenv --without-pip RUN . /appenv/bin/activate; \ wget -O - -o /dev/null https://bootstrap.pypa.io/get-pip.py | python -RUN apt-get install -y gcc python3-dev +COPY ./*requirements.txt /application/ + +# Build wheels separately so build is cached by Docker +RUN . /appenv/bin/activate; \ + pip install wheel \ + && pip wheel --wheel-dir=/wheelhouse -r /application/requirements.txt \ + && pip wheel --wheel-dir=/wheelhouse -r /application/test_requirements.txt COPY . /application/ +# Install application using our built wheels RUN . /appenv/bin/activate; \ - pip install /application/. + pip install --no-index --find-links=/wheelhouse /application \ + && pip install --no-index --find-links=/wheelhouse -r /application/test_requirements.txt USER docker WORKDIR /home/docker diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..7cf67a5b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +ruffus>=2.6.3 +Pillow>=2.4.0 +reportlab>=3.1.44 +PyPDF2>=1.25.1 \ No newline at end of file diff --git a/setup.py b/setup.py index cf8086d9..b9b4a452 100644 --- a/setup.py +++ b/setup.py @@ -174,6 +174,9 @@ if 'upload' in sys.argv[1:]: print('Use twine to upload the package - setup.py upload is insecure') sys.exit(1) +install_requires = open('requirements.txt').read().splitlines() +tests_require = open('test_requirements.txt').read().splitlines() + setup( name='ocrmypdf', version='3.0rc5', # also update: release notes, main.py @@ -200,16 +203,8 @@ setup( "Topic :: Text Processing :: Indexing", "Topic :: Text Processing :: Linguistic", ], - install_requires=[ - 'ruffus>=2.6.3', - 'Pillow>=2.4.0', - 'reportlab>=3.1.44', - 'PyPDF2>=1.25.1' - ], - tests_require=[ - 'img2pdf>=0.1.5', - 'pytest>=2.7.2' - ], + install_requires=install_requires, + tests_require=tests_require, entry_points={ 'console_scripts': [ 'ocrmypdf = ocrmypdf.main:run_pipeline' diff --git a/test_requirements.txt b/test_requirements.txt new file mode 100644 index 00000000..481a4778 --- /dev/null +++ b/test_requirements.txt @@ -0,0 +1,2 @@ +img2pdf>=0.1.5 +pytest>=2.7.2