Use Application Mode scripts
Deephaven's Application Mode allows you to initialize server state. This guide covers how to use Application Mode scripts, which run Python or Groovy code when Deephaven launches. The examples package the script in a Docker image. You can use the same app.d directory (the folder that holds your scripts and a *.app config file) with any launch that sets the deephaven.application.dir property. This guide shows the Docker setup.
Application Mode config file
Deephaven reads settings for Application Mode from a config file whose name ends in .app. Call this file the *.app file. For using Application Mode with scripts, you need to set:
typeset toscriptscriptTypeset topythonorgroovy, matching the server's console languageidset to an identifier of your choicenameset to an application name of your choicefile_Nset to the path of one script, whereNis an integer such as0or1. Scripts run in ascending numeric order.
enabled is optional and defaults to true. Set enabled=false to skip an application without deleting its file.
A complete example is in Packaging your files below.
Packaging your files
Deephaven doesn't require your script files to be in any particular place, as long as each file_N path points to them. Relative file_N paths resolve against the application directory (app.d), the directory that holds the *.app files. Absolute paths are used as they are.
Each *.app config file must sit directly in the app.d directory, not in a subdirectory. Putting the *.app and script files in the same directory simplifies packaging your files with Docker and simplifies your file_N paths.
In this example, we show what a directory app.d looks like and how to package it with a Dockerfile for Deephaven.
Scripts and config file
Let's say we have a Python script (init_tables.py) we want to run when Deephaven launches. We can make a directory called app.d, and put the script in there.
The script creates my_table, a five-row table. Each row's Hello value is the string that hello returns.
Next, define our *.app config file to run this Python script on launch. Let's name it config.app and use the following to define it. Put it in the app.d directory next to the script.
Dockerfile
Since we have bundled our scripts and config files in the same directory (app.d), our Dockerfile needs to copy over this directory when we build it. The Dockerfile extends the Deephaven server image and copies over our app.d directory.
This Dockerfile assumes that it is in the same directory as app.d.
Because you're extending Deephaven's Docker image, you need to build this locally and tag it, for example my-app/deephaven-app. You also need to reference this tag in your docker-compose.yml file. The build command is in Putting it all together.
docker-compose.yml
The docker-compose.yml file sets the deephaven.application.dir property to /app.d, the directory where the Dockerfile copies app.d. Pass the property through START_OPTS, as described in the Docker application configuration guide.
The ports line publishes the server port, which you need to open the web IDE from the host. The volumes line mounts a data folder and is optional. In the environment line, only -Ddeephaven.application.dir=/app.d is specific to Application Mode. -Xmx4g sets the JVM heap size and is optional.
Our docker-compose.yml file should look like this.
Putting it all together
Once we've defined our files, our directory should look like this.
Build and tag the image with docker build --tag my-app/deephaven-app ., then run docker compose up to launch the application. When the server is up, open the Deephaven web IDE at localhost:10000 in a browser. my_table is available in the query scope with five rows.