This example runs the sqlctx HTTP API behind a Cloudflare Worker that proxies requests into Cloudflare Containers.
- HTTPS terminates at the Worker.
- The Worker starts a sqlctx container and forwards requests to port
4400. - The container runs
SQLCTX_MODE=api. - The example image uses the demo models and seeded
demo.duckdbfrom/app/modelsin the base image.
For a real deployment, the clean shape is:
- bake your semantic models into the container image
- point sqlctx at an external database with
SQLCTX_CONNECTION - keep DuckDB files out of the container unless they are disposable, because Cloudflare container disks reset on stop
wrangler.jsonc: Cloudflare Worker and container binding configsrc/index.ts: Worker entrypoint and container proxyDockerfile: sqlctx container image used by Cloudflare, built on thesidequery/sqlctximagepackage.json: Worker dependencies and thedeployscript
- Bun
- Docker
- A Cloudflare account with Containers enabled
- Wrangler auth:
bunx wrangler whoami
docker build -t sidequery/sqlctx .
cd examples/cloudflare_containers
bun install
bunx wrangler secret put SQLCTX_API_TOKEN
bun run deployAfter deploy, query the worker URL:
curl -s https://YOUR-WORKER.workers.dev/query \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"metrics":["customers.customer_count"]}'Arrow still works through the Worker:
curl -s https://YOUR-WORKER.workers.dev/query \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Accept: application/vnd.apache.arrow.stream" \
-H "Content-Type: application/json" \
-d '{"metrics":["customers.customer_count"]}' \
> result.arrowEdit Dockerfile to bake in your models:
FROM sidequery/sqlctx:latest
ENV SQLCTX_MODE=api
ENV SQLCTX_API_PORT=4400
# Replace the demo models that ship in /app/models.
RUN rm -rf /app/models/*
COPY models/ /app/models/
WORKDIR /app/modelsThen remove SQLCTX_DB from the default container env in src/index.ts.
Then set your warehouse connection:
bunx wrangler secret put SQLCTX_CONNECTIONThe Worker passes SQLCTX_CONNECTION, SQLCTX_API_TOKEN, and SQLCTX_CORS_ORIGINS into the container at startup.
The container already supports bearer-token auth via SQLCTX_API_TOKEN.
If you want proper edge auth, put the deployed hostname behind Cloudflare Access and use service tokens or your IdP there. Keep the app bearer token as a second gate if you want defense in depth.
- Cloudflare Containers is beta.
- Cold starts are materially slower than plain Workers.
- The Worker is required. The container is not exposed directly on the public Internet.