-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docker): restructure Dockerfile for multi-stage build
Update the Dockerfile to implement a multi-stage build process. Introduce a dedicated FFmpeg stage and separate development, build, and production stages to optimize image size and improve build efficiency. Add necessary dependencies and configure the environment for better performance. Update the .dockerignore to exclude sensitive files and unnecessary directories.
- Loading branch information
1 parent
125e206
commit 8e3aaff
Showing
2 changed files
with
60 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
* | ||
**/coverage | ||
**/.env | ||
**/.aws | ||
**/.ssh | ||
Dockerfile | ||
docker-compose.yml | ||
**/.DS_Store | ||
**/venv | ||
**/env |
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,23 +1,58 @@ | ||
FROM python:3.13-slim-bullseye | ||
# FFmpeg stage | ||
FROM jrottenberg/ffmpeg:4.1-scratch AS ffmpeg | ||
|
||
USER root | ||
# Development stage | ||
FROM python:3.13-bullseye AS development | ||
|
||
ARG INSTALL_GIT=false | ||
RUN if [ "$INSTALL_GIT" = "true" ]; then \ | ||
apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*; \ | ||
fi | ||
COPY --from=ffmpeg / / | ||
|
||
# Runtime dependency | ||
RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
ffmpeg \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
ENV PYTHONUNBUFFERED=1 \ | ||
PYTHONDONTWRITEBYTECODE=1 | ||
|
||
RUN pip install markitdown | ||
# Install build dependencies | ||
RUN apt-get update && apt install -y --no-install-recommends \ | ||
build-essential \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Default USERID and GROUPID | ||
ARG USERID=10000 | ||
ARG GROUPID=10000 | ||
RUN pip install --no-cache-dir hatch | ||
|
||
WORKDIR /app | ||
COPY . /app/ | ||
|
||
# Build stage | ||
FROM python:3.13-bullseye AS build | ||
|
||
# Install build dependencies | ||
RUN apt-get update && apt install -y --no-install-recommends \ | ||
build-essential \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN pip install --no-cache-dir hatch | ||
|
||
WORKDIR /app | ||
|
||
COPY pyproject.toml /app/ | ||
COPY . /app/ | ||
|
||
USER $USERID:$GROUPID | ||
RUN hatch build | ||
|
||
# Production stage | ||
FROM python:3.13-slim-bullseye AS production | ||
|
||
# Copy ffmpeg binaries | ||
COPY --from=ffmpeg / / | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=build /app/dist /tmp/dist | ||
|
||
RUN pip install --no-cache-dir /tmp/dist/markitdown-*.whl | ||
|
||
# Default USERID and GROUPID | ||
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app | ||
USER appuser | ||
|
||
ENTRYPOINT [ "markitdown" ] | ||
# Entrypoint | ||
ENTRYPOINT ["markitdown"] |