Neon DB and Fly.IO
I like Fly and NeonDB is one of their recommended managed Postges vendors, so I thought I would check them out for one of my projects.
They have a pretty good guide to setting it up in Phoenix.
Of course, I ran into issues.
The problem is, Fly uses IPv6 and Neon doesn’t support it (yet). You need to make a couple of changes to the default Dockerfile and runtime configuration.
Dockerfile
Comment out the line, added by Fly, that sets Ecto to IPV6
...
# Appended by flyctl
# ENV ECTO_IPV6 true <- Comment out this line
ENV ERL_AFLAGS "-proto_dist inet6_tcp"
Runtime.exs
-
Remove
maybe_ipv6
-
Configure
ssl_opts
...
%URI{host: database_host} = URI.parse(database_url)
# maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []
# NOTE: explicitly set no ipv6 because fly.io was still setting ECTO_IPV6
config :my_app, MyApp.Repo,
ssl: true,
url: database_url,
ssl_opts: [
verify: :verify_peer,
cacertfile: Path.join(:code.priv_dir(:my_app), "cert/cacert.pem"),
server_name_indication: to_charlist(database_host),
customize_hostname_check: [
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
]
],
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
# maybe_ipv6,
socket_options: [],
prepare: :unnamed
...