elsa-core icon indicating copy to clipboard operation
elsa-core copied to clipboard

Sqlite database persistence with Docker

Open c9482 opened this issue 1 year ago • 2 comments

Hello,

I am trying to persist the sqlite database using docker-compose. Despite overriding the connection string as shown below, the application still starts with the default connection string from appsettings.json. What am I missing? Many thanks in advance.

elsa-server-and-studio:
    image: elsaworkflows/elsa-server-and-studio-v3:latest
    container_name: elsa-server-and-studio
    volumes:
      - elsa-db:/app/data
    ports:
      - 13000:8080
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_CONFIG=./app/appsettings.json
      - ConnectionStrings__SqlLite=Data Source=/app/data/elsa.sqlite.db;Cache=Shared;
      # This does not work either
      # - ConnectionStrings:SqlLite=Data Source=/app/data/elsa.sqlite.db;Cache=Shared;

c9482 avatar Mar 08 '24 18:03 c9482

To persist the SQLite database using Docker Compose and override the connection string, you need to ensure that the environment variable name matches the one expected by the application. In the case of Elsa, the environment variable for the SQLite connection string should be Elsa__ConnectionStrings__Sqlite, not ConnectionStrings__SqlLite. The Elsa__ prefix is necessary because the application expects the connection string to be nested under the Elsa section in the appsettings.json file.

Here's how you can modify your docker-compose.yml service definition:

elsa-server-and-studio:
    image: elsaworkflows/elsa-server-and-studio-v3:latest
    container_name: elsa-server-and-studio
    volumes:
      - elsa-db:/app/data
    ports:
      - 13000:8080
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - Elsa__ConnectionStrings__Sqlite=Data Source=/app/data/elsa.sqlite.db;Cache=Shared;

Make sure that the volume elsa-db is correctly defined elsewhere in your docker-compose.yml file to persist the data.

Additionally, the environment variable ASPNETCORE_CONFIG is not a standard variable used by ASP.NET Core to specify configuration files. If you want to provide a custom appsettings.json, you should mount it as a volume to the appropriate path inside the container.

If you continue to face issues, please ensure that the application is coded to read the connection string from the environment variables, which is a common practice for applications designed to run in containers.

glime-ai[bot] avatar Mar 08 '24 18:03 glime-ai[bot]

I modified the service definition as recommended but it did not solve my problem.

version: "3"

volumes:
  elsa-db: {}

  elsa-server-and-studio:
    image: elsaworkflows/elsa-server-and-studio-v3:latest
    container_name: elsa-server-and-studio
    volumes:
      - elsa-db:/app/data
    ports:
      - 13000:8080
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - Elsa__ConnectionStrings__SqlLite=${ELSA_CONNECTION_STRING}

Also, I do not see "elsa" section in the appsettings.config. The file looks like this:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Elsa.Mediator": "Warning",
      "MassTransit": "Warning",
      "Microsoft.Extensions.Http": "Warning",
      "Microsoft.Hosting.Lifetime": "Information",
      "Microsoft.EntityFrameworkCore": "Warning",
      "Microsoft.AspNetCore": "Warning",
      "System.Net.Http": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "Sqlite": "Data Source=elsa.sqlite.db;Cache=Shared;",
    "RabbitMq": "rabbitmq://guest:guest@localhost:5672"
  }
}

Is there anything else I can try?

c9482 avatar Mar 08 '24 18:03 c9482

Hi @c9482 I don't think it's enough to just change the connection string, because Elsa runs within the docker container, the SQLite driver will create a file within the filesystem of that container.

The docker image isn't really designed to be configurable, but we do plan on creating a fully-featured, configurable image at some point. Until then, it might be better to create your own workflow server by following some of the existing examples, such as Elsa.Server.Web and/or Elsa.ServerAndStudio.Web. This way, you have full control over your workflow server's setup.

More information can be found here: https://elsa-workflows.github.io/elsa-documentation/application-types.html

sfmskywalker avatar Apr 05 '24 22:04 sfmskywalker