Skip to content

Instantly share code, notes, and snippets.

@danielballan
Last active February 2, 2023 16:22
Show Gist options
  • Save danielballan/ebee67b3169e5c9e30a6230fc2ef21e1 to your computer and use it in GitHub Desktop.
Save danielballan/ebee67b3169e5c9e30a6230fc2ef21e1 to your computer and use it in GitHub Desktop.

Experimental Databroker Sandbox

  1. Install podman. https://podman.io/getting-started/installation

  2. Install podman-compose:

    pip install podman-compose
  3. Clone or copy docker-compose.yml and config.yml from this gist into a directory.

  4. From inside that directory, start podman-compose.

    TILED_SINGLE_USER_API_KEY=secret podman-compose up

    This should start MongoDB and a Tiled server. The server is ready when you see

    INFO:     Started server process [1]
    INFO:     Waiting for application startup.
    OBJECT CACHE: Will use up to 10_095_076_147 bytes (15% of total physical RAM)
    INFO:     Application startup complete.
    INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
    

    Later, when finished, stop it like this. This must be run to clean up before up is run again.

    podman-compose down
    
  5. Connect from the client.

    pip install --upgrade tiled[client] ipython
    ipython
    In [1]: from tiled.client import from_uri, show_logs
    
    In [2]: c = from_uri("http://localhost:8000?api_key=secret")
    
    In [3]: c
    Out[3]: <Node {}>
    
    In [4]: c.write_array([1,2,3], metadata={"color": "yellow"})
    Out[4]: <ArrayClient shape=(3,) chunks=((3,),) dtype=int64>
    
    In [5]: c
    Out[5]: <Node {'9f13ebd6-a9ad-48f8-a79b-dddcdacbc03c'}>

The data is stored across a MongoDB database and files. It is persisted in the directories ./db_data and ./file_data, created in the current directory when podman-compose up is first run. To clear the data, delete those directories.

# This is intended to be used with docker-compose.yml.
trees:
- path: /
tree: databroker.experimental.server_ext:MongoAdapter.from_uri
args:
uri: mongodb://mongo:27017/example_database
directory: /file_data
version: "3.7"
services:
tiled:
image: ghcr.io/bluesky/databroker:v2.0.0b14
volumes:
- type: bind
source: ./config.yml
target: /deploy/config.yml
- type: bind
source: ./file_data
target: /file_data
environment:
- TILED_SINGLE_USER_API_KEY=$TILED_SINGLE_USER_API_KEY
ports:
- 8000:8000
networks:
- backend
depends_on:
- mongo
mongo:
image: docker.io/mongo:6.0.4
volumes:
- type: bind
source: ./db_data
target: /data/db
networks:
- backend
networks:
backend: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment