Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker): multi-stage builds for separate development and production environments #181

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile",
"args": {
"INSTALL_GIT": "true"
}
"target": "development"
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
"features": {
"ghcr.io/devcontainers-extra/features/hatch:2": {}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"charliermarsh.ruff"
]
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
Expand All @@ -28,5 +34,5 @@
// "customizations": {},

// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
// "remoteUser": "root"
}
10 changes: 9 additions & 1 deletion .dockerignore
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
65 changes: 50 additions & 15 deletions Dockerfile
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
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*
build-essential \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN pip install markitdown
RUN pip install --no-cache-dir hatch

# Default USERID and GROUPID
ARG USERID=10000
ARG GROUPID=10000
WORKDIR /app
COPY . /app/

# Build stage
FROM python:3.13-bullseye AS build

# Install build dependencies
RUN apt-get update && apt-get 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"]