Major overhaul of the Dockerfile
Switched from Ubuntu to debian:stretch because stretch has more recent versions of our binary packages and starts smaller. In particular, stretch has both pillow==2.9.0 and reportlab==3.2.0 available as system packages which saves the considerable hassle of install a toolchain. Instead, a pyvenv is set up with access to system's site-packages (note: needs two steps), making the binary-dependent packages available. Then the remaining packages are installed into the pyvenv with --no-cache-dir to avoid saving files. And there we are. Image is still very large (>500 MB), but programs like reportlab require font rendering capabilities so they pull in large portions of the Linux graphics stack. Not much will shrink that.
This commit is contained in:
+15
-30
@@ -1,7 +1,7 @@
|
||||
# OCRmyPDF
|
||||
#
|
||||
# VERSION 3.0.0
|
||||
FROM ubuntu:14.04
|
||||
FROM debian:stretch
|
||||
MAINTAINER James R. Barlow <jim@purplerock.ca>
|
||||
|
||||
# Add unprivileged user
|
||||
@@ -9,13 +9,8 @@ RUN useradd docker \
|
||||
&& mkdir /home/docker \
|
||||
&& chown docker:docker /home/docker
|
||||
|
||||
# Update system
|
||||
# Update system and install our dependencies
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
bc \
|
||||
curl \
|
||||
wget \
|
||||
zlib1g-dev \
|
||||
libjpeg-dev \
|
||||
ghostscript \
|
||||
tesseract-ocr \
|
||||
tesseract-ocr-deu tesseract-ocr-spa tesseract-ocr-eng tesseract-ocr-fra \
|
||||
@@ -24,39 +19,29 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
poppler-utils \
|
||||
python3 \
|
||||
python3-pip \
|
||||
python3-pytest \
|
||||
python3-dev \
|
||||
gcc
|
||||
python3-venv \
|
||||
python3-reportlab \
|
||||
python3-pil
|
||||
|
||||
|
||||
# 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
|
||||
# http://www.thefourtheye.in/2014/12/Python-venv-problem-with-ensurepip-in-Ubuntu.html
|
||||
|
||||
RUN python3 -m venv appenv --without-pip
|
||||
RUN . /appenv/bin/activate; \
|
||||
wget -O - -o /dev/null https://bootstrap.pypa.io/get-pip.py | python
|
||||
|
||||
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
|
||||
# Set up a Python virtualenv and take all of the system packages, so we can
|
||||
# rely on the platform packages rather than importing GCC and compiling them
|
||||
RUN pyvenv /appenv \
|
||||
&& pyvenv --system-site-packages /appenv
|
||||
|
||||
COPY . /application/
|
||||
|
||||
# Install application using our built wheels
|
||||
# Install application and dependencies
|
||||
# In this arrangement Pillow and reportlab will be provided by the system
|
||||
RUN . /appenv/bin/activate; \
|
||||
pip install --no-index --find-links=/wheelhouse /application \
|
||||
&& pip install --no-index --find-links=/wheelhouse -r /application/test_requirements.txt
|
||||
pip install --upgrade pip \
|
||||
&& pip install --no-cache-dir /application \
|
||||
&& pip install --no-cache-dir -r /application/test_requirements.txt
|
||||
|
||||
USER docker
|
||||
WORKDIR /home/docker
|
||||
|
||||
ENV DEFAULT_RUFFUS_HISTORY_FILE=/tmp/.{basename}.ruffus_history.sqlite
|
||||
ENV OCRMYPDF_TEST_OUTPUT=/tmp/test-output
|
||||
|
||||
# Must use array form of ENTRYPOINT
|
||||
# Non-array form does not append other arguments, because that is "intuitive"
|
||||
|
||||
@@ -158,7 +158,7 @@ if command.startswith('install') or \
|
||||
)
|
||||
check_external_program(
|
||||
program='unpaper',
|
||||
need_version='6.1',
|
||||
need_version='0.4.2',
|
||||
package='unpaper',
|
||||
optional=True
|
||||
)
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
img2pdf>=0.1.5
|
||||
pytest>=2.7.2
|
||||
pytest>=2.7.2
|
||||
+3
-2
@@ -7,7 +7,6 @@ import os
|
||||
import shutil
|
||||
from contextlib import suppress
|
||||
import sys
|
||||
from unittest.mock import patch, create_autospec
|
||||
import pytest
|
||||
from ocrmypdf.pageinfo import pdf_get_all_pageinfo
|
||||
import PyPDF2 as pypdf
|
||||
@@ -22,7 +21,9 @@ TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
|
||||
PROJECT_ROOT = os.path.dirname(TESTS_ROOT)
|
||||
OCRMYPDF = os.path.join(PROJECT_ROOT, 'OCRmyPDF.sh')
|
||||
TEST_RESOURCES = os.path.join(PROJECT_ROOT, 'tests', 'resources')
|
||||
TEST_OUTPUT = os.path.join(PROJECT_ROOT, 'tests', 'output')
|
||||
TEST_OUTPUT = os.environ.get(
|
||||
'OCRMYPDF_TEST_OUTPUT',
|
||||
default=os.path.join(PROJECT_ROOT, 'tests', 'output'))
|
||||
TEST_BINARY_PATH = os.path.join(TEST_OUTPUT, 'fakebin')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user