Skip to content

Commit edb847c

Browse files
authored
adding Dockerfile (#359)
1 parent a00c6fe commit edb847c

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed

Dockerfile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# syntax=docker/dockerfile:experimental
2+
3+
FROM centos:centos7.9.2009
4+
5+
ARG PIP_VERSION
6+
ARG UNSTRUCTURED
7+
8+
RUN yum -y update && \
9+
yum -y install poppler-utils xz-devel which
10+
11+
# Note(austin) Get a recent tesseract from this repo
12+
# See https://tesseract-ocr.github.io/tessdoc/Installation.html
13+
# PDF and images:
14+
RUN yum-config-manager --add-repo https://download.opensuse.org/repositories/home:/Alexander_Pozdnyakov/CentOS_7/ && \
15+
rpm --import https://build.opensuse.org/projects/home:Alexander_Pozdnyakov/public_key && \
16+
yum -y update && \
17+
yum -y install tesseract
18+
19+
# Note(yuming): Install gcc & g++ ≥ 5.4 for Detectron2 requirement
20+
RUN yum -y update
21+
RUN yum -y install centos-release-scl
22+
RUN yum -y install devtoolset-7-gcc*
23+
SHELL [ "/usr/bin/scl", "enable", "devtoolset-7"]
24+
25+
RUN yum -y update && \
26+
# MS Office docs:
27+
yum -y install libreoffice && \
28+
yum -y install openssl-devel bzip2-devel libffi-devel make git sqlite-devel && \
29+
curl -O https://www.python.org/ftp/python/3.8.15/Python-3.8.15.tgz && tar -xzf Python-3.8.15.tgz && \
30+
cd Python-3.8.15/ && ./configure --enable-optimizations && make altinstall && \
31+
cd .. && rm -rf Python-3.8.15* && \
32+
ln -s /usr/local/bin/python3.8 /usr/local/bin/python3
33+
34+
# create a home directory
35+
ENV HOME /home/
36+
37+
WORKDIR ${HOME}
38+
RUN mkdir ${HOME}/.ssh && chmod go-rwx ${HOME}/.ssh \
39+
&& ssh-keyscan -t rsa github.com >> /home/.ssh/known_hosts
40+
41+
ENV PYTHONPATH="${PYTHONPATH}:${HOME}"
42+
ENV PATH="/home/usr/.local/bin:${PATH}"
43+
44+
COPY example-docs example-docs
45+
46+
COPY requirements/base.txt requirements-base.txt
47+
COPY requirements/huggingface.txt requirements-huggingface.txt
48+
COPY requirements/dev.txt requirements-dev.txt
49+
# PDFs and images
50+
COPY requirements/local-inference.txt requirements-local-inference.txt
51+
52+
53+
RUN python3.8 -m pip install pip==${PIP_VERSION} \
54+
&& pip install --no-cache -r requirements-base.txt \
55+
&& pip install --no-cache -r requirements-huggingface.txt \
56+
&& pip install --no-cache -r requirements-dev.txt \
57+
# PDFs and images
58+
&& pip install --no-cache -r requirements-local-inference.txt \
59+
# PDFs
60+
&& pip install --no-cache "detectron2@git+https://github.com/facebookresearch/[email protected]#egg=detectron2"
61+
62+
COPY unstructured unstructured
63+
64+
CMD ["/bin/bash"]

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,18 @@ version-sync:
178178
.PHONY: check-coverage
179179
check-coverage:
180180
coverage report --fail-under=95
181+
182+
##########
183+
# Docker #
184+
##########
185+
186+
# Docker targets are provided for convenience only and are not required in a standard development environment
187+
188+
189+
.PHONY: docker-build
190+
docker-build:
191+
PIP_VERSION=${PIP_VERSION} ./scripts/docker-build.sh
192+
193+
.PHONY: docker-start-bash
194+
docker-start-bash:
195+
docker run --platform linux/amd64 -ti --rm unstructured-dev:latest

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,32 @@ elements = partition("example-docs/layout-parser-paper.pdf")
8181
print("\n\n".join([str(el) for el in elements]))
8282
```
8383

84+
## :dizzy: Instructions for using the docker image
85+
86+
The following instructions are intended to help you get up and running using docker to interact with `unstructured`.
87+
88+
If you only plan on parsing one type of data you can speed up building the image by commenting out some
89+
of the packages/requirements necessary for other data types. See Dockerfile to know which lines are necessary
90+
for your use case.
91+
92+
See [here](https://docs.docker.com/get-docker/) if you don't already have docker installed on your machine.
93+
94+
```bash
95+
make docker-build
96+
97+
# this will drop you into a bash shell where the docker image is running
98+
make docker-start-bash
99+
100+
# this will drop you into a python console so you can run the below partition functions
101+
python3
102+
103+
>>> from unstructured.partition.pdf import partition_pdf
104+
>>> elements = partition_pdf(filename="example-docs/layout-parser-paper-fast.pdf")
105+
106+
>>> from unstructured.partition.text import partition_text
107+
>>> elements = partition_text(filename="example-docs/fake-text.txt")
108+
```
109+
84110

85111
## :coffee: Installation Instructions for Local Development
86112

scripts/docker-build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
DOCKER_BUILDKIT=1 docker buildx build --load --platform=linux/amd64 -f Dockerfile \
6+
--build-arg PIP_VERSION="$PIP_VERSION" \
7+
--progress plain \
8+
-t unstructured-dev:latest .

0 commit comments

Comments
 (0)