From 6e669902556843d774ef2a51b041771fdf40cfea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=9Aled=C5=BA?= Date: Thu, 23 May 2024 14:58:19 +0200 Subject: [PATCH] Read JF_DIST_* env vars. Remove divo. (#205) --- config/config.exs | 4 --- config/{ci.exs => test_cluster.exs} | 0 docker-compose-dns.yaml | 2 +- docker-compose-epmd.yaml | 2 +- lib/fishjam/application.ex | 7 ++++- mix.exs | 20 +++++------- mix.lock | 2 -- openapi.yaml | 2 +- rel/env.sh.eex | 22 ++++++++++--- test/fishjam/cluster/load_balancing_test.exs | 33 ++++++++------------ 10 files changed, 46 insertions(+), 48 deletions(-) rename config/{ci.exs => test_cluster.exs} (100%) diff --git a/config/config.exs b/config/config.exs index 786c8080..1db072c3 100644 --- a/config/config.exs +++ b/config/config.exs @@ -37,10 +37,6 @@ config :logger, [application: :membrane_rtc_engine_sip, level_lower_than: :warning] ] -config :fishjam, - divo: "docker-compose.yaml", - divo_wait: [dwell: 1_500, max_tries: 50] - config :ex_aws, http_client: Fishjam.Component.HLS.HTTPoison, normalize_path: false diff --git a/config/ci.exs b/config/test_cluster.exs similarity index 100% rename from config/ci.exs rename to config/test_cluster.exs diff --git a/docker-compose-dns.yaml b/docker-compose-dns.yaml index 1b7af457..97ed1f14 100644 --- a/docker-compose-dns.yaml +++ b/docker-compose-dns.yaml @@ -18,7 +18,7 @@ services: - | cd app/ mix deps.get - MIX_ENV=ci mix test --only cluster + MIX_ENV=test_cluster mix test --only cluster volumes: - .:/app - /app/_build diff --git a/docker-compose-epmd.yaml b/docker-compose-epmd.yaml index e60c521f..12f8e028 100644 --- a/docker-compose-epmd.yaml +++ b/docker-compose-epmd.yaml @@ -17,7 +17,7 @@ services: - | cd app/ mix deps.get - MIX_ENV=ci mix test --only cluster + MIX_ENV=test_cluster mix test --only cluster volumes: - .:/app - /app/_build diff --git a/lib/fishjam/application.ex b/lib/fishjam/application.ex index 0092e9bd..4560ac4c 100644 --- a/lib/fishjam/application.ex +++ b/lib/fishjam/application.ex @@ -87,7 +87,12 @@ defmodule Fishjam.Application do # When running FJ not in a cluster and using # mix release, it starts in the distributed mode # automatically - unless Node.alive?() do + if Node.alive?() do + Logger.info(""" + Not starting Fishjam node as it is already alive. \ + Node name: #{Node.self()}.\ + """) + else case Node.start(dist_config[:node_name], dist_config[:mode]) do {:ok, _} -> :ok diff --git a/mix.exs b/mix.exs index 1f4d44b8..ba15795a 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Fishjam.MixProject do def project do [ app: :fishjam, - version: "0.6.2", + version: "0.6.3", elixir: "~> 1.14", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, @@ -22,9 +22,7 @@ defmodule Fishjam.MixProject do "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test, - "coveralls.json": :test, - "test.cluster": :test, - "test.cluster.ci": :test + "coveralls.json": :test ] ] end @@ -40,7 +38,7 @@ defmodule Fishjam.MixProject do end # Specifies which paths to compile per environment. - defp elixirc_paths(env) when env in [:test, :ci], do: ["lib", "test/support"] + defp elixirc_paths(env) when env in [:test, :test_cluster], do: ["lib", "test/support"] defp elixirc_paths(_env), do: ["lib"] defp deps do @@ -94,12 +92,9 @@ defmodule Fishjam.MixProject do {:klotho, "~> 0.1.0"}, # Test deps - {:websockex, "~> 0.4.3", only: [:test, :ci], runtime: false}, + {:websockex, "~> 0.4.3", only: [:test, :test_cluster], runtime: false}, {:excoveralls, "~> 0.15.0", only: :test, runtime: false}, - {:mox, "~> 1.0", only: [:test, :ci]}, - - # Load balancing tests - {:divo, "~> 1.3.1", only: [:test, :ci]} + {:mox, "~> 1.0", only: [:test, :test_cluster]} ] end @@ -108,11 +103,10 @@ defmodule Fishjam.MixProject do setup: ["deps.get"], "api.spec": &generate_api_spec/1, test: ["test --exclude cluster"], - "test.cluster": ["test --only cluster"], - "test.cluster.ci": [ + "test.cluster.epmd": [ "cmd docker compose -f docker-compose-epmd.yaml up test; docker compose -f docker-compose-epmd.yaml down" ], - "test.cluster.dns.ci": [ + "test.cluster.dns": [ "cmd docker compose -f docker-compose-dns.yaml up test; docker compose -f docker-compose-dns.yaml down" ] ] diff --git a/mix.lock b/mix.lock index e8ef3e49..0856c6d3 100644 --- a/mix.lock +++ b/mix.lock @@ -15,7 +15,6 @@ "crc": {:hex, :crc, "0.10.5", "ee12a7c056ac498ef2ea985ecdc9fa53c1bfb4e53a484d9f17ff94803707dfd8", [:mix, :rebar3], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "3e673b6495a9525c5c641585af1accba59a1eb33de697bedf341e247012c2c7f"}, "credo": {:hex, :credo, "1.7.5", "643213503b1c766ec0496d828c90c424471ea54da77c8a168c725686377b9545", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "f799e9b5cd1891577d8c773d245668aa74a2fcd15eb277f51a0131690ebfb3fd"}, "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, - "divo": {:hex, :divo, "1.3.2", "3a5ce880a1fe930ea804361d1b57b5144129e79e1c856623d923a6fab6d539a1", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:patiently, "~> 0.2", [hex: :patiently, repo: "hexpm", optional: false]}], "hexpm", "4bd035510838959709db2cacd28edd2eda7948d0e7f1b0dfa810a134c913a88a"}, "elixir_make": {:hex, :elixir_make, "0.8.3", "d38d7ee1578d722d89b4d452a3e36bcfdc644c618f0d063b874661876e708683", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "5c99a18571a756d4af7a4d89ca75c28ac899e6103af6f223982f09ce44942cc9"}, "elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, @@ -101,7 +100,6 @@ "open_api_spex": {:hex, :open_api_spex, "3.18.3", "fefb84fe323cacfc92afdd0ecb9e89bc0261ae00b7e3167ffc2028ce3944de42", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :poison, repo: "hexpm", optional: true]}, {:ymlr, "~> 2.0 or ~> 3.0 or ~> 4.0 or ~> 5.0", [hex: :ymlr, repo: "hexpm", optional: true]}], "hexpm", "c0cfc31570199ce7e7520b494a591027da609af45f6bf9adce51e2469b1609fb"}, "p1_utils": {:hex, :p1_utils, "1.0.23", "7f94466ada69bd982ea7bb80fbca18e7053e7d0b82c9d9e37621fa508587069b", [:rebar3], [], "hexpm", "47f21618694eeee5006af1c88731ad86b757161e7823c29b6f73921b571c8502"}, "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, - "patiently": {:hex, :patiently, "0.2.0", "67eb139591e10c4b363ae0198e832552f191c58894731efd3bf124ec4722267a", [:mix], [], "hexpm", "c08cc5edc27def565647a9b55a0bea8025a5f81a4472e57692f28f2292c44c94"}, "phoenix": {:hex, :phoenix, "1.7.12", "1cc589e0eab99f593a8aa38ec45f15d25297dd6187ee801c8de8947090b5a9d3", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.7", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "d646192fbade9f485b01bc9920c139bfdd19d0f8df3d73fd8eaf2dfbe0d2837c"}, "phoenix_html": {:hex, :phoenix_html, "3.3.3", "380b8fb45912b5638d2f1d925a3771b4516b9a78587249cabe394e0a5d579dc9", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "923ebe6fec6e2e3b3e569dfbdc6560de932cd54b000ada0208b5f45024bdd76c"}, "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.7.2", "97cc4ff2dba1ebe504db72cb45098cb8e91f11160528b980bd282cc45c73b29c", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.5", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.18.3", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6 or ~> 1.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "0e5fdf063c7a3b620c566a30fcf68b7ee02e5e46fe48ee46a6ec3ba382dc05b7"}, diff --git a/openapi.yaml b/openapi.yaml index dacfe1f2..5d0a784f 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -835,7 +835,7 @@ info: name: Apache 2.0 url: https://www.apache.org/licenses/LICENSE-2.0 title: Fishjam Media Server - version: 0.6.2 + version: 0.6.3 openapi: 3.0.0 paths: /health: diff --git a/rel/env.sh.eex b/rel/env.sh.eex index 936e04cf..73a7c4b2 100644 --- a/rel/env.sh.eex +++ b/rel/env.sh.eex @@ -2,7 +2,7 @@ # those provided by mix release. # This is to have a unified way of configuring Fishjam distribution # in both development and production environments -if [ "$FJ_DIST_ENABLED" == "true" ]; then +if [[ "$FJ_DIST_ENABLED" == "true" || "$JF_DIST_ENABLED" == "true" ]]; then # If Fishjam is meant to be run in a cluster, # leave node setup to the Elixir code where # we do extra steps for DNS strategy to determine actual node name. @@ -18,20 +18,32 @@ if [ "$FJ_DIST_ENABLED" == "true" ]; then # In other case, when someone wants to expose only one port # (FJ_DIST_MIN_PORT==FJ_DIST_MAX_PORT), we won't be able to # connect to already running node with the `remote` command. - if [ "$FJ_DIST_MIN_PORT" != "" ]; then + if [[ "$FJ_DIST_MIN_PORT" != "" || "$JF_DIST_MIN_PORT" != "" ]]; then + if [ "$FJ_DIST_MIN_PORT" != "" ]; then + DIST_MIN_PORT="$FJ_DIST_MIN_PORT" + else + DIST_MIN_PORT="$JF_DIST_MIN_PORT" + fi + case $RELEASE_COMMAND in start* | daemon*) - ELIXIR_ERL_OPTIONS="$ELIXIR_ERL_OPTIONS -kernel inet_dist_listen_min $FJ_DIST_MIN_PORT" + ELIXIR_ERL_OPTIONS="$ELIXIR_ERL_OPTIONS -kernel inet_dist_listen_min $DIST_MIN_PORT" export ELIXIR_ERL_OPTIONS ;; *) ;; esac fi - if [ "$FJ_DIST_MAX_PORT" != "" ]; then + if [[ "$FJ_DIST_MAX_PORT" != "" || "$JF_DIST_MAX_PORT" != "" ]]; then + if [ "$FJ_DIST_MAX_PORT" != "" ]; then + DIST_MAX_PORT="$FJ_DIST_MAX_PORT" + else + DIST_MAX_PORT="$JF_DIST_MAX_PORT" + fi + case $RELEASE_COMMAND in start* | daemon*) - ELIXIR_ERL_OPTIONS="$ELIXIR_ERL_OPTIONS -kernel inet_dist_listen_max $FJ_DIST_MAX_PORT" + ELIXIR_ERL_OPTIONS="$ELIXIR_ERL_OPTIONS -kernel inet_dist_listen_max $DIST_MAX_PORT" export ELIXIR_ERL_OPTIONS ;; *) ;; diff --git a/test/fishjam/cluster/load_balancing_test.exs b/test/fishjam/cluster/load_balancing_test.exs index 8d5ed654..0f9bdcd4 100644 --- a/test/fishjam/cluster/load_balancing_test.exs +++ b/test/fishjam/cluster/load_balancing_test.exs @@ -1,10 +1,10 @@ defmodule Fishjam.Cluster.LoadBalancingTest do @moduledoc false + # These tests can only be run with `mix test.cluster.epmd` or `mix test.cluster.dns`. + use ExUnit.Case, async: false - @node1 "localhost:4001" - @node2 "localhost:4002" @token Application.compile_env(:fishjam, :server_api_token) @headers [Authorization: "Bearer #{@token}", Accept: "Application/json; Charset=utf-8"] @@ -17,14 +17,11 @@ defmodule Fishjam.Cluster.LoadBalancingTest do @tag timeout: @max_test_duration test "spawning tasks on a cluster" do - [node1, node2] = - if Mix.env() == :ci do - # On CI we don't use Divo, because we don't want to run Docker in Docker - ["app1:4001", "app2:4002"] - else - Divo.Suite.start(services: [:app1, :app2]) |> on_exit() - [@node1, @node2] - end + if Mix.env() != :test_cluster do + raise "Load balancing tests can only be run with MIX_ENV=test_cluster" + end + + [node1, node2] = ["app1:4001", "app2:4002"] response_body1 = add_room(node1) @@ -70,16 +67,12 @@ defmodule Fishjam.Cluster.LoadBalancingTest do body end - if Mix.env() == :test do - defp map_fishjam_address(fishjam), do: fishjam - else - defp map_fishjam_address(fishjam) do - %{ - @node1 => "app1:4001", - @node2 => "app2:4002" - } - |> Map.get(fishjam) - end + defp map_fishjam_address(fishjam) do + %{ + "localhost:4001" => "app1:4001", + "localhost:4002" => "app2:4002" + } + |> Map.get(fishjam) end defp get_fishjam_address(response_body) do