-
Notifications
You must be signed in to change notification settings - Fork 21
Added dockerfile improvements #126
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,21 +4,31 @@ FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder | |
| # Set environment variables for build | ||
| ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
| PYTHONUNBUFFERED=1 \ | ||
| PIP_NO_CACHE_DIR=1 | ||
| PIP_NO_CACHE_DIR=1 \ | ||
| UV_COMPILE_BYTECODE=1 \ | ||
| UV_LINK_MODE=copy | ||
|
|
||
| # Install the project into `/app` | ||
| WORKDIR /app | ||
|
|
||
| ADD . /app | ||
| # Copy only dependency files first (better caching) | ||
| COPY pyproject.toml uv.lock ./ | ||
| COPY version.py ./ | ||
| COPY README.md ./ | ||
|
|
||
| # Create a virtual environment and install dependencies | ||
| RUN python -m venv /app/.venv | ||
| ENV PATH="/app/.venv/bin:$PATH" | ||
| RUN uv sync --no-cache-dir --no-dev --python /app/.venv/bin/python | ||
|
|
||
| # Copy the rest of the application | ||
| COPY . /app | ||
|
|
||
| FROM python:3.12-slim-bookworm AS runtime | ||
|
|
||
| RUN groupadd -r appuser && useradd -r -g appuser -m -d /home/appuser appuser | ||
| # Create non-root user with specific UID/GID for better security | ||
| RUN groupadd -r -g 1001 appuser && \ | ||
| useradd -r -g appuser -u 1001 -m -d /home/appuser appuser | ||
|
|
||
| WORKDIR /appuser | ||
|
|
||
|
|
@@ -27,11 +37,18 @@ COPY --from=builder --chown=appuser:appuser /app /appuser | |
| # Set the PATH to use the virtual environment | ||
| ENV PATH="/appuser/.venv/bin:$PATH" | ||
|
|
||
| ENV MCP_TRANSPORT="stdio" | ||
| ENV MCP_HOST="0.0.0.0" | ||
| ENV MCP_PORT="8000" | ||
| ENV MCP_PATH="/" | ||
| # Environment variables with defaults | ||
| ENV MCP_TRANSPORT="stdio" \ | ||
| MCP_HOST="0.0.0.0" \ | ||
| MCP_PORT="8000" \ | ||
| MCP_PATH="/" | ||
|
|
||
| # Simple health check for HTTP transports (without external dependencies) | ||
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can wait for this PR merge so that we have a dedicated health endpoint to check
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @arpit-at can we merge this since there are no dependencies yet and later I will replcae with ealth check endpoint?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Hk669 once the health check PR is merged, I will make this endpoint |
||
| CMD if [ "$MCP_TRANSPORT" = "sse" ] || [ "$MCP_TRANSPORT" = "streamable-http" ]; then \ | ||
| python -c "import urllib.request; urllib.request.urlopen('http://localhost:$MCP_PORT$MCP_PATH', timeout=5)" || exit 1; \ | ||
| else exit 0; fi | ||
|
|
||
| USER appuser | ||
|
|
||
| ENTRYPOINT exec python server.py --transport "$MCP_TRANSPORT" --host "$MCP_HOST" --port "$MCP_PORT" --path "$MCP_PATH" | ||
| ENTRYPOINT ["sh", "-c", "exec python server.py --transport \"$MCP_TRANSPORT\" --host \"$MCP_HOST\" --port \"$MCP_PORT\" --path \"$MCP_PATH\""] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this change even required? i think we have simpler version already!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check docker docs: This is the preferred way. If we do not change this then
Advantages: |
||
Uh oh!
There was an error while loading. Please reload this page.