Skip to content

Commit

Permalink
Read JF_DIST_* env vars. Remove divo. (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed May 23, 2024
1 parent fadf344 commit 6e66990
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 48 deletions.
4 changes: 0 additions & 4 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docker-compose-dns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-epmd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/fishjam/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 7 additions & 13 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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"
]
]
Expand Down
2 changes: 0 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 17 additions & 5 deletions rel/env.sh.eex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
;;
*) ;;
Expand Down
33 changes: 13 additions & 20 deletions test/fishjam/cluster/load_balancing_test.exs
Original file line number Diff line number Diff line change
@@ -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"]

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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6e66990

Please sign in to comment.