Skip to content

Commit

Permalink
chg: [deploying] some clustering experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
gallypette committed Jun 9, 2023
1 parent 24cae70 commit e643483
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 23 deletions.
20 changes: 20 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ config :fun_with_flags, :cache_bust_notifications,
adapter: FunWithFlags.Notifications.PhoenixPubSub,
client: Cocktailparty.PubSub

config :libcluster,
debug: true,
topologies: [
gossip: [
strategy: Elixir.Cluster.Strategy.Gossip,
config: [
port: 45892,
if_addr: "0.0.0.0",
multicast_addr: "255.255.255.255",
broadcast_only: true,
secret: "thisismypassword"
]
]
]

# Setting defaults
config :cocktailparty,
standalone: true,
broker: true

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"
21 changes: 19 additions & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,24 @@ if config_env() == :prod do
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
# Configure your redis connection

redis_uri = System.get_env("REDIS_URI") || "redis://127.0.0.1:6379/0"
standalone =
case System.get_env("STANDALONE") || true do
"true" -> true
"false" -> false
nil -> true
end

broker =
case System.get_env("BROKER") || true do
"true" -> true
"false" -> false
nil -> true
end

config :cocktailparty,
redix_uri: redis_uri
redix_uri: System.get_env("REDIS_URI") || "redis://127.0.0.1:6379/0",
# won't start libcluster unless this is true
standalone: standalone,
# won't start the broker and redis connection unless this is true
broker: broker
end
57 changes: 37 additions & 20 deletions lib/cocktailparty/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,39 @@ defmodule Cocktailparty.Application do

@impl true
def start(_type, _args) do
children = [
# Start the Telemetry supervisor
CocktailpartyWeb.Telemetry,
# Start the Ecto repository
Cocktailparty.Repo,
# Start the PubSub system
{Phoenix.PubSub, name: Cocktailparty.PubSub},
# Start Finch
{Finch, name: Cocktailparty.Finch},
# Start the Endpoint (http/https)
CocktailpartyWeb.Endpoint,
# Start a worker by calling: Cocktailparty.Worker.start_link(arg)
# {Cocktailparty.Worker, arg}
# Redis connection
{Redix, {Application.get_env(:cocktailparty, :redix_uri), [name: :redix]}},
# Fun with Flags
FunWithFlags.Supervisor,
# Start the Broker once the application is started
Cocktailparty.Broker
]
# Common children
children =
[
# Start the Telemetry supervisor
CocktailpartyWeb.Telemetry,
# Start the Ecto repository
Cocktailparty.Repo,
# Start the PubSub system
{Phoenix.PubSub, name: Cocktailparty.PubSub},
# Start Finch
{Finch, name: Cocktailparty.Finch},
# Start the Endpoint (http/https)
CocktailpartyWeb.Endpoint,
# Start a worker by calling: Cocktailparty.Worker.start_link(arg)
# {Cocktailparty.Worker, arg}
# Fun with Flags
FunWithFlags.Supervisor
]
|> append_if_true(
!Application.get_env(:cocktailparty, :standalone),
{Cluster.Supervisor,
[Application.get_env(:libcluster, :topologies), [name: Cocktailparty.ClusterSupervisor]]}
)
|> append_if_true(
Application.get_env(:cocktailparty, :standalone) ||
Application.get_env(:cocktailparty, :broker),
{Redix, {Application.get_env(:cocktailparty, :redix_uri), [name: :redix]}}
)
|> append_if_true(
Application.get_env(:cocktailparty, :standalone) ||
Application.get_env(:cocktailparty, :broker),
Cocktailparty.Broker
)

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
Expand All @@ -41,4 +54,8 @@ defmodule Cocktailparty.Application do
CocktailpartyWeb.Endpoint.config_change(changed, removed)
:ok
end

defp append_if_true(list, cond, extra) do
if cond, do: list ++ [extra], else: list
end
end
4 changes: 3 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ defmodule Cocktailparty.MixProject do
{:redix, "~>1.2.2"},
# runtime: false because we don't want to start the FunWithFlags.Supervisor automatically
{:fun_with_flags, "~> 1.10.1", runtime: false},
{:fun_with_flags_ui, "~> 0.8.1", runtime: false}
{:fun_with_flags_ui, "~> 0.8.1", runtime: false},
# Libcluster
{:libcluster, "~> 3.3"}
]
end

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"gettext": {:hex, :gettext, "0.22.1", "e7942988383c3d9eed4bdc22fc63e712b655ae94a672a27e4900e3d4a2c43581", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "ad105b8dab668ee3f90c0d3d94ba75e9aead27a62495c101d94f2657a190ac5d"},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
"libcluster": {:hex, :libcluster, "3.3.2", "84c6ebfdc72a03805955abfb5ff573f71921a3e299279cc3445445d5af619ad1", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8b691ce8185670fc8f3fc0b7ed59eff66c6889df890d13411f8f1a0e6871d8a5"},
"mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"},
"mint": {:hex, :mint, "1.5.1", "8db5239e56738552d85af398798c80648db0e90f343c8469f6c6d8898944fb6f", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "4a63e1e76a7c3956abd2c72f370a0d0aecddc3976dea5c27eccbecfa5e7d5b1e"},
"nimble_options": {:hex, :nimble_options, "1.0.2", "92098a74df0072ff37d0c12ace58574d26880e522c22801437151a159392270e", [:mix], [], "hexpm", "fd12a8db2021036ce12a309f26f564ec367373265b53e25403f0ee697380f1b8"},
Expand Down
Empty file modified scripts/launch.sh
100644 → 100755
Empty file.
Empty file modified scripts/release.sh
100644 → 100755
Empty file.

0 comments on commit e643483

Please sign in to comment.