forked from mindee/doctr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Official docker images for docTR (mindee#1322)
- Loading branch information
1 parent
19f101c
commit 69f6705
Showing
4 changed files
with
198 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages | ||
# | ||
name: Docker image on ghcr.io | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
pull_request: | ||
branches: main | ||
schedule: | ||
- cron: '0 2 29 * *' # At 02:00 on day-of-month 29 | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
# Must match version at https://www.python.org/ftp/python/ | ||
python: ["3.8.18", "3.9.18", "3.10.13"] | ||
framework: ["tf", "torch"] | ||
system: ["cpu", "gpu"] | ||
|
||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ github.repository }} | ||
tags: | | ||
# used only on schedule event | ||
type=schedule,pattern={{date 'YYYY-MM'}},prefix=${{ matrix.framework }}-py${{ matrix.python }}-${{ matrix.system }}- | ||
# used only if a tag following semver is published | ||
type=semver,pattern={{raw}},prefix=${{ matrix.framework }}-py${{ matrix.python }}-${{ matrix.system }}- | ||
- name: Build Docker image | ||
id: build | ||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | ||
with: | ||
context: . | ||
build-args: | | ||
FRAMEWORK=${{ matrix.framework }} | ||
PYTHON_VERSION=${{ matrix.python }} | ||
SYSTEM=${{ matrix.system }} | ||
DOCTR_REPO=${{ github.repository }} | ||
DOCTR_VERSION=${{ github.sha }} | ||
push: false # push only if `import doctr` works | ||
tags: ${{ steps.meta.outputs.tags }} | ||
|
||
- name: Check if `import doctr` works | ||
run: docker run ${{ steps.build.outputs.imageid }} python3 -c 'import doctr' | ||
|
||
- name: Push Docker image | ||
# Push only if the CI is not triggered by "PR on main" | ||
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' | ||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | ||
with: | ||
context: . | ||
build-args: | | ||
FRAMEWORK=${{ matrix.framework }} | ||
PYTHON_VERSION=${{ matrix.python }} | ||
SYSTEM=${{ matrix.system }} | ||
DOCTR_REPO=${{ github.repository }} | ||
DOCTR_VERSION=${{ github.sha }} | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,72 @@ | ||
# Use the TensorFlow GPU image as the base image. This image also works with CPU-only setups | ||
FROM tensorflow/tensorflow@sha256:b4676741c491bff3d0f29c38c369281792c7d5c5bfa2b1aa93e5231a8d236323 | ||
FROM ubuntu:22.04 | ||
|
||
ENV PYTHONUNBUFFERED=1 | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
ENV DOCTR_CACHE_DIR=/app/.cache | ||
ENV DEBIAN_FRONTEND=noninteractive | ||
ENV LANG=C.UTF-8 | ||
ENV PYTHONUNBUFFERED=1 | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
|
||
WORKDIR /app | ||
ARG SYSTEM=gpu | ||
|
||
COPY . . | ||
# Enroll NVIDIA GPG public key and install CUDA | ||
RUN if [ "$SYSTEM" = "gpu" ]; then \ | ||
apt-get update && \ | ||
apt-get install -y gnupg ca-certificates wget && \ | ||
# - Install Nvidia repo keys | ||
# - See: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#network-repo-installation-for-ubuntu | ||
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb && \ | ||
dpkg -i cuda-keyring_1.1-1_all.deb && \ | ||
apt-get update && apt-get install -y --no-install-recommends \ | ||
cuda-command-line-tools-11-8 \ | ||
cuda-cudart-dev-11-8 \ | ||
cuda-nvcc-11-8 \ | ||
cuda-cupti-11-8 \ | ||
cuda-nvprune-11-8 \ | ||
cuda-libraries-11-8 \ | ||
cuda-nvrtc-11-8 \ | ||
libcufft-11-8 \ | ||
libcurand-11-8 \ | ||
libcusolver-11-8 \ | ||
libcusparse-11-8 \ | ||
libcublas-11-8 \ | ||
# - CuDNN: https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#ubuntu-network-installation | ||
libcudnn8=8.6.0.163-1+cuda11.8 \ | ||
libnvinfer-plugin8=8.6.1.6-1+cuda11.8 \ | ||
libnvinfer8=8.6.1.6-1+cuda11.8; \ | ||
fi | ||
|
||
# Install necessary dependencies for video processing and GUI operations | ||
RUN apt-get update \ | ||
&& apt-get install --no-install-recommends ffmpeg libsm6 libxext6 -y \ | ||
&& apt-get autoremove -y \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
# - Other packages | ||
build-essential \ | ||
pkg-config \ | ||
curl \ | ||
wget \ | ||
software-properties-common \ | ||
unzip \ | ||
git \ | ||
# - Packages to build Python | ||
tar make gcc zlib1g-dev libffi-dev libssl-dev liblzma-dev libbz2-dev \ | ||
# - Packages for docTR | ||
libgl1-mesa-dev libsm6 libxext6 libxrender-dev libpangocairo-1.0-0 \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
fi | ||
|
||
# Install the current application with TensorFlow extras and modify permissions | ||
RUN pip install --upgrade pip setuptools wheel \ | ||
&& pip install -e .[tf] \ | ||
&& chmod -R a+w /app | ||
# Install Python | ||
ARG PYTHON_VERSION=3.10.13 | ||
|
||
RUN wget http://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz && \ | ||
tar -zxf Python-$PYTHON_VERSION.tgz && \ | ||
cd Python-$PYTHON_VERSION && \ | ||
mkdir /opt/python/ && \ | ||
./configure --prefix=/opt/python && \ | ||
make && \ | ||
make install | ||
|
||
ENV PATH=/opt/python/bin:$PATH | ||
|
||
# Install docTR | ||
ARG FRAMEWORK=tf | ||
ARG DOCTR_REPO='mindee/doctr' | ||
ARG DOCTR_VERSION=main | ||
RUN pip3 install -U pip setuptools wheel && \ | ||
pip3 install "python-doctr[$FRAMEWORK]@git+https://github.com/$DOCTR_REPO.git@$DOCTR_VERSION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters