bitwalker / distillery

Simplify deployments in Elixir with OTP releases!
MIT License
2.97k stars 398 forks source link

Distillery build appending '_1' in front of database and web app. #641

Closed dottjt closed 5 years ago

dottjt commented 5 years ago

Steps to reproduce

Following the guide

Verbose Logs

This is essentially the error I get when I run docker-compose up

web_1  | 20:56:40.342 [error] Postgrex.Protocol (#PID<0.2263.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "nfd_db" does not exist
db_1   | 2019-02-28 20:56:40.341 UTC [101] FATAL:  database "nfd_db" does not exist
web_1  | 20:56:40.506 [error] Postgrex.Protocol (#PID<0.2264.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "nfd_db" does not exist
db_1   | 2019-02-28 20:56:40.505 UTC [102] FATAL:  database "nfd_db" does not exist
db_1   | 2019-02-28 20:56:40.623 UTC [103] FATAL:  database "nfd_db" does not exist
web_1  | 20:56:40.624 [error] Postgrex.Protocol (#PID<0.2260.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "nfd_db" does not exist
db_1   | 2019-02-28 20:56:43.302 UTC [104] FATAL:  database "nfd_db" does not exist
web_1  | 20:56:43.303 [error] Postgrex.Protocol (#PID<0.2265.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "nfd_db" does not exist
^CGracefully stopping... (press Ctrl+C again to force)
Stopping nfd_web_1 ...
Stopping nfd_db_1  ...
^CKilling nfd_web_1  ...
Killing nfd_db_1   ...

Description of issue

I've been following the documentation for https://hexdocs.pm/distillery/guides/working_with_docker.html and essentially, it seems to be naming the application nfd_web_1 and the database nfd_db_1, as opposed to nfd_db which is what it's being set to in the config. Also, why is it nfd_web?

Anyway, what should I be doing differently to get the correct details? I've followed the documentation to a Tee, and now I'm stuck.

// rel/config/config.exs


use Mix.Config

config :nfd, Nfd.Repo,
  username: System.get_env("DATABASE_USER"),
  password: System.get_env("DATABASE_PASS"),
  database: System.get_env("DATABASE_NAME"),
  hostname: System.get_env("DATABASE_HOST"),
  pool_size: 15

port = String.to_integer(System.get_env("PORT") || "8080")
config :nfd, Nfd.Endpoint,
  http: [port: port],
  url: [host: System.get_env("HOSTNAME"), port: port],
  root: ".",
  secret_key_base: System.get_env("SECRET_KEY_BASE")

In my config/docker.env

HOSTNAME=localhost
SECRET_KEY_BASE="" # this has been removed just for this ticket issue.
DATABASE_HOST=db
DATABASE_USER=postgres
DATABASE_PASS=postgres
DATABASE_NAME=nfd_db
PORT=4000
LANG=en_US.UTF-8
REPLACE_OS_VARS=true
ERLANG_COOKIE=nfd

Dockerfile

ARG APP_NAME=nfd
# The version of the application we are building (required)
ARG APP_VSN=0.1.0

# where this is referenced twice. 
ARG APP_NAME=nfd
OvermindDL1 commented 5 years ago

That doesn't look like distillery doing that, that just looks like normal docker unique naming?

dottjt commented 5 years ago

Why would it be unique naming though?

dottjt commented 5 years ago

Is it a possible flaw in the Makefile for not specifying a --name?

dottjt commented 5 years ago

So there simply might be a flaw in the build instructions in the Distillery docs for Docker. I've attempted to provide nfd_web and nfd_db container_names to the services in the docker-compose.yml file, and now they're congruent in the terminal, however I still get the error:

~/C/P/nfd ❯❯❯ docker-compose up                                                             master ✖ ✱ ◼
Creating nfd_db ... done
Creating nfd_web ... done
Attaching to nfd_db, nfd_web
db_1   | 2019-02-28 21:34:27.586 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2019-02-28 21:34:27.586 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2019-02-28 21:34:27.597 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-02-28 21:34:27.754 UTC [19] LOG:  database system was shut down at 2019-02-28 21:33:31 UTC
db_1   | 2019-02-28 21:34:27.821 UTC [1] LOG:  database system is ready to accept connections
web_1  | 21:34:29.865 [info] [swarm on nfd@127.0.0.1] [tracker:init] started
db_1   | 2019-02-28 21:34:29.936 UTC [26] FATAL:  database "nfd_db" does not exist
web_1  | 21:34:29.938 [error] Postgrex.Protocol (#PID<0.2271.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "nfd_db" does not exist
db_1   | 2019-02-28 21:34:29.953 UTC [31] FATAL:  database "nfd_db" does not exist
web_1  | 21:34:29.954 [error] Postgrex.Protocol (#PID<0.2266.0>) failed to connect: ** (Postgrex.Error) FATAL 3D000 (invalid_catalog_name) database "nfd_db" does not exist
db_1   | 2019-02-28 21:34:29.967 UTC [30] FATAL:  database "nfd_db" does not exist
db_1   | 2019-02-28 21:34:29.969 UTC [29] FATAL:  database "nfd_db" does not exist
db_1   | 2019-02-28 21:34:29.974 UTC [32] FATAL:  database "nfd_db" does not exist

Thoughts?

OvermindDL1 commented 5 years ago

Why would it be unique naming though?

Just what I see it do, though in my case it might be a docker-compose thing.

jchristgit commented 5 years ago

I'm pretty sure the _1 being appended is coming from Docker Compose, since it allows you to spawn multiple replicas of a single service. Since by default it only starts up one instance of each application, all your apps have _1 appended to them.

However, the individual containers in your compose file can reach each other by their name you configured them with in docker-compose.yml. If you run multiple replicas of the same service, Docker will loadbalance them internally.

Your error seems unrelated to both Docker and Distillery: you're trying to access a database in Postgres which doesn't exist, the default postgres container only sets up a database named postgres. In config/docker.env, you should probably add something like:

POSTGRES_DB=nfd_db

in order to automatically create the database when the PostgreSQL container is created. See the "Environment variables" section on https://hub.docker.com/_/postgres for more things you can configure at startup.

Hope this helps.

dottjt commented 5 years ago

@jchristgit Thank you, I appreciate the advice.

bitwalker commented 5 years ago

Yes, this is a Docker Compose thing, not Distillery