From e4a4500d9970715ac14d2cfe220c14d7744c96de Mon Sep 17 00:00:00 2001 From: Mayel de Borniol Date: Thu, 19 Oct 2023 23:11:42 +0100 Subject: [PATCH] Use bandit web server by default --- flavours/classic/config/deps.hex | 2 +- flavours/classic/config/dev.exs | 4 +- flavours/classic/config/runtime.exs | 146 ++++++++++--------- flavours/classic/config/templates/public.env | 4 +- mix.lock | 4 +- 5 files changed, 83 insertions(+), 77 deletions(-) diff --git a/flavours/classic/config/deps.hex b/flavours/classic/config/deps.hex index 60a0b954bcf..7e302aecba4 100755 --- a/flavours/classic/config/deps.hex +++ b/flavours/classic/config/deps.hex @@ -14,7 +14,7 @@ plug_crypto = "~> 2.0" # newer crypto for plug/phoenix plug_cowboy = "~> 2.6" # should match the version in phoenix's mix.exs cowboy = "~> 2.10" # should match the version used in plug_cowboy # gettext = "<= 0.21.0" # note: usually we should let bonfire_ui_common control this -bandit = ">= 0.6.3" # alternative to Cowboy web server +bandit = "~> 1.0" # alternative to Cowboy web server orion = "~> 1.0" # tracing with web UI (at /admin/system/orion) # admin tools diff --git a/flavours/classic/config/dev.exs b/flavours/classic/config/dev.exs index 76f28c235a7..e40f9810b29 100755 --- a/flavours/classic/config/dev.exs +++ b/flavours/classic/config/dev.exs @@ -39,12 +39,14 @@ local_deps = # ), # else: [] +use_cowboy? = System.get_env("PLUG_SERVER") == "cowboy" + # Watch static and templates for browser reloading. config :bonfire, Bonfire.Web.Endpoint, server: true, debug_errors: false, check_origin: false, - http: [protocol_options: [idle_timeout: 120_000]], + http: if(use_cowboy?, do: [protocol_options: [idle_timeout: 120_000]], else: []), watchers: [ yarn: [ "watch.js", diff --git a/flavours/classic/config/runtime.exs b/flavours/classic/config/runtime.exs index 69f082a8150..c550acf66cd 100755 --- a/flavours/classic/config/runtime.exs +++ b/flavours/classic/config/runtime.exs @@ -26,68 +26,6 @@ hosts = # |> IO.inspect() -if (config_env() == :prod or System.get_env("OTEL_ENABLED") == "1") 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, - disabled: false - - config :opentelemetry_exporter, - otlp_protocol: :http_protobuf - - otel_endpoint = System.get_env("OTEL_EXPORTER_OTLP_ENDPOINT") - - if otel_endpoint do - IO.puts("NOTE: OTLP (open telemetry) data will be sent to #{otel_endpoint}") - - config :opentelemetry_exporter, - otlp_endpoint: otel_endpoint - end - - if System.get_env("OTEL_LIGHTSTEP_API_KEY") do - IO.puts("NOTE: OTLP (open telemetry) data will be sent to lightstep.com") - # Example configuration for Lightstep.com, for more refers to: - # https://github.com/open-telemetry/opentelemetry-erlang/tree/main/apps/opentelemetry_exporter#application-environment - config :opentelemetry_exporter, - # You can configure the compression type for exporting traces. - otlp_compression: :gzip, - oltp_traces_compression: :gzip, - otlp_traces_endpoint: "https://ingest.lightstep.com:443/traces/otlp/v0.9", - otlp_headers: [ - {"lightstep-access-token", System.get_env("OTEL_LIGHTSTEP_API_KEY")} - ] - end - - if System.get_env("OTEL_HONEYCOMB_API_KEY") do - IO.puts("NOTE: OTLP (open telemetry) data will be sent to honeycomb.io") - - config :opentelemetry, :processors, - otel_batch_processor: %{ - exporter: { - :opentelemetry_exporter, - %{ - endpoints: [ - {:https, ~c"api.honeycomb.io", 443, - [ - verify: :verify_peer, - cacertfile: :certifi.cacertfile(), - depth: 3, - customize_hostname_check: [ - match_fun: :public_key.pkix_verify_hostname_match_fun(:https) - ] - ]} - ], - headers: [ - {"x-honeycomb-team", System.fetch_env!("OTEL_HONEYCOMB_API_KEY")}, - {"x-honeycomb-dataset", System.get_env("OTEL_SERVICE_NAME", "bonfire")} - ], - protocol: :grpc - } - } - } - end -end - ## load extensions' runtime configs (and behaviours) directly via extension-provided modules Bonfire.Common.Config.LoadExtensionsConfig.load_configs(Bonfire.RuntimeConfig) ## @@ -142,6 +80,8 @@ config :bonfire, signing_salt: signing_salt, root_path: File.cwd!() +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 @@ -152,19 +92,21 @@ config :bonfire, Bonfire.Web.Endpoint, ], # check_origin: hosts, # FIXME check_origin: false, - http: [ - port: server_port, - transport_options: - if(System.get_env("PLUG_SERVER") != "bandit", - do: [max_connections: 16_384, socket_opts: [:inet6]], - else: [:inet6] - ) - ], adapter: - if(System.get_env("PLUG_SERVER") != "bandit", + if(use_cowboy?, do: Phoenix.Endpoint.Cowboy2Adapter, else: Bandit.PhoenixAdapter ), + http: + if(use_cowboy?, + do: [ + port: server_port, + transport_options: [max_connections: 16_384, socket_opts: [:inet6]] + ], + else: [ + port: server_port + ] + ), secret_key_base: secret_key_base, live_view: [signing_salt: signing_salt] @@ -227,6 +169,68 @@ case System.get_env("GRAPH_DB_URL") do pool_size: 10 end +if (config_env() == :prod or System.get_env("OTEL_ENABLED") == "1") 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, + disabled: false + + config :opentelemetry_exporter, + otlp_protocol: :http_protobuf + + otel_endpoint = System.get_env("OTEL_EXPORTER_OTLP_ENDPOINT") + + if otel_endpoint do + IO.puts("NOTE: OTLP (open telemetry) data will be sent to #{otel_endpoint}") + + config :opentelemetry_exporter, + otlp_endpoint: otel_endpoint + end + + if System.get_env("OTEL_LIGHTSTEP_API_KEY") do + IO.puts("NOTE: OTLP (open telemetry) data will be sent to lightstep.com") + # Example configuration for Lightstep.com, for more refers to: + # https://github.com/open-telemetry/opentelemetry-erlang/tree/main/apps/opentelemetry_exporter#application-environment + config :opentelemetry_exporter, + # You can configure the compression type for exporting traces. + otlp_compression: :gzip, + oltp_traces_compression: :gzip, + otlp_traces_endpoint: "https://ingest.lightstep.com:443/traces/otlp/v0.9", + otlp_headers: [ + {"lightstep-access-token", System.get_env("OTEL_LIGHTSTEP_API_KEY")} + ] + end + + if System.get_env("OTEL_HONEYCOMB_API_KEY") do + IO.puts("NOTE: OTLP (open telemetry) data will be sent to honeycomb.io") + + config :opentelemetry, :processors, + otel_batch_processor: %{ + exporter: { + :opentelemetry_exporter, + %{ + endpoints: [ + {:https, ~c"api.honeycomb.io", 443, + [ + verify: :verify_peer, + cacertfile: :certifi.cacertfile(), + depth: 3, + customize_hostname_check: [ + match_fun: :public_key.pkix_verify_hostname_match_fun(:https) + ] + ]} + ], + headers: [ + {"x-honeycomb-team", System.fetch_env!("OTEL_HONEYCOMB_API_KEY")}, + {"x-honeycomb-dataset", System.get_env("OTEL_SERVICE_NAME", "bonfire")} + ], + protocol: :grpc + } + } + } + end +end + # start prod-only config if config_env() == :prod do config :bonfire, Bonfire.Common.Repo, diff --git a/flavours/classic/config/templates/public.env b/flavours/classic/config/templates/public.env index 180d1e0a6aa..35d0aae6d03 100755 --- a/flavours/classic/config/templates/public.env +++ b/flavours/classic/config/templates/public.env @@ -11,11 +11,12 @@ MAIL_BACKEND=none SEARCH_MEILI_INSTANCE=http://localhost:7700 # require an email address to be invited before being able to sign up INVITE_ONLY=true - # uncomment in order to NOT automatically change the database schema when you upgrade the app # DISABLE_DB_AUTOMIGRATION=true # max file upload size (default is 20 meg) UPLOAD_LIMIT=20000000 +# Use cowboy or bandit as webserver? +PLUG_SERVER=bandit # ==================================== # You should not have to edit any of the following ones: POSTGRES_HOST=localhost @@ -27,4 +28,3 @@ POSTGRES_USER=postgres POSTGRES_DB=bonfire_db ACME_AGREE=true SHOW_DEBUG_IN_DEV=true -# PLUG_SERVER=bandit diff --git a/mix.lock b/mix.lock index 70758c4675e..4d07180db27 100644 --- a/mix.lock +++ b/mix.lock @@ -12,7 +12,7 @@ "bamboo_ses": {:hex, :bamboo_ses, "0.4.2", "e148a0ae17f8223b830029c2e81b2ba18220aa7378531ef1f50c4212fbd9ddb1", [:mix], [{:bamboo, "~> 2.0", [hex: :bamboo, repo: "hexpm", optional: false]}, {:ex_aws, "~> 2.4.1", [hex: :ex_aws, repo: "hexpm", optional: false]}, {:gen_smtp, "~> 1.2.0", [hex: :gen_smtp, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "feb609b57316d335b217937f66cfc7c1ebe37ec481bebe97fcd5da5f31171808"}, "bamboo_smtp": {:hex, :bamboo_smtp, "4.2.2", "e9f57a2300df9cb496c48751bd7668a86a2b89aa2e79ccaa34e0c46a5f64c3ae", [:mix], [{:bamboo, "~> 2.2.0", [hex: :bamboo, repo: "hexpm", optional: false]}, {:gen_smtp, "~> 1.2.0", [hex: :gen_smtp, repo: "hexpm", optional: false]}], "hexpm", "28cac2ec8adaae02aed663bf68163992891a3b44cfd7ada0bebe3e09bed7207f"}, "bamboo_sparkpost": {:hex, :bamboo_sparkpost, "2.0.0", "8617642e438340186da422b7f1ec25663d1c8fa869ecaf3e5ba2524131a1b5f0", [:mix], [{:bamboo, "~> 2.0", [hex: :bamboo, repo: "hexpm", optional: false]}], "hexpm", "a89a1c29e122270e50c53c77e091d885c40bebb689f8904572c38b299649bebf"}, - "bandit": {:hex, :bandit, "0.7.7", "48456d09022607a312cf723a91992236aeaffe4af50615e6e2d2e383fb6bef10", [:mix], [{:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 0.6.7", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "772f0a32632c2ce41026d85e24b13a469151bb8cea1891e597fb38fde103640a"}, + "bandit": {:hex, :bandit, "1.0.0", "2bd87bbf713d0eed0090f2fa162cd1676198122e6c2b68a201c706e354a6d5e5", [:mix], [{:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "32acf6ac030fee1f99fd9c3fcf81671911ae8637e0a61c98111861b466efafdb"}, "beam_file": {:hex, :beam_file, "0.5.3", "8ef6b6ab3b2981e5d67c20e635fdddab4b82d96d25fe50c26a259bafed996ead", [:mix], [], "hexpm", "f4722cc3b811b94c4941fa981e25319f7b2ae24495196fcf075208cffb9228e4"}, "benchee": {:hex, :benchee, "1.1.0", "f3a43817209a92a1fade36ef36b86e1052627fd8934a8b937ac9ab3a76c43062", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}], "hexpm", "7da57d545003165a012b587077f6ba90b89210fd88074ce3c60ce239eb5e6d93"}, "benchee_html": {:hex, :benchee_html, "1.0.0", "5b4d24effebd060f466fb460ec06576e7b34a00fc26b234fe4f12c4f05c95947", [:mix], [{:benchee, ">= 0.99.0 and < 2.0.0", [hex: :benchee, repo: "hexpm", optional: false]}, {:benchee_json, "~> 1.0", [hex: :benchee_json, repo: "hexpm", optional: false]}], "hexpm", "5280af9aac432ff5ca4216d03e8a93f32209510e925b60e7f27c33796f69e699"}, @@ -257,7 +257,7 @@ "tesla": {:hex, :tesla, "1.7.0", "a62dda2f80d4f8a925eb7b8c5b78c461e0eb996672719fe1a63b26321a5f8b4e", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.13", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:msgpax, "~> 2.3", [hex: :msgpax, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2e64f01ebfdb026209b47bc651a0e65203fcff4ae79c11efb73c4852b00dc313"}, "text": {:hex, :text, "0.2.0", "5a1d84eec574533d500439feacafe3681e2326f883800976df9f9dffd4cf9afd", [:mix], [{:flow, "~> 0.14", [hex: :flow, repo: "hexpm", optional: false]}], "hexpm", "5ca265ba24bd2f00ab647dd524305e24cc17224b4f0052f169ff488013888bc3"}, "text_corpus_udhr": {:hex, :text_corpus_udhr, "0.1.0", "d29b37bdeedc922138e144a7161cae4ece3d7809d37a52398cb9d43d923cc141", [:mix], [{:text, "~> 0.2", [hex: :text, repo: "hexpm", optional: false]}], "hexpm", "056a0b6a804ef03070f89b9b2e09d3271539654f4e2c30bb7d229730262f3fb8"}, - "thousand_island": {:hex, :thousand_island, "0.6.7", "3a91a7e362ca407036c6691e8a4f6e01ac8e901db3598875863a149279ac8571", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "541a5cb26b88adf8d8180b6b96a90f09566b4aad7a6b3608dcac969648cf6765"}, + "thousand_island": {:hex, :thousand_island, "1.0.0", "63fc8807d8607c9d74fa670996897c8c8a1f2022c8c68d024182e45249acd756", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "996320c72ba8f34d7be9b02900622e44341649f24359e0f67643e4dda8f23995"}, "timex": {:hex, :timex, "3.7.11", "bb95cb4eb1d06e27346325de506bcc6c30f9c6dea40d1ebe390b262fad1862d1", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.20", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 1.1", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "8b9024f7efbabaf9bd7aa04f65cf8dcd7c9818ca5737677c7b76acbc6a94d1aa"}, "tls_certificate_check": {:hex, :tls_certificate_check, "1.20.0", "1ac0c53f95e201feb8d398ef9d764ae74175231289d89f166ba88a7f50cd8e73", [:rebar3], [{:ssl_verify_fun, "~> 1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "ab57b74b1a63dc5775650699a3ec032ec0065005eff1f020818742b7312a8426"}, "twinkle_star": {:git, "https://github.com/bonfire-networks/twinkle_star", "627a29bc426313c4d680803792b77eb8921c4e9d", []},