Improve config & rel

This commit is contained in:
Mayel de Borniol 2024-02-08 09:22:43 +00:00
parent 0766462145
commit 374b3248ef
10 changed files with 36 additions and 12 deletions

View file

@ -9,6 +9,10 @@ IO.puts("🔥 Welcome to Bonfire!")
host = System.get_env("HOSTNAME", "localhost")
server_port = String.to_integer(System.get_env("SERVER_PORT", "4000"))
public_port = String.to_integer(System.get_env("PUBLIC_PORT", "4000"))
test_instance = System.get_env("TEST_INSTANCE")
yes? = ~w(true yes 1)
no? = ~w(false no 0)
repos =
if Code.ensure_loaded?(Beacon.Repo),
@ -16,7 +20,7 @@ repos =
else: [Bonfire.Common.Repo]
repos =
if System.get_env("TEST_INSTANCE") == "yes",
if test_instance in yes?,
do: repos ++ [Bonfire.Common.TestInstanceRepo],
else: repos
@ -40,14 +44,20 @@ System.get_env("DATABASE_URL") || System.get_env("POSTGRES_PASSWORD") || System.
and POSTGRES_USER (default: postgres) and POSTGRES_HOST (default: localhost)
"""
maybe_repo_ipv6 = if System.get_env("ECTO_IPV6") in yes?, do: [:inet6], else: []
repo_connection_config =
if System.get_env("DATABASE_URL") do
[url: System.get_env("DATABASE_URL")]
[
url: System.get_env("DATABASE_URL"),
socket_options: maybe_repo_ipv6
]
else
[
username: System.get_env("POSTGRES_USER", "postgres"),
password: System.get_env("POSTGRES_PASSWORD", "postgres"),
hostname: System.get_env("POSTGRES_HOST", "localhost")
hostname: System.get_env("POSTGRES_HOST", "localhost"),
socket_options: maybe_repo_ipv6
]
end
@ -90,12 +100,13 @@ config :bonfire,
dir: cute_gifs_dir
]
phx_server = System.get_env("PHX_SERVER")
use_cowboy? = System.get_env("PLUG_SERVER") == "cowboy"
config :bonfire, Bonfire.Web.Endpoint,
server:
config_env() != :test or System.get_env("TEST_INSTANCE") == "yes" or
System.get_env("START_SERVER") == "yes",
phx_server not in no? and
(config_env() != :test or test_instance in yes? or phx_server in yes?),
url: [
host: host,
port: public_port
@ -152,7 +163,7 @@ IO.puts("Note: Starting database connection pool of #{pool_size}")
database =
case config_env() do
:test ->
"bonfire_test_#{System.get_env("TEST_INSTANCE")}_#{System.get_env("MIX_TEST_PARTITION")}"
"bonfire_test_#{test_instance}_#{System.get_env("MIX_TEST_PARTITION")}"
:dev ->
System.get_env("POSTGRES_DB", "bonfire_dev")
@ -227,7 +238,7 @@ case System.get_env("GRAPH_DB_URL") do
pool_size: pool_size
end
if (config_env() == :prod or System.get_env("OTEL_ENABLED") == "1") and
if (config_env() == :prod or System.get_env("OTEL_ENABLED") in yes?) and
(System.get_env("OTEL_EXPORTER_OTLP_ENDPOINT") || System.get_env("OTEL_LIGHTSTEP_API_KEY") ||
System.get_env("OTEL_HONEYCOMB_API_KEY")) do
config :opentelemetry_exporter,

View file

@ -88,8 +88,7 @@ config :exsync,
# use Ecto sandbox?
config :bonfire,
sql_sandbox:
System.get_env("START_SERVER") != "yes" and System.get_env("TEST_INSTANCE") != "yes"
sql_sandbox: System.get_env("PHX_SERVER") != "yes" and System.get_env("TEST_INSTANCE") != "yes"
{chromedriver_path, _} = System.cmd("sh", ["-c", "command -v chromedriver"])

View file

@ -222,7 +222,7 @@ recompile *args='':
just compile --force $args
dev-test:
@MIX_ENV=test START_SERVER=yes just dev-run
@MIX_ENV=test PHX_SERVER=yes just dev-run
# Run the app in dev mode, as a background service
dev-bg: init
@ -565,7 +565,7 @@ test-federation-dance-positions:
TEST_INSTANCE=yes MIX_ENV=test just mix deps.clean bonfire --build
test-federation-live-DRAGONS *args='':
FEDERATE=yes START_SERVER=yes HOSTNAME=$(just local-tunnel-hostname) PUBLIC_PORT=443 just test --only live_federation $@
FEDERATE=yes PHX_SERVER=yes HOSTNAME=$(just local-tunnel-hostname) PUBLIC_PORT=443 just test --only live_federation $@
load_testing:
TEST_INSTANCE=yes just mix bonfire.load_testing

3
rel/overlays/bin/migrate Normal file
View file

@ -0,0 +1,3 @@
#!/bin/sh
cd -P -- "$(dirname -- "$0")"
exec ./bonfire eval Bonfire.Common.Repo.migrate

View file

@ -0,0 +1 @@
call "%~dp0\bonfire" eval Bonfire.Common.Repo.migrate

View file

@ -0,0 +1,3 @@
#!/bin/sh
cd -P -- "$(dirname -- "$0")"
PHX_SERVER=no exec ./bonfire start

View file

@ -0,0 +1,2 @@
set PHX_SERVER=no
call "%~dp0\bonfire" start

3
rel/overlays/bin/server Normal file
View file

@ -0,0 +1,3 @@
#!/bin/sh
cd -P -- "$(dirname -- "$0")"
PHX_SERVER=yes exec ./bonfire start

View file

@ -0,0 +1,2 @@
set PHX_SERVER=yes
call "%~dp0\bonfire" start

View file

@ -29,7 +29,7 @@ Mix.Task.run("ecto.migrate")
# Ecto.Adapters.SQL.Sandbox.mode(repo(), :manual)
# if System.get_env("START_SERVER") !="yes" do
# if System.get_env("PHX_SERVER") !="yes" do
Ecto.Adapters.SQL.Sandbox.mode(repo(), :auto)
# end