Skip to content

Commit

Permalink
Move config in prod.exs to runtime.exs #94
Browse files Browse the repository at this point in the history
  • Loading branch information
x-ji committed Oct 3, 2020
1 parent 5cf75cb commit b48a242
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 107 deletions.
14 changes: 3 additions & 11 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ config :magpie, Magpie.Endpoint,
secret_key_base: "mUum0f5OpF/oj91tE+XldtHDV5RzRCwZ6GxdF3KDj1lau8GI6dq7HsB1pRMA5Z3z",
render_errors: [view: Magpie.ErrorView, accepts: ~w(html json)],
pubsub: [name: Magpie.PubSub, adapter: Phoenix.PubSub.PG2],
instrumenters:
(if System.get_env("USE_TIMBER") == "true" do
[Timber.Phoenix]
else
[]
end)
instrumenters: []

# Configures Elixir's Logger
config :logger, :console,
Expand All @@ -30,13 +25,10 @@ config :logger, :console,
# The local timezone where the app is deployed.
config :magpie, :timezone, "Europe/Berlin"

# Define a default. Only override in production where the app is accessible by the others
config :magpie,
:no_basic_auth,
(if System.get_env("MAGPIE_NO_BASIC_AUTH") == "true" do
true
else
false
end)
true

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
Expand Down
96 changes: 0 additions & 96 deletions config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,102 +1,6 @@
use Mix.Config

# For production, we configure the host to read the PORT
# from the system environment. Therefore, you will need
# to set PORT=80 before running your server.
#
# You should also configure the url host to something
# meaningful, we use this information when generating URLs.
#
# Finally, we also include the path to a manifest
# containing the digested version of static files. This
# manifest is generated by the mix phoenix.digest task
# which you typically run after static files are built.
config :magpie, Magpie.Endpoint,
load_from_system_env: true,
http: [port: {:system, "PORT"}],
# Replace the host with your own application URL!
url: [scheme: "https", host: "${APP_NAME}.gigalixirapp.com", port: 443],
force_ssl: [rewrite_on: [:x_forwarded_proto]],
cache_static_manifest: "priv/static/cache_manifest.json",
# Configuration for Heroku
secret_key_base: "${SECRET_KEY_BASE}",
# Needed for Distillery releases
server: true,
# Allow clients from anywhere to connect to use the interactive experiment facilities. We can't constrain where the user chooses to host the frontend anyways.
check_origin: false,
root: ".",
version: Application.spec(:magpie, :vsn)

# Configure the database
config :magpie, Magpie.Repo,
adapter: Ecto.Adapters.Postgres,
url: "${DATABASE_URL}",
database: "",
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "2"),
ssl: true,
log:
(if System.get_env("USE_TIMBER") == "true" do
false
else
:debug
end)

config :logger,
level: :info,
backends:
(if System.get_env("USE_TIMBER") == "true" do
[Timber.LoggerBackends.HTTP, :console]
else
[:console]
end)

config :timber,
api_key: "${TIMBER_API_KEY}",
source_id: "${TIMBER_SOURCE_ID}"

# Used for basic_auth
config :magpie, :authentication,
username: "${AUTH_USERNAME}",
password: "${AUTH_PASSWORD}"

config :magpie, :environment, :prod

# This is useful when the app is behind a reverse proxy and you need to actually use the URL shown to the outside by the reverse proxy, e.g. in template generation in web/templates/experiments/edit.html..ex
# config :magpie, :real_url, "URL_PRESENTED_BY_REVERSE_PROXY"

# ## SSL Support
#
# To get SSL working, you will need to add the `https` key
# to the previous section and set your `:url` port to 443:
#
# config :magpie, Magpie.Endpoint,
# ...
# url: [host: "example.com", port: 443],
# https: [port: 443,
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")]
#
# Where those two env variables return an absolute path to
# the key and cert in disk or a relative path inside priv,
# for example "priv/ssl/server.key".
#
# We also recommend setting `force_ssl`, ensuring no data is
# ever sent via http, always redirecting to https:
#
# config :magpie, Magpie.Endpoint,
# force_ssl: [hsts: true]
#
# Check `Plug.SSL` for all available options in `force_ssl`.

# ## Using releases
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start the server for all endpoints:
#
# config :phoenix, :serve_endpoints, true
#
# Alternatively, you can configure exactly which server to
# start per endpoint:
#
# config :magpie, Magpie.Endpoint, server: true
#
74 changes: 74 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import Config

config :magpie, Magpie.Endpoint,
http: [port: System.fetch_env!("PORT") |> String.to_integer()],
url: [
scheme: System.fetch_env!("URL_SCHEME"),
host: System.fetch_env!("HOST"),
path: System.fetch_env!("PATH"),
port: System.fetch_env!("PORT") |> String.to_integer()
],
force_ssl:
(if System.fetch_env!("URL_SCHEME") == "https" do
[rewrite_on: [:x_forwarded_proto]]
else
[]
end),
server: true,
# Allow clients from anywhere to connect to use the interactive experiment facilities. We can't constrain where the user chooses to host the frontend anyways.
secret_key_base: System.fetch_env!("SECRET_KEY_BASE"),
check_origin: false,
root: ".",
version: Application.spec(:magpie, :vsn),
instrumenters:
(if System.get_env("USE_TIMBER") == "true" do
[Timber.Phoenix]
else
[]
end)

# Configure the database
config :magpie, Magpie.Repo,
adapter: Ecto.Adapters.Postgres,
username: System.fetch_env!("DATABASE_USERNAME"),
password: System.fetch_env!("DATABASE_PASSWORD"),
hostname: System.fetch_env!("DATABASE_HOST"),
database: System.fetch_env!("DATABASE_NAME"),
pool_size: String.to_integer(System.get_env("POOL_SIZE", "2")),
ssl: true,
log:
(if System.get_env("USE_TIMBER") == "true" do
false
else
:debug
end)

# Used for basic_auth
config :magpie, :authentication,
username: System.fetch_env!("AUTH_USERNAME"),
password: System.fetch_env!("AUTH_PASSWORD")

# We don't have a basic auth on the demo app
config :magpie,
:no_basic_auth,
(if System.get_env("MAGPIE_NO_BASIC_AUTH") == "true" do
true
else
false
end)

config :logger,
backends:
(if System.get_env("USE_TIMBER") == "true" do
[Timber.LoggerBackends.HTTP, :console]
else
[:console]
end)

# Logging
config :timber,
api_key: System.get_env("TIMBER_API_KEY"),
source_id: System.get_env("TIMBER_SOURCE_ID")

# This is useful when the app is behind a reverse proxy and you need to actually use the URL shown to the outside by the reverse proxy, e.g. in template generation in web/templates/experiments/edit.html..ex
config :magpie, :real_url, System.get_env("REAL_URL", System.fetch_env!("HOST"))

0 comments on commit b48a242

Please sign in to comment.