Key :database not found when testing on ci/cd

I am using gitlab ci/cd to run my test suite. My tests run just fine locally but when the ci/cd runs it I get the following error:

(KeyError) key :database not found in: [telemetry_prefix: [:tiffany, :repo], otp_app: :tiffany, timeout: 15000, pool_size: 10]` `   
(elixir 1.11.4) lib/keyword.ex:420: Keyword.fetch!/2` `    
(ecto_sql 3.6.2) lib/ecto/adapters/postgres.ex:131: Ecto.Adapters.Postgres.storage_up/1` `    
(ecto 3.6.2) lib/mix/tasks/ecto.create.ex:53: anonymous fn/3 in` `   
(elixir 1.11.4) lib/enum.ex:798: Enum."-each/2-lists^foreach/1-0-"/2` `    
(mix 1.11.4) lib/mix/task.ex:394: Mix.Task.run_task/3` `    
(mix 1.11.4) lib/mix/cli.ex:84: Mix.CLI.run_task/2

I can’t figure out where the config setting is missing. I have everything setup as I have with all my applications which run tests on the same platform with not issues. Can someone point me in the right direction?

Show us your config/test.exs

use Mix.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.
config :tiffany, Tiffany.Repo,
  username: System.get_env("POSTGRES_USER") || "postgres",
  password: System.get_env("POSTGRES_PASSWORD") || "postgres",
  database: System.get_env("POSTGRES_DB") || "tiffany_test",
  hostname: System.get_env("POSTGRES_HOST") || "localhost",
  pool: Ecto.Adapters.SQL.Sandbox

# We don't run a server during test. If one is required,
# you can enable the server option below.
config :tiffany, TiffanyWeb.Endpoint,
  http: [port: 4002],
  server: false

# Print only warnings and errors during test
config :logger, level: :debug

Can you duplicate exactly the command and environment that your CI runs?

Do you have other mix environments outside the usual suspects (dev / test / prod)?

Can you show your Tiffany.Repo module? Do you have an init function on it?

when I run mix test locally it works just fine. Here are the steps being run during test on the CI/CD:

mix local.rebar --force
mix local.hex --force
mix archive.install hex sobelow --force
mix deps.get
mix ecto.create
mix ecto.migrate
mix test

It fails on mix ecto.create as it compiles the app and fails the compile with the error mentioned above. However if I run the CI/CD with a tag which will run the test then build the docker as a second step it works fine… it’s running the same commands there for testing as well.


defmodule Tiffany.Repo do
  use Ecto.Repo,
    otp_app: :tiffany,
    adapter: Ecto.Adapters.Postgres

Well I don’t know, maybe try inspecting your app’s config at the end of starting your application’s supervision tree?