Skip to content

Commit

Permalink
refactor: restructure Dockerfile for multi-stage builds
Browse files Browse the repository at this point in the history
Reorganize the Dockerfile to implement multi-stage builds for 
improved efficiency. Introduce a dedicated stage for ffmpeg to 
reduce image size and separate concerns. Set up a development 
stage for installing Python packages and a production stage 
to copy necessary binaries and dependencies. This enhances 
build performance and maintains a cleaner final image.
  • Loading branch information
l-lumin authored and gitbutler-client committed Dec 21, 2024
1 parent f94d099 commit d873c30
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
FROM python:3.13-slim-bullseye
# ffmpeg
FROM jrottenberg/ffmpeg:4.1-scratch AS ffmpeg

USER root
# Developoment stage
FROM python:3.13-bullseye AS development
# Copy ffmpeg binaries
COPY --from=ffmpeg / /

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
# Install Python package
RUN pip install --no-cache-dir markitdown

# Runtime dependency
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*

RUN pip install markitdown
# Production stage
FROM python:3.13-slim-bullseye AS production
# Copy ffmpeg binaries
COPY --from=ffmpeg / /

# Default USERID and GROUPID
ARG USERID=10000
ARG GROUPID=10000

# Set up user
RUN groupadd -g $GROUPID appgroup && \
useradd -m -u $USERID -g appgroup appuser

USER $USERID:$GROUPID

ENTRYPOINT [ "markitdown" ]
# Copy installed dependencies from development stage
COPY --from=development /usr/local /usr/local

# Entrypoint
ENTRYPOINT ["markitdown"]

0 comments on commit d873c30

Please sign in to comment.