Spaces:
Paused
Paused
metadata
title: oTree Production Server
emoji: π―
colorFrom: blue
colorTo: purple
sdk: docker
sdk_version: 0.0.1
app_file: Dockerfile
pinned: false
oTree HF Production Template
This directory packages the IBE public policy oTree demos for deployment on a Hugging Face Space using the Docker runtime. It was cloned from otree-projects/ibe-pp and augmented with container and deployment assets.
Directory Overview
Dockerfileβ builds the production image expected by Hugging Face Spaces.docker-entrypoint.shβ runtime bootstrap that ensures SQLite initialization, collects static files, and launches the ASGI server.requirements.txtβ locked dependencies for the production image..dockerignoreβ keeps dev artifacts (db.sqlite3, logs, caches) out of the build context.settings.py, apps/, tests/ β unchanged oTree project source.
Deploying to a Hugging Face Space
Create the Space
- Runtime:
Docker. - Visibility: choose
PrivateorPublicper your needs.
- Runtime:
Add secrets / environment variables (Settings β Repository secrets):
Key Purpose Example OTREE_ADMIN_PASSWORDProtects the oTree admin interface set-a-unique-passwordOTREE_AUTH_LEVELOptional access control ( STUDY,DEMO,BASELINE)STUDYOTREE_DATABASE_URLOverride DB (defaults to SQLite under /data)postgres://user:pass@host:5432/dbnameAdditional variables such as
SENTRY_DSN,OTREE_SECRET_KEY, or mail settings can also be defined here.Populate the repository
# from repository root cd otree-projects/hf-prod-ibe-pp git init # if pushing standalone git add . git commit -m "Initial oTree HF deployment" git remote add origin https://huggingface.co/spaces/<org>/<space-name> git push origin mainSpace build & launch
- Hugging Face automatically builds the Docker image.
- The container starts
/app/entrypoint.sh, which:- Creates the SQLite database (default:
/tmp/otree.sqlite3) ifOTREE_DATABASE_URL/DATABASE_URLpoints to SQLite. - Launches
otree prodserver1of2 0.0.0.0:$PORT(HF sets$PORT).
- Creates the SQLite database (default:
- The app becomes available at
https://<org>-<space-name>.hf.space/.
Local Verification
To build and run the same image locally before pushing:
cd otree-projects/hf-prod-ibe-pp
DOCKER_BUILDKIT=1 docker build -t ibe-pp-hf .
docker run --rm -p 8000:8000 \
-e OTREE_ADMIN_PASSWORD=changeme \
-e OTREE_AUTH_LEVEL=STUDY \
ibe-pp-hf
# open http://localhost:8000/
For persistence, mount a volume:
docker run --rm -p 8000:8000 \
-v $(pwd)/data:/data \
-e OTREE_ADMIN_PASSWORD=changeme \
ibe-pp-hf
Notes & Customization
- Database: The default fallback
sqlite:////tmp/otree.sqlite3is ephemeral. Configure an external Postgres database (e.g., Neon, Supabase) viaOTREE_DATABASE_URL(orDATABASE_URL) for any session data you need to persist across restarts. - Static assets: For lightweight deployments the built-in static files under
_static/are served directly by oTree; add an external asset pipeline only if required. - Session configs: Update
settings.pyor add new apps as usual; rebuild the Space to apply changes. - Logging / monitoring: Set
SENTRY_DSN,OTREE_PRODUCTION=1(already set), or add custom logging handlers as desired.
Once pushed, you can administer the server via https://<space-url>/otree/admin using the password stored in OTREE_ADMIN_PASSWORD.