<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="350796" data-post-id="350796">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="James_E" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/James_E/120/36696_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  James_E
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="benwilson512" data-post="11" data-topic="67926">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/48/1457_2.png" class="avatar"> benwilson512:</div>
<blockquote>
<p>just to avoid the actual good practice of doing a rolling deploy. And if you can’t rely on an environment variable being present on boot, how are you going to connect to the database anyway?</p>
</blockquote>
</aside>
<p>That’s stored in the application data directory, unless overridden by environment for some ad-hoc reason (such as being run in a deployed, managed, Linux-based or containerized environment).</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">database_path =
  System.get_env("DATABASE_PATH")
  || Path.expand("fooApp.db", :filename.basedir(:user_data, "fooApp"))
</code></pre>
<p>I’d <em>really</em> like it if the application I’m writing did not offload these “hoops to jump through”, as you put it, to the installing technician.</p>
<p>The existing version of the application I’m writing a replacement for “just works”: you unzip it and run it, and it generates defaults for its own config and state files if needed, which is (in my experience using non Elixir based programs) an almost completely universal standard; are you telling me there’s <em>no</em> best practice pattern for implementing that with Phoenix?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="350796" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/managing-secret-key-base-without-kubernetes-docker-etc/67926/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-350796" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="350796"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="350797" data-post-id="350797">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="James_E" data-post="12" data-topic="67926">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/james_e/48/36696_2.png" class="avatar"> James_E:</div>
<blockquote>
<p>The existing version of the application I’m writing a replacement for “just works”: you unzip it and run it, and it generates defaults for its own config and state files if needed, which is (in my experience using non Elixir based programs) an almost completely universal standard; are you telling me there’s <em>no</em> best practice pattern for implementing that with Phoenix?</p>
</blockquote>
</aside>
<p>The biggest part about this is getting the order of operations correct. <code>config/runtime.exs</code> is evaluated just after kernel/stdlib of otp are started. This is because you want it to be able to configure any other application (all your dependencies) and once applications are started they usually have already read their config from their application env. At the same time that means though that you cannot use any of your dependencies without them starting.</p>
<p>You can surely go ahead and figure out an order of starting up your dependencies so that you can do whatever custom configration needs you have while defering to start anything you want to configure through that configuration system – just like it would need to be done in any other application of any other language. This is not a simple thing to provide out of the box though. Nobody can anticipate what can be started for not needing additional configuration vs. the other half of your application needing additional configuration.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="350797" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/managing-secret-key-base-without-kubernetes-docker-etc/67926/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-350797" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="350797"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="350798" data-post-id="350798">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="benwilson512" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/120/1457_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  benwilson512
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Author of Craft GraphQL APIs in Elixir with Absinthe</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="James_E" data-post="12" data-topic="67926">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/james_e/48/36696_2.png" class="avatar"> James_E:</div>
<blockquote>
<p>the installing technician.</p>
</blockquote>
</aside>
<p>In your original post you said this is being managed and installed in a boring standard way. I took that to mean that there is still a company who has written software that they are deploying themselves, and would be using some sort of deployment tooling. This is what I would consider standard.</p>
<p>Is this software instead getting shipped to people who haven’t written it and need to run it and manage new versions / deploys manually?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="350798" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/managing-secret-key-base-without-kubernetes-docker-etc/67926/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-350798" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="350798"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="350805" data-post-id="350805">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="James_E" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/James_E/120/36696_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  James_E
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="LostKobrakai" data-post="13" data-topic="67926">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lostkobrakai/48/3072_2.png" class="avatar"> LostKobrakai:</div>
<blockquote>
<p><code>config/runtime.exs</code> is evaluated just after kernel/stdlib of otp are started … once applications are started they usually have already read their config from their application env. … You can surely go ahead and figure out an order of starting up your dependencies … [however] Nobody can anticipate what can be started for not needing additional configuration vs. the other half of your application needing additional configuration.</p>
</blockquote>
</aside>
<p>I see… I guess that’s a bit awkward, then, that Phoenix seems <a href="https://github.com/phoenixframework/phoenix/blob/v1.7.13/lib/phoenix/endpoint.ex#L649" rel="noopener nofollow ugc">hard-coded</a> to expect that lump of <em>application state</em> in an API optimized for storing and loading <em>config</em>.</p>
<p>Mostly thinking out loud, then; I guess there’s a few ways to handle that:</p>
<ol>
<li>Create the secrets during Migration, then figure out how to override <a href="https://github.com/phoenixframework/phoenix/blob/v1.7.13/lib/phoenix/endpoint.ex#L519" rel="noopener nofollow ugc"><code>FooWeb.Endpoint.start_link</code></a> to defer setting that config item as a parameter,<pre data-code-wrap="elixir"><code class="lang-elixir">children = [
  Foo.Telemetry,
  Foo.Repo,
  {Ecto.Migrator,
    repos: Application.fetch_env!(:fooApp, :ecto_repos),
    skip: skip_migrations?()},
  {DNSCluster, query: Application.get_env(:fooApp, :dns_cluster_query) || :ignore},
  {Phoenix.PubSub, name: Foo.PubSub},
  #{Finch, name: Foo.Finch}
  {DynamicSupervisor, name: Foo.ModelInstanceSupervisor},
  {FooWeb.Endpoint,
    secret_key_base: Foo.Repo.one!(
      Ecto.Query.from(s in Foo.Repo.Schemas.Secret, select: s.value),
      type: "secret_key_base")}
]
</code></pre>
</li>
<li>Inject a new “Foo.Util.LoadPseudoConfig” task into the application startup sequence <a href="https://github.com/phoenixframework/phoenix/blob/v1.7.13/installer/templates/phx_single/lib/app_name/application.ex#L20" rel="noopener nofollow ugc">somewhere after <code>Ecto.Migrator</code> but before <code>FooWeb.Endpoint</code></a>, which pulls values like that out of Ecto and sticks them in the Application config;</li>
<li>Give up on handling this in software, and just write a buddy-doc SOP to defer the task to a human and force the org to consider more managed deployment going forward.</li>
</ol> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="350805" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/managing-secret-key-base-without-kubernetes-docker-etc/67926/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-350805" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="350805"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="350807" data-post-id="350807">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="LostKobrakai" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/LostKobrakai/120/3072_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  LostKobrakai
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="James_E" data-post="15" data-topic="67926">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/james_e/48/36696_2.png" class="avatar"> James_E:</div>
<blockquote>
<p>I see… I guess that’s a bit awkward, then, that Phoenix seems <a href="https://github.com/phoenixframework/phoenix/blob/v1.7.13/lib/phoenix/endpoint.ex#L649" rel="nofollow">hard-coded</a> to expect that lump of <em>application state</em> in an API optimized for storing and loading <em>config</em>.</p>
</blockquote>
</aside>
<p>That’s not the case. Phoenix will merge config coming from the app env with config passed when starting the endpoint. If you want to you can ditch the app env completely and pass all the config via <code>{MyAppWeb.Endpoint, config}</code>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="350807" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/managing-secret-key-base-without-kubernetes-docker-etc/67926/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-350807" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="350807"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="350847" data-post-id="350847">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="rhcarvalho" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rhcarvalho/120/32243_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  rhcarvalho
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="James_E" data-post="1" data-topic="67926">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/james_e/48/36696_2.png" class="avatar"> James_E:</div>
<blockquote>
<p>I’ve currently got this code to manage <code>SECRET_KEY_BASE</code>, and it seems to work, but it also seems like a really messy hack</p>
</blockquote>
</aside>
<p>If you need someone else to install the app without much thinking about configuration, then I think your existing solution is fine.</p>
<p>It provides an automatic and persistent value for <code>SECRET_KEY_BASE</code>, and places it right at the normal place for configuration.</p>
<p>As a source of inspiration, I suggest looking at how LiveBook handles config, because similar to your use case it provides this experience of “just works”.</p>
<p><a href="https://github.com/livebook-dev/livebook/blob/84ac71b8262636140f5364821c5c7b47f6381063/lib/livebook.ex#L98" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/livebook-dev/livebook/blob/84ac71b8262636140f5364821c5c7b47f6381063/lib/livebook.ex#L98</a></p><aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/search?q=repo%3Alivebook-dev%2Flivebook%20secret%21&amp;type=code">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" alt="" width="32" height="32">

      <a href="https://github.com/search?q=repo%3Alivebook-dev%2Flivebook%20secret%21&amp;type=code" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <img width="690" height="690" src="https://github.githubassets.com/assets/github-logo-55c5b9a1fe52.png" class="thumbnail onebox-avatar" alt="">

<h3><a href="https://github.com/search?q=repo%3Alivebook-dev%2Flivebook%20secret%21&amp;type=code" target="_blank" rel="noopener nofollow ugc">Build software better, together</a></h3>

  <p>GitHub is where people build software. More than 150 million people use GitHub to discover, fork, and contribute to over 420 million projects.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
<p><a href="https://github.com/livebook-dev/livebook/blob/main/config%2Fruntime.exs" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/livebook-dev/livebook/blob/main/config%2Fruntime.exs</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="350847" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/managing-secret-key-base-without-kubernetes-docker-etc/67926/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-350847" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="350847"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="350865" data-post-id="350865">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="felix-starman" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/felix-starman/120/18051_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  felix-starman
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Admittedly, having not read all the replies, there’s Config. Provider of you really need fine tuned control.</p>
<p>There’s also a lovely library I’ve used called Hush</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://hex.pm/packages/hush">
  <header class="source">
      <img src="https://hex.pm/images/hex-full-a8183c4f9adac71516516d107d402b18.svg?vsn=d" class="site-icon" alt="" width="136" height="120">

      <a href="https://hex.pm/packages/hush" target="_blank" rel="noopener nofollow">Hex</a>
  </header>

  <article class="onebox-body">
    <img width="160" height="160" src="https://hex.pm/images/favicon-160-3770bc59f1f8ba7656b4db5a1eacd8e3.png?vsn=d" class="thumbnail onebox-avatar" alt="">

<h3><a href="https://hex.pm/packages/hush" target="_blank" rel="noopener nofollow">hush</a></h3>

  <p>Load configuration and secrets from files, environment variables, AWS, GCP and more.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>EDIT:<br>
Im not sure if it works well in runtime, but there’s also the new <a href="https://hexdocs.pm/elixir/Config.html#read_config/1" rel="noopener nofollow ugc">read_config</a> which could be combined with hush to limit some of the extra calls to your Hush.Provider</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="350865" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/managing-secret-key-base-without-kubernetes-docker-etc/67926/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-350865" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="350865"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="350880" data-post-id="350880">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dimitarvp" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dimitarvp/120/38664_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dimitarvp
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>If you want to pull config from the database, you have these options (off the top of my head – there might be more):</p>
<ol>
<li>Finish app startup normally but schedule loading of config immediately after that (various good options to achieve it) and forbid any database operations until this initializer finishes (via f.ex. ETS);</li>
<li>Use <a href="https://hexdocs.pm/db_connection/DBConnection.html#start_link/2-connection-configuration-callback" rel="noopener nofollow ugc"><code>Repo</code>’s ability to call a function before each connect attempt</a> (configuration via <code>start_link</code> options <a href="https://hexdocs.pm/db_connection/DBConnection.html" rel="noopener nofollow ugc">described here</a>) and limit the <code>pool_index</code> to e.g. zero so it’s not ran for every allocated connection and check some sort of a global state (f.ex. in ETS) to establish whether whatever config you need from the DB has been already read and whether you should read it again – though maybe if you want runtime-reloadable config you should just leave this check intact and have it run on each connect attempt as originally intended in the API. This is slightly involved and I don’t like it but my former colleagues have used this technique successfully for similar purposes (in our case we wanted to be able to change database details while the app was running so the callback function we wrote was re-reading a file where the full PostgreSQL database URL was stored – this gave us the ability to migrate databases to new locations and have zero app downtime);</li>
<li>Have a throwaway single DB connection that you can start i.e. do <code>Postgrex.start_link(...)</code> inside <code>Application.start</code>, execute a bespoke hard-coded SQL query that fetches the config, and move on with life.</li>
</ol>
<p>IMO we can’t be mad at the core team for not providing tight integration between the built-in <code>Config</code> API and the [technically] 3rd party library that is <code>Ecto</code>.</p>
<p>If you want quick-and-dirty, go for option 3.</p>
<p>If you want to do it as the Ecto maintainers intended, go for option 2 (also gives you the ability to have the said config be reloaded during runtime without requiring app restart).</p>
<p>I wouldn’t go for option 1 ever, but it’s technically still an option.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="350880" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/managing-secret-key-base-without-kubernetes-docker-etc/67926/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-350880" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="350880"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="351926" data-post-id="351926">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="James_E" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/James_E/120/36696_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  James_E
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="LostKobrakai" data-post="16" data-topic="67926">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lostkobrakai/48/3072_2.png" class="avatar"> LostKobrakai:</div>
<blockquote>
<p>Phoenix will merge config coming from the app env with <strong>config passed when starting the endpoint.</strong></p>
</blockquote>
</aside>
<p>Wow, I didn’t realize that! Thank you.</p>
<p>That ended up leading to this relatively generic solution to allow deferring arbitrary config:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Foo.Application do
  @moduledoc false
  use Application

  @impl true
  def start(_type, _args) do
    children = [
      FooWeb.Telemetry,
      Foo.Repo,
      {Ecto.Migrator,
        repos: Application.fetch_env!(:fooApp, :ecto_repos),
        skip: skip_migrations?()},
      #{DNSCluster, query: Application.get_env(:foo, :dns_cluster_query) || :ignore},
      {Phoenix.PubSub, name: Foo.PubSub},
      {DynamicSupervisor, name: Foo.RoomSupervisor},
      FooWeb.Endpoint |&gt; Foo.Util.defer_spec(
        secret_key_base: {Foo.Repo, Foo.Repo.Schemas.Secret, &amp;FooWeb.Util.phx_gen_secret/0}
      )
    ]

    opts = [strategy: :one_for_one, name: Foo.Supervisor]
    Supervisor.start_link(children, opts)
  end

  …
end
</code></pre>
<details>
<summary>
Utility functions / heavy lifting</summary>
<pre data-code-wrap="elixir"><code class="lang-elixir"># lib/foo/util.ex
defmodule Foo.Util do
  require Ecto.Query

  …

  # https://github.com/elixir-ecto/ecto/blob/v3.12.5/lib/ecto/repo/queryable.ex#L153
  def one_or_insert_lazy!(repo, query, fun) do
    repo.transaction(fn -&gt;
      case repo.all(query) do
        [value] -&gt; value
        [] -&gt;
          repo.insert!(fun.())
          repo.one!(query)
        other -&gt; raise Ecto.MultipleResultsError, queryable: query, count: length(other)
      end
    end)
  end

  @spec defer_spec(Supervisor.module_spec(), deferred_opts :: keyword()) :: Supervisor.child_spec()
  def defer_spec(module_spec, deferred_opts \\ [])
  def defer_spec(module, deferred_opts) when is_atom(module), do: defer_spec({module, []}, deferred_opts)
  def defer_spec({module, opts}, deferred_opts)
      when is_atom(module) do
    %{
      id: module,
      start: {__MODULE__, :_start_link_helper, [module, opts, deferred_opts]}
    }
  end

  def _start_link_helper(module, opts, deferred_opts) do
    access = if is_list(opts), do: Keyword, else: Access

    opts = Enum.reduce(deferred_opts, opts, fn
      {key, {repo, schema, default_fun}}, acc when is_function(default_fun, 0) -&gt;
        {_, acc} = access.get_and_update(acc, key, fn
          value when not is_nil(value) -&gt;
            {value, value}

          _ -&gt;
            key = Atom.to_string(key)
            value = one_or_insert_lazy!(
              repo,
              Ecto.Query.from(
                s in schema,
                where: s.name == ^key,
                select: s.value
              ),
              fn -&gt; struct(
                schema,
                name: key,
                value: default_fun.()
              ) end
            )
            {nil, value}
        end)
        acc

      {key, fun}, acc when is_function(fun, 0) -&gt;
        access.put(acc, key, fun.())

      {key, fun}, acc when is_function(fun, 1) -&gt;
        {_, acc} = access.get_and_update(acc, key, &amp;{&amp;1, fun.(&amp;1)})
        acc

      {key, {:get_and_update, fun}}, acc when is_function(fun, 1) -&gt;
        {_, acc} = access.get_and_update(acc, key, fun)
        acc
    end)

    module.start_link(opts)
  end
end
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir"># lib/foo_web/util.ex
defmodule FooWeb.Util do
  def phx_gen_secret(length \\ 64) do
    # https://github.com/phoenixframework/phoenix/blob/v1.7.17/lib/mix/tasks/phx.gen.secret.ex#L17
    :crypto.strong_rand_bytes(length) |&gt; Base.encode64(padding: false) |&gt; binary_part(0, length)
  end
end
</code></pre>
</details> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="351926" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/managing-secret-key-base-without-kubernetes-docker-etc/67926/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-351926" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="351926"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>