Skip to content

Commit

Permalink
Improve config & rel
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Feb 8, 2024
1 parent 0766462 commit 374b324
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 12 deletions.
25 changes: 18 additions & 7 deletions flavours/classic/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ 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),
do: [Bonfire.Common.Repo, Beacon.Repo],
else: [Bonfire.Common.Repo]

repos =
if System.get_env("TEST_INSTANCE") == "yes",
if test_instance in yes?,
do: repos ++ [Bonfire.Common.TestInstanceRepo],
else: repos

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions flavours/classic/config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions rel/overlays/bin/migrate
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
cd -P -- "$(dirname -- "$0")"
exec ./bonfire eval Bonfire.Common.Repo.migrate
1 change: 1 addition & 0 deletions rel/overlays/bin/migrate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
call "%~dp0\bonfire" eval Bonfire.Common.Repo.migrate
3 changes: 3 additions & 0 deletions rel/overlays/bin/no_server
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
cd -P -- "$(dirname -- "$0")"
PHX_SERVER=no exec ./bonfire start
2 changes: 2 additions & 0 deletions rel/overlays/bin/no_server.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set PHX_SERVER=no
call "%~dp0\bonfire" start
3 changes: 3 additions & 0 deletions rel/overlays/bin/server
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
cd -P -- "$(dirname -- "$0")"
PHX_SERVER=yes exec ./bonfire start
2 changes: 2 additions & 0 deletions rel/overlays/bin/server.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set PHX_SERVER=yes
call "%~dp0\bonfire" start
2 changes: 1 addition & 1 deletion test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 374b324

Please sign in to comment.