-
Notifications
You must be signed in to change notification settings - Fork 11
Add Docker production setup #98
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,26 @@ | ||
| .git | ||
| .github | ||
| .venv | ||
| .mypy_cache | ||
| .pytest_cache | ||
| .ruff_cache | ||
| __pycache__ | ||
| *.egg-info | ||
| *.pyc | ||
|
|
||
| # Rust/DuckDB extension builds (not needed for Python image) | ||
| sidemantic-rs/ | ||
| sidemantic-duckdb/ | ||
|
|
||
| # Docs and examples not needed at runtime | ||
| docs/ | ||
| examples/superset_demo/ | ||
| examples/rill_demo/ | ||
| examples/cube_demo/ | ||
|
|
||
| # Dev/test artifacts | ||
| Dockerfile.test | ||
| docker-compose.yml | ||
| *.md | ||
| !README.md | ||
| .context/ |
This file contains hidden or 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,64 @@ | ||
| name: Docker | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: | ||
| - 'Dockerfile' | ||
| - 'docker-entrypoint.sh' | ||
| - '.dockerignore' | ||
| - 'sidemantic/**' | ||
| - 'pyproject.toml' | ||
| pull_request: | ||
| paths: | ||
| - 'Dockerfile' | ||
| - 'docker-entrypoint.sh' | ||
| - '.dockerignore' | ||
| - 'sidemantic/**' | ||
| - 'pyproject.toml' | ||
|
|
||
| jobs: | ||
| docker: | ||
| name: Docker build and test | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Build image | ||
| run: docker build -t sidemantic . | ||
|
|
||
| - name: Start server (demo mode) | ||
| run: | | ||
| docker run -d --name sidemantic-test -p 5433:5433 sidemantic --demo | ||
| for i in $(seq 1 30); do | ||
| if docker logs sidemantic-test 2>&1 | grep -q "Listening on"; then | ||
| echo "Server ready" | ||
| break | ||
| fi | ||
| echo "Waiting for server... ($i/30)" | ||
| sleep 1 | ||
| done | ||
|
|
||
| - name: Verify server logs | ||
| run: docker logs sidemantic-test 2>&1 | ||
|
|
||
| - name: Install psql | ||
| run: sudo apt-get update && sudo apt-get install -y postgresql-client | ||
|
|
||
| - name: Test connection | ||
| run: PGPASSWORD=any psql -h localhost -p 5433 -U any -d sidemantic -c "SELECT 1 AS test" | ||
|
|
||
| - name: Test metric aggregation (products) | ||
| run: | | ||
| PGPASSWORD=any psql -h localhost -p 5433 -U any -d sidemantic -c \ | ||
| "SELECT category, product_count, avg_price, total_catalog_value FROM semantic_layer.products GROUP BY category ORDER BY category" | ||
|
|
||
| - name: Test metric aggregation (customers) | ||
| run: | | ||
| PGPASSWORD=any psql -h localhost -p 5433 -U any -d sidemantic -c \ | ||
| "SELECT region, customer_count FROM semantic_layer.customers GROUP BY region ORDER BY region" | ||
|
|
||
| - name: Stop server | ||
| if: always() | ||
| run: docker stop sidemantic-test || true |
This file contains hidden or 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,41 @@ | ||
| FROM python:3.12-slim AS builder | ||
|
|
||
| # Install build deps for riffq (Rust/maturin) and other native extensions | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| build-essential \ | ||
| cmake \ | ||
| pkg-config \ | ||
| libssl-dev \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY pyproject.toml README.md LICENSE ./ | ||
| COPY sidemantic/ sidemantic/ | ||
| COPY examples/ examples/ | ||
|
|
||
| RUN uv pip install --system --no-cache ".[serve,mcp,all-databases]" | ||
|
|
||
| # --- Runtime stage (no build tools) --- | ||
| FROM python:3.12-slim | ||
|
|
||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv | ||
|
|
||
| # Copy installed packages from builder | ||
| COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages | ||
| COPY --from=builder /usr/local/bin/sidemantic /usr/local/bin/sidemantic | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY docker-entrypoint.sh /docker-entrypoint.sh | ||
| RUN chmod +x /docker-entrypoint.sh | ||
|
|
||
| RUN mkdir -p /app/models | ||
| WORKDIR /app/models | ||
|
|
||
| EXPOSE 5433 | ||
|
|
||
| ENTRYPOINT ["/docker-entrypoint.sh"] | ||
| # Mode is controlled by SIDEMANTIC_MODE env var (serve, mcp, both) |
This file contains hidden or 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 hidden or 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,46 @@ | ||
| #!/bin/sh | ||
| set -e | ||
|
|
||
| # SIDEMANTIC_MODE: "serve" (default), "mcp", or "both" | ||
| MODE="${SIDEMANTIC_MODE:-serve}" | ||
|
|
||
| # Build shared args from environment variables | ||
| ARGS="" | ||
| if [ -n "$SIDEMANTIC_CONNECTION" ]; then | ||
| ARGS="$ARGS --connection $SIDEMANTIC_CONNECTION" | ||
| fi | ||
| if [ -n "$SIDEMANTIC_DB" ]; then | ||
| ARGS="$ARGS --db $SIDEMANTIC_DB" | ||
| fi | ||
|
|
||
| # Serve-specific args | ||
| SERVE_ARGS="" | ||
| if [ -n "$SIDEMANTIC_USERNAME" ]; then | ||
| SERVE_ARGS="$SERVE_ARGS --username $SIDEMANTIC_USERNAME" | ||
| fi | ||
| if [ -n "$SIDEMANTIC_PASSWORD" ]; then | ||
| SERVE_ARGS="$SERVE_ARGS --password $SIDEMANTIC_PASSWORD" | ||
| fi | ||
| if [ -n "$SIDEMANTIC_PORT" ]; then | ||
| SERVE_ARGS="$SERVE_ARGS --port $SIDEMANTIC_PORT" | ||
| fi | ||
|
|
||
| case "$MODE" in | ||
| serve) | ||
| exec sidemantic serve --host 0.0.0.0 $ARGS $SERVE_ARGS "$@" | ||
| ;; | ||
| mcp) | ||
| exec sidemantic mcp-serve $ARGS "$@" | ||
| ;; | ||
| both) | ||
| # Start PG server in background, MCP on stdio in foreground | ||
| sidemantic serve --host 0.0.0.0 $ARGS $SERVE_ARGS & | ||
| SERVE_PID=$! | ||
| trap "kill $SERVE_PID 2>/dev/null" EXIT | ||
| exec sidemantic mcp-serve $ARGS "$@" | ||
| ;; | ||
| *) | ||
| echo "Unknown SIDEMANTIC_MODE: $MODE (use serve, mcp, or both)" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docker-entrypoint.shadds--connectionto the sharedARGSlist and then passes that list tosidemantic mcp-serveinmcp/bothmodes, butmcp_serveonly acceptsdirectory,--db, and--demo(sidemantic/cli.py,mcp_servesignature). In any container run whereSIDEMANTIC_CONNECTIONis set, these modes fail during CLI parsing with an unknown-option error instead of starting MCP, so the documented environment-variable flow is broken for MCP (and forboth, MCP exits and takes down the background PG process).Useful? React with 👍 / 👎.