I found two issues when I’m try to deploy my app to Fly.io
The first is that fly expects me to have a config/prod.exs
file which I don’t have. I created an empty prod.exs
file there just so that error go away, but it would be nice if I could specify that I don’t want that file copied during the docker container creation.
The second one is that I have my configs separated into multiple files to make things easier to organize.
So, for example, I have a config/aws.exs
file and in my config/config.exs
I have the following line loading it: import_config "aws.exs"
.
fly seems to expect that I just use config/config.exs
and config/prod.exs
and will just copy these two files to the docker container. I think this is very problematic since it will fail as soon as someone changes how their config are handled.
Probably a better solition is to just copy the full config
directory.
Here is the error I get when I try to deploy:
core [fix_credo_warnings]× » fly deploy 13:34:38
==> Verifying app config
Validating /var/home/sezdocs/projects/feedback_cupcake/core/fly.toml
✓ Configuration is valid
--> Verified app config
==> Building image
Remote builder fly-builder-rough-silence-291 ready
Remote builder fly-builder-rough-silence-291 ready
==> Building image with Docker
--> docker host: 24.0.7 linux x86_64
[+] Building 4.5s (19/28)
=> [internal] load build definition from Dockerfile 0.7s
=> => transferring dockerfile: 2.82kB 0.7s
=> [internal] load .dockerignore 0.7s
=> => transferring context: 1.37kB 0.7s
=> [internal] load metadata for docker.io/library/debian:bullseye-20240130-slim 1.0s
=> [internal] load metadata for docker.io/hexpm/elixir:1.16.2-erlang-26.2.1-debian-bul 1.1s
=> [builder 1/17] FROM docker.io/hexpm/elixir:1.16.2-erlang-26.2.1-debian-bullseye-20 0.0s
=> [internal] load build context 1.8s
=> => transferring context: 209.51kB 1.8s
=> [stage-1 1/6] FROM docker.io/library/debian:bullseye-20240130-slim@sha256:8481471ca 0.0s
=> CACHED [stage-1 2/6] RUN apt-get update -y && apt-get install -y libstdc++6 opens 0.0s
=> CACHED [stage-1 3/6] RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-g 0.0s
=> CACHED [stage-1 4/6] WORKDIR /app 0.0s
=> CACHED [stage-1 5/6] RUN chown nobody /app 0.0s
=> CACHED [builder 2/17] RUN apt-get update -y && apt-get install -y build-essential 0.0s
=> CACHED [builder 3/17] WORKDIR /app 0.0s
=> CACHED [builder 4/17] RUN mix local.hex --force && mix local.rebar --force 0.0s
=> CACHED [builder 5/17] COPY mix.exs mix.lock ./ 0.0s
=> CACHED [builder 6/17] RUN mix deps.get --only prod 0.0s
=> CACHED [builder 7/17] RUN mkdir config 0.0s
=> [builder 8/17] COPY config/config.exs config/prod.exs config/ 0.0s
=> ERROR [builder 9/17] RUN mix deps.compile 0.7s
------
> [builder 9/17] RUN mix deps.compile:
0.725 ["config", "deps", "mix.exs", "mix.lock"]
0.726 ["config.exs", "prod.exs"]
0.734 ** (File.Error) could not read file "/app/config/aws.exs": no such file or directory
0.734 (elixir 1.16.2) lib/file.ex:384: File.read!/1
0.734 (elixir 1.16.2) lib/config.ex:275: Config.__import__!/1
0.734 /app/config/config.exs:6: (file)
0.734 (stdlib 5.2) erl_eval.erl:750: :erl_eval.do_apply/7
0.734 (stdlib 5.2) erl_eval.erl:136: :erl_eval.exprs/6
------
Error: failed to fetch an image or build from source: error building: failed to solve: process "/bin/sh -c mix deps.compile" did not complete successfully: exit code: 1