Deployment - NatLabRockies/alfalfa GitHub Wiki
General Deployment Considerations
Alfalfa is a containerized application that can be deployed via docker-compose, Docker Swarm, or Kubernetes. Experience deploying and troubleshooting Docker applications is a pre-requisite.
The Alfalfa Helm Chart repo contains resources for deployment to Kubernetes. This is the recommended pathway for production deployments. Instructions below are for deployment with docker-compose and Docker Swarm and intended primarily for local development and testing.
Caveats
- All deployment instructions here use environment variables that are committed to the repo. These are set to allow local deployments to work seamlessly out of the box, but it is your responsibility to update any sensitive variables (ie credentials) before deploying.
- Unlike your average web application, Alfalfa is heavily dependent on in-memory state because the underlying models must run in memory. This means that deployments are not resilient to worker restarts; if a worker is restarted while a model is running, that model state will be lost.
How to Deploy Historian
Alfalfa includes optional Historian functionality, which is enabled by setting the HISTORIAN_ENABLE=true environment variable for the worker container and adding two containers to the stack:
- InfluxDB for timeseries data storage
- Grafana for visualization
Notes
- Note that in images published to DockerHub, the datasource has been provisioned to connect to InfluxDB using the username and password in the repo's .env file. If you have updated these (as you should) for your deployment, you will also need to manually update them via the Grafana UI, which can be accessed at
<grafana-host>/datasources/edit/1/ - Model time is always treated as UTC, which is also the default for chart display. This means that plot filters like "past 6 hours" are relative to current UTC time.
- The Historian only considers model time and has no concept of the real-world time as simulations run. All plots are of model time.
How to Deploy with docker-compose
This assumes that you have installed Docker and docker-compose and are in the root of this repo.
- update .env file: replace any credentials with real values and modify
VERSION_TAGif appropriate to a tag available on DockerHub. To build the containers yourself, do not run thepullcommand and append--buildto theupcommands below. - Without Historian:
docker compose pull && docker compose up -d
With Historian:
HISTORIAN_ENABLE=true && docker compose -f docker-compose.yml -f docker-compose.historian.yml pull && docker-compose -f docker-compose.yml -f docker-compose.historian.yml up -d
- Confirm the web server is up at http://localhost
- Confirm the minio (file upload) server is up at http://localhost:9000
- Confirm the historian (if applicable) is up at http://localhost:3000
- Clean up with
docker compose downordocker compose -f docker-compose.yml -f docker-compose.historian.yml down - To clear the database and delete uploaded models run
docker compose downwith-vargument
How to Deploy with Docker Swarm
- Swarm deployments don't load .env, so do that explicitly:
export $(cat .env | xargs) - Without Historian:
docker stack deploy -c docker-compose.yml alfalfa - With Historian:
HISTORIAN_ENABLE=true && docker stack deploy -c docker-compose.yml -c docker-compose.historian.yml alfalfa - Confirm the web server is up at http://localhost
- Confirm the minio (file upload) server is up at http://localhost:9000
- Confirm the historian (if applicable) is up at http://localhost:3000
- Clean up:
docker stack rm alfalfa