My Elixir/Phoenix runs on a single node and uses an SQLite db with a volume (I understand the volume is linked to the region where the app runs).
I want to run a distributed version on 2 regions. I understand I have to use a Litefs volume to be synced between regions.
The (distrbuted version) deployment fails on the release command:
ERROR: config file not found
INFO Main child exited normally with code: 2
Which “config file” is missing? There might be several points to clarify in the docs:
- Update Dockerfile to Install LiteFS dependencies:
Is this the “runner” stage?
#Dockerfile
#runner stage
RUN apt-get update -y && apt-get install -y ca-certificates fuse3
...
COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs
^^^here?
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/my_app./
#USER nobody
^^^Fly asks to remove this
ENV ECTO_IPV6 true
ENV ERL_AFLAGS "-proto_dist inet6_tcp"
ENTRYPOINT litefs mount
^^?
#CMD ["/app/bin/server"]
^^^unused since declared in "litefs.yml" ?
- [mounts].
For SQLite, I fly volumes create litefs --region cdg --size 1
as the source.
I created another one for SQLite before:
fly volumes list
ID STATE NAME SIZE REGION ZONE ENCRYPTED ATTACHED VM
vol_9vwdqnqzyg99nm9r created litefs 1GB cdg 99aa true
vol_6vjwd6p5k9g62l94 created mydata 1GB cdg 9937 true e82d37dc25e678
In the “Litefs.yml” file, it is written “this data should not be accessed directly by the user application.”.
It is also asked to append the declared LiteFS volume in the “fly.toml” with a [mounts]
section.
As said, in the SQLite settings, I am asked to create a volume for SQlite and declare a “DATABASE_PATH” in the “fly.toml”. Should I just forget it now?
I can’t use several “mounts”, nor use several “source” in a mount. This means I cannot declare the special volume I declared for SQLite. Will LiteFS proxy correctly to its volume?
#litefs.yml
fuse:
dir: "/litefs"
# The data section describes settings for the internal LiteFS storage. We'll
# mount a volume to the data directory so it can be persisted across restarts.
# However, this data should not be accessed directly by the user application.
data:
dir: "/var/lib/litefs"
proxy:
addr: ":8080"
target: "localhost:4000"
^^??
exec:
- cmd: "/app/bin/server -addr :4000 -dsn /litefs/db"
#fly.toml
[mounts]
source = "litefs"
destination = "/var/lib/litefs"
[ENV]
DATABASE_PATH = "my_app_prod.db"
^^^correct??
DNS_CLUSTER_QUERY = "my_app.internal"
PHX_HOST = "my_app.fly.dev"
PORT = "8080"
My defaults were (deploys ok):
[mounts]
source = "mydata"
destination = "/data"
[ENV]
DATABASE_PATH = "/data/mydata/my_app_prod.db"
DNS_CLUSTER_QUERY = "my_app.internal"
PHX_HOST = "my_app.fly.dev"
PORT = "8080"
So in terms of config, I don’t have anything else that “fly.toml”, “litefs.yml”, the Dockerfile, and Phoenix “config/runtime.exs” (standard too). The “release” action file is standard too.
if config_env() == :prod do
database_path =
System.get_env("DATABASE_PATH") ||
raise """
environment variable DATABASE_PATH is missing.
For example: /data/name/name.db
"""
config :name, Counter.Repo,
database: database_path,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5")
end
Thank you.