-
Notifications
You must be signed in to change notification settings - Fork 11
Add Docker setup with PG and MCP servers #99
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
Changes from 3 commits
c5ee9c2
4b0b277
83fac25
130a4e0
37dc2a6
6cbf918
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 |
|---|---|---|
| @@ -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/ |
| 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 |
| 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) |
| 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 "$@" | ||
|
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.
In Useful? React with 👍 / 👎. |
||
| ;; | ||
| 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 | ||
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.
The command expands
$ARGSand$SERVE_ARGSunquoted, so values from environment variables are subject to shell word splitting and metacharacter handling; connection strings and credentials commonly contain characters like&or spaces, which can turn into broken/misaligned CLI arguments at runtime. This can make validSIDEMANTIC_CONNECTION/auth values fail unpredictably in Docker deployments.Useful? React with 👍 / 👎.