Skip to content

Commit

Permalink
Migrate to Config, add runtime.exs, adjust CI config
Browse files Browse the repository at this point in the history
  • Loading branch information
wmnnd committed Jan 3, 2021
1 parent 80a5007 commit 63d7588
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
MIX_ENV: test
DB_URL: postgres://postgres:postgres@postgres/keila
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand All @@ -36,16 +39,12 @@ jobs:
~/assets/node_modules
key: ${{ runner.os }}-${{ hashFiles('mix.lock') }}
- name: mix deps.get
env:
MIX_ENV: test
run: |
apk add build-base git
mix local.rebar --force
mix local.hex --force
mix deps.get
- name: mix ecto.create && ecto.migrate
env:
MIX_ENV: test
run: |
mix ecto.create
mix ecto.migrate
Expand Down
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# is restricted to this project.

# General application configuration
use Mix.Config
import Config

config :keila,
ecto_repos: [Keila.Repo]
Expand Down Expand Up @@ -34,4 +34,4 @@ config :phoenix, :json_library, Jason

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env()}.exs"
import_config "#{config_env()}.exs"
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# Configure your database
config :keila, Keila.Repo,
Expand Down
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# For production, don't forget to configure the url host
# to something meaningful, Phoenix uses this information
Expand Down
2 changes: 1 addition & 1 deletion config/prod.secret.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# from environment variables. You can also hardcode secrets,
# although such is generally not recommended and you have to
# remember to add this file to your .gitignore.
use Mix.Config
import Config

database_url =
System.get_env("DATABASE_URL") ||
Expand Down
23 changes: 23 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Config

update_env = fn (app, key, update_fn) ->
value = update_fn.(Application.get_env(app, key))
Application.put_env(app, key, value)
end

if config_env() == :prod do

end

if config_env() == :test do
db_url = System.get_env("DB_URL")
if db_url do
db_url = db_url <> "#{System.get_env("MIX_TEST_PARTITION")}"
update_env.(:keila, Keila.Repo, &Keyword.replace(&1, :url, db_url))
end
# username: "postgres",
# password: "postgres-keila-dev-pw",
# database: "keila_test#{System.get_env("MIX_TEST_PARTITION")}",
# hostname: "localhost",
# port: 54323,
end
8 changes: 3 additions & 5 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use Mix.Config
import Config

# Configure your database
#
# The MIX_TEST_PARTITION environment variable can be used
# to provide built-in test partitioning in CI environment.
# Run `mix help test` for more information.
# URL can be overwritten with the DB_URL environment variable.
config :keila, Keila.Repo,
username: "postgres",
password: "postgres",
database: "keila_test#{System.get_env("MIX_TEST_PARTITION")}",
hostname: "postgres",
url: "ecto://postgres:postgres@localhost:5432/keila_test#{System.get_env("MIX_TEST_PARTITION")}",
pool: Ecto.Adapters.SQL.Sandbox

# We don't run a server during test. If one is required,
Expand Down

0 comments on commit 63d7588

Please sign in to comment.