Open epichiori opened 6 years ago
To deploy on prod environment I changed the Dockerfile to run as "non root" user and to set the env to production:
FROM elixir:1.5.2 ENV MIX_ENV=prod \ HOME=/app ADD mix.exs mix.lock /app/ ADD config /app/config WORKDIR /app RUN mix local.hex --force RUN mix local.rebar --force RUN mix deps.get --only prod RUN mix deps.compile ADD . /app RUN mix compile RUN useradd -s /bin/bash -u 1001 -g 0 aida RUN chmod -R g+rw /app && \ chown -R aida:0 /app USER 1001 ENV PORT=80 EXPOSE 80 CMD elixir --sname server -S mix phx.server
In config directory I set the variable to point to env variables in prod.exs file :
[..] config :aida, AidaWeb.Endpoint, load_from_system_env: true, # url: [host: {:system, "HOST"}, port: 80] url: [host: {:system, "DBHOST"}, port: {:system, "DBPORT"}] [..] config :aida, Aida.Repo, adapter: Ecto.Adapters.Postgres, username: System.get_env("DBUSER"), password: System.get_env("DBPWD"), database: System.get_env("DBSCHEMA"), # username: "postgres", # password: "postgres", # database: "aida", pool_size: 15 [..]
My modifcations seems not working.
The build operations are ok:
Successfully built 5f27dd3095b8 Pushing image docker-registry.default.svc:5000/chatbot-aida-dev/app:latest ... Pushed 0/18 layers, 0% complete Pushed 1/18 layers, 13% complete Pushed 2/18 layers, 17% complete Pushed 3/18 layers, 21% complete Pushed 4/18 layers, 35% complete Pushed 5/18 layers, 38% complete Pushed 6/18 layers, 44% complete Pushed 7/18 layers, 49% complete Pushed 8/18 layers, 55% complete Pushed 9/18 layers, 61% complete Pushed 10/18 layers, 62% complete Pushed 11/18 layers, 67% complete Pushed 12/18 layers, 73% complete Pushed 13/18 layers, 78% complete Pushed 14/18 layers, 84% complete Pushed 15/18 layers, 90% complete Pushed 16/18 layers, 97% complete Pushed 17/18 layers, 100% complete Pushed 18/18 layers, 100% complete Push successful
But the pod give the following error messages:
10:22:06.703 [error] Postgrex.Protocol (#PID<0.331.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.326.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.334.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.330.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.329.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.324.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.332.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.327.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.325.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.328.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.703 [error] Postgrex.Protocol (#PID<0.333.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused 10:22:06.907 [error] Failed to start Ranch listener AidaWeb.Endpoint.HTTP in :ranch_tcp:listen([:inet6, {:port, 80}]) for reason :eacces (permission denied) {"Kernel pid terminated",application_controller,"{application_start_failure,aida,{{shutdown,{failed_to_start_child,'Elixir.AidaWeb.Endpoint',{shutdown,{failed_to_start_child,'Elixir.Phoenix.Endpoint.Handler',{shutdown,{failed_to_start_child,{ranch_listener_sup,'Elixir.AidaWeb.Endpoint.HTTP'},{shutdown,{failed_to_start_child,ranch_acceptors_sup,{listen_error,'Elixir.AidaWeb.Endpoint.HTTP',eacces}}}}}}}}},{'Elixir.Aida.Application',start,[normal,[]]}}}"} Kernel pid terminated (application_controller) ({application_start_failure,aida,{{shutdown,{failed_to_start_child,'Elixir.AidaWeb.Endpoint',{shutdown,{failed_to_start_child,'Elixir.Phoenix.Endpoint.Ha Crash dump is being written to: erl_crash.dump...done
How can i set correctly the PROD env and how can I use env variables to load producion values?
Thank you in advance, E. Pichiori
Hi @epichiori The connection to the database is specified with the DATABASE_URL environment variable. Here's an example of the value for this variable:
ecto://user:password@database-host/database-name
To deploy on prod environment I changed the Dockerfile to run as "non root" user and to set the env to production:
In config directory I set the variable to point to env variables in prod.exs file :
My modifcations seems not working.
The build operations are ok:
But the pod give the following error messages:
How can i set correctly the PROD env and how can I use env variables to load producion values?
Thank you in advance, E. Pichiori