diff --git a/flavours/classic/config/runtime.exs b/flavours/classic/config/runtime.exs index d72474de4d..2ca510c0af 100755 --- a/flavours/classic/config/runtime.exs +++ b/flavours/classic/config/runtime.exs @@ -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, diff --git a/flavours/classic/config/test.exs b/flavours/classic/config/test.exs index def4c6768d..17a08ef077 100755 --- a/flavours/classic/config/test.exs +++ b/flavours/classic/config/test.exs @@ -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"]) diff --git a/justfile b/justfile index c7a8beb2be..0641b3b44d 100644 --- a/justfile +++ b/justfile @@ -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 diff --git a/rel/overlays/bin/migrate b/rel/overlays/bin/migrate new file mode 100644 index 0000000000..6d4c9f0599 --- /dev/null +++ b/rel/overlays/bin/migrate @@ -0,0 +1,3 @@ +#!/bin/sh +cd -P -- "$(dirname -- "$0")" +exec ./bonfire eval Bonfire.Common.Repo.migrate diff --git a/rel/overlays/bin/migrate.bat b/rel/overlays/bin/migrate.bat new file mode 100644 index 0000000000..c043e70467 --- /dev/null +++ b/rel/overlays/bin/migrate.bat @@ -0,0 +1 @@ +call "%~dp0\bonfire" eval Bonfire.Common.Repo.migrate diff --git a/rel/overlays/bin/no_server b/rel/overlays/bin/no_server new file mode 100644 index 0000000000..825d02370b --- /dev/null +++ b/rel/overlays/bin/no_server @@ -0,0 +1,3 @@ +#!/bin/sh +cd -P -- "$(dirname -- "$0")" +PHX_SERVER=no exec ./bonfire start diff --git a/rel/overlays/bin/no_server.bat b/rel/overlays/bin/no_server.bat new file mode 100644 index 0000000000..a815ea8243 --- /dev/null +++ b/rel/overlays/bin/no_server.bat @@ -0,0 +1,2 @@ +set PHX_SERVER=no +call "%~dp0\bonfire" start diff --git a/rel/overlays/bin/server b/rel/overlays/bin/server new file mode 100644 index 0000000000..42b6a75cd4 --- /dev/null +++ b/rel/overlays/bin/server @@ -0,0 +1,3 @@ +#!/bin/sh +cd -P -- "$(dirname -- "$0")" +PHX_SERVER=yes exec ./bonfire start diff --git a/rel/overlays/bin/server.bat b/rel/overlays/bin/server.bat new file mode 100644 index 0000000000..5f70f97907 --- /dev/null +++ b/rel/overlays/bin/server.bat @@ -0,0 +1,2 @@ +set PHX_SERVER=yes +call "%~dp0\bonfire" start diff --git a/test/test_helper.exs b/test/test_helper.exs index d6246b71db..3cd4967c5f 100755 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -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