Gettings tcp error using mix releases

With the release of Elixir 1.9, I’m having issues related to run-time variables

config :cidades, App.Repo,
ssl: true,
username: db_user,
password: db_password,
database: db_name,
hostname: db_hostname,
port: String.to_integer(db_port),
pool_size: String.to_integer(db_pool)

When I put this config inside “config/releases.exs” the app fails with: Error tcp connect: non-existing domain - :nxdomain, but when I set inside the “config/prod.exs” everything works almost fine. Except, I can’t set the variables inside the prod.exs no longer since I remove the REPLACE_OS_VARS in my docker build.
In Distillery, I would use the pattern "${DB_NAME}" instead of System.fetch_env!("DB_NAME") and setting REPLACE_OS_VARS=true and the above code/commands will work. Any hint?

Your code sample is incomplete, you have a bunch of variables (eg db_user) but you don’t show us how you set them. It’s hard to answer your question without knowing where you get the actual values from.

So sorry, but i’m using the standard way as show by the documentation

# Configure your database
 config :myapp, MyApp.Repo,
 ssl: true,
 username: System.fetch_env!("DO_POSTGRES_USER"),
 password: System.fetch_env!("DO_POSTGRES_PASSWORD"),
 database: System.fetch_env!("DO_POSTGRES_DB")
 hostname: System.fetch_env!("DO_POSTGRES_HOST"),
 port: String.to_integer(System.fetch_env!("DO_POSTGRES_PORT")),
 pool_size: String.to_integer(System.fetch_env!("DO_POSTGRES_POOL_SIZE"))

Just to clarify the variable is being loaded, I had omited the host but is something as:
“Error tcp connect: (myhost, myport) non-existing domain - :nxdomain”
So is being loaded when using the releases file, but the error persist :confused:
When I set them(the actual string in the repo params) on “config/prods.exs” everything works flawlessly!

Okay, so you’re saying that hard coding the values into prod.exs works, but reading them from environment in releases.exs doesn’t work, you’re getting the error Error tcp connect: (myhost, myport) non-existing domain - :nxdomain, although I guess you’ve edited that, it doesn’t look like a domain at all. Does the real error message have the correct domain?

If it’s trying to connect to the wrong domain it’s probably because you have the wrong domain defined in your environment. I suggest checking with echo $DO_POSTGRES_HOST etc, to make sure that it is actually there.

Yes, I had edited for the sensitive information on it. I’m connecting to a Digital Ocean database. And unfortunately the domain is the same in the prod.exs. That’s the part which bugs me.
If you want any additional info to be provided.

This is my prods.exs

import Config

config :cidades, CidadesWeb.Endpoint, load_from_system_env: true, check_origin: false

# Do not print debug messages in production
config :logger, level: :info

# Configure your database
config :cidades, Cidades.Repo,
  ssl: true,
  username: "",
  password: "",
  database: "",
  hostname: "",
  port: ,
  pool_size: 12,
  timeout: 60_000

# Logs
config :rollbax,
  environment: "prod",
  enabled: true,
  enable_crash_reports: true

This is my releases.exs

import Config

# Configure your endpoin
config :cidades, CidadesWeb.Endpoint,
  http: [
    :inet6,
    port: String.to_integer(System.fetch_env!("CIDADES_PHOENIX_PORT"))
  ],
  url: [
    host: System.fetch_env!("CIDADES_K8S_PUBLIC_HOST"),
    port: String.to_integer(System.fetch_env!("CIDADES_K8S_PUBLIC_PORT"))
  ],
  secret_key_base: System.fetch_env!("CIDADES_PHOENIX_SECRET_KEY_BASE"),
  cache_static_manifest: "priv/static/cache_manifest.json",
  version: Application.get_env(:cidades, :version),
  server: true,
  root: "."

# Configure your database
# config :cidades, Cidades.Repo,
# ssl: true,
# username: System.fetch_env!("CIDADES_DO_POSTGRES_USER"),
# password: System.fetch_env!("CIDADES_DO_POSTGRES_PASSWORD"),
# database: System.fetch_env!("CIDADES_DO_POSTGRES_DB")
# hostname: System.fetch_env!("CIDADES_DO_POSTGRES_HOST"),
# port: String.to_integer(System.fetch_env!("CIDADES_DO_POSTGRES_PORT")),
# pool_size: String.to_integer(System.fetch_env!("CIDADES_DO_POSTGRES_POOL_SIZE"))

# Configures Bamboo
config :cidades, Cidades.Mailer,
  adapter: Bamboo.SendGridAdapter,
  api_key: System.fetch_env!("CIDADES_SENDGRID_API_KEY")

# Arc uploader
config :arc,
  storage: Arc.Storage.S3,
  virtual_host: true,
  bucket: System.fetch_env!("CIDADES_DO_S3_BUCKET"),
  asset_host: "https://#{"${CIDADES_DO_S3_HOST}"}/#{"${CIDADES_DO_S3_BUCKET}"}"

# asset_host: "https://#{System.get_env("S3_HOST")}/#{System.get_env("S3_BUCKET")}"

# AWS & S3 DO SPACES
config :ex_aws,
  access_key_id: System.fetch_env!("CIDADES_DO_S3_KEY"),
  secret_access_key: System.fetch_env!("CIDADES_DO_S3_SECRET"),
  region: System.fetch_env!("CIDADES_DO_S3_REGION"),
  s3: [
    scheme: "https://",
    host: System.fetch_env!("CIDADES_DO_S3_HOST"),
    region: System.fetch_env!("CIDADES_DO_S3_REGION")
  ]

# Logs
config :rollbax,
  access_token: System.fetch_env!("CIDADES_ROLLBAR_ACCESS_TOKEN")

All the environment variables are correctly being loaded in my docker container. I had tried outside docker and the same thing happen. Hard coding values works and in releases.exs throws exception: “Error tcp connect: (domain, port) non-existing domain - :nxdomain”

Are you sure, that there is no space or newline in the environment variable that doesn’t belong there?

hostname: System.fetch_env!("CIDADES_DO_POSTGRES_HOST") |> IO.inspect(label: "DB Host"),

Yes, this is the return:
_build/prod/rel/cidades/bin/cidades start /s/w/c/api DB Host: “blablabla.db.ondigitalocean.com
“Starting Prometheus”
api | “Prometheus started” api | 21:14:45.277 application=phoenix module=Phoenix.Endpoint.Cowboy2Adapter [info] Running CidadesWeb.Endpoint with cowboy 2.6.3 at :::80 (http)
api | 21:14:45.278 application=phoenix module=Phoenix.Endpoint.Supervisor [info] Access CidadesWeb.Endpoint at http://‘localhost’ api | 21:14:45.368 application=db_connection module=DBConnection.Connection [error] Postgrex.Protocol (#PID<0.4747.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (‘blablabla.db.ondigitalocean.com’:1234): non-existing domain - :nxdomain

An update here, it seems that the problem is being raised by a dns config in my alpine docker container. When I fix, it I’ll be posting here. Thanks everyone… The odd is that used to work in distillery release

Problem fixed adding those params to docker-compose service:
tty: true
dns_search: google.com
dns:
- 8.8.8.8
- 8.8.4.4
I tried to append to last reply, but the option to edit wasn’t available. Thank you all.