I asked a question here (Mariaex.Error) failed to upgraded socket: :enotconn yesterday, and finally made it work under dev
environment with this config in dev.exs
:
config :app, App.Repo,
adapter: Ecto.Adapters.MySQL,
ssl: true,
ssl_opts: [cacertfile: Path.join(["priv", "ssl", "ca.pem"]), certfile: Path.join(["priv", "ssl", "client-cert.pem"]), keyfile: Path.join(["priv", "ssl", "client-key.pem"])]
But then I got another problem deploying my app with Distillery, since the path would be wrong in prod
environment.
Here is what I do.
First, I build my app with distillery in docker GitHub - bitwalker/alpine-elixir-phoenix: An Alpine Linux base image containing Elixir, Erlang, Node, Hex, and Rebar. Ready for Phoenix applications!, then deploy it in docker GitHub - bitwalker/alpine-erlang: An alpine image with Erlang installed, intended for releases. My app will run from /opt/app/bin/app start
, then I got these error logs:
app | 10:21:32.387 [error] Mariaex.Protocol (#PID<0.1286.0>) failed to connect: ** (Mariaex.Error) failed to upgraded socket: {:options, {:cacertfile, '/opt/app/priv/ssl/ca.pem', {:error, :enoent}}}
The application try to read those ca.pem
files from /opt/app/priv/ssl/
folder, but they are not there. The /opt/app
only has these:
I can find the ssl folder under /opt/app/lib/app-0.0.1/priv/
, but I have no idea how to access it in my prod.secret.exs
config file.
I have tried File.cwd!
, it won’t work.
The other post Including data files in a Distillery release - #5 by chensan said I can access priv
either with Application.app_dir(app_name, "priv/path/to/file")
or :code.priv_dir(app)
:
"#{Application.app_dir(:app)}/priv/ssl/ca.pem"
But I would got error:
** (Mix.Config.LoadError) could not load config config/dev.exs
** (ArgumentError) unknown application: :app
(elixir) lib/application.ex:428: Application.app_dir/1
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
(stdlib) erl_eval.erl:269: :erl_eval.expr/5
(stdlib) eval_bits.erl:81: :eval_bits.eval_field/3
(stdlib) eval_bits.erl:65: :eval_bits.expr_grp/4
(stdlib) erl_eval.erl:474: :erl_eval.expr/5
(stdlib) erl_eval.erl:878: :erl_eval.expr_list/6
(stdlib) erl_eval.erl:236: :erl_eval.expr/5
Seems like I can’t use :app
here. I’m still new to elixir, and google won’t help anymore, so any help here are welcome. Thanks very much.