diff --git a/Dockerfile b/Dockerfile index 1d407f99..4422d6d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,4 +58,4 @@ RUN mix phx.digest RUN script/restore-timestamps -CMD ["mix", "phx.server"] +CMD elixir --name ${NAME:=legendary}@$(hostname -f) -S mix phx.server diff --git a/apps/core/mix.exs b/apps/core/mix.exs index 40d979bf..02cba3b9 100644 --- a/apps/core/mix.exs +++ b/apps/core/mix.exs @@ -154,6 +154,7 @@ defmodule Legendary.Core.MixProject do {:telemetry_poller, "~> 0.4"}, {:gettext, "~> 0.11"}, {:jason, "~> 1.0"}, + {:libcluster, "~> 3.3"}, {:plug_cowboy, "~> 2.0"}, ] end diff --git a/config/config.exs b/config/config.exs index 5c477cc7..388cfaf6 100644 --- a/config/config.exs +++ b/config/config.exs @@ -73,6 +73,13 @@ config :app, crontab: [ ] +config :libcluster, + topologies: [ + local_epmd: [ + Elixir.Cluster.Strategy.LocalEpmd + ] + ] + import_config "email_styles.exs" import_config "admin.exs" diff --git a/config/prod.exs b/config/prod.exs index 959c290c..0b14a1fe 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -81,6 +81,17 @@ config :core, Legendary.CoreMailer, config :core, email_from: System.get_env("EMAIL_FROM") +config :libcluster, + topologies: [ + kubernetes: [ + strategy: Elixir.Cluster.Strategy.Kubernetes, + config: [ + mode: :ip, + kubernetes_node_basename: System.get_env("NAME", "legendary"), + kubernetes_selector: "app=#{System.get_env("NAME", "legendary")}", + kubernetes_namespace: System.get_env("NAMESPACE", "legendary"), + polling_interval: 10_000]]] + # ## Using releases (Elixir v1.9+) # # If you are doing OTP releases, you need to instruct Phoenix diff --git a/infrastructure/kube.yaml b/infrastructure/kube.yaml index 67f545b4..0f2d3440 100644 --- a/infrastructure/kube.yaml +++ b/infrastructure/kube.yaml @@ -28,6 +28,18 @@ spec: value: legendaryframework.org - name: EMAIL_FROM value: no-reply@legendaryframework.org + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP - name: DATABASE_URL valueFrom: secretKeyRef: diff --git a/infrastructure_templates/kube.yaml.dot b/infrastructure_templates/kube.yaml.dot index 07fb530d..da555131 100644 --- a/infrastructure_templates/kube.yaml.dot +++ b/infrastructure_templates/kube.yaml.dot @@ -28,6 +28,18 @@ spec: value: legendaryframework.org - name: EMAIL_FROM value: no-reply@legendaryframework.org + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP - name: DATABASE_URL valueFrom: secretKeyRef: diff --git a/mix.lock b/mix.lock index f6fd36f7..6aa2936b 100644 --- a/mix.lock +++ b/mix.lock @@ -39,6 +39,7 @@ "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, "kaffy": {:hex, :kaffy, "0.9.0", "bef34c9729f6a3af4d0dea8eede8bcb9e11371a83ac9a8b393991bce81839517", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.11", [hex: :phoenix_html, repo: "hexpm", optional: false]}], "hexpm", "d18ff57b8e68feb433aed11e71510cd357abc7034e75358af5deff7d0d4c6ed3"}, + "libcluster": {:hex, :libcluster, "3.3.0", "f7d45ff56d88e9fb4c30aee662480cbab69ebc0e7f7da4ad8d01b1e4f7492da8", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "ecdcdc88334ec8eb18b10a13a1d5f22a3319a970b5b1e66cfe71c7719a4ab6cc"}, "libring": {:hex, :libring, "1.5.0", "44313eb6862f5c9168594a061e9d5f556a9819da7c6444706a9e2da533396d70", [:mix], [], "hexpm", "04e843d4fdcff49a62d8e03778d17c6cb2a03fe2d14020d3825a1761b55bd6cc"}, "linguist": {:hex, :linguist, "0.3.1", "8ce81114691be8ef4a122e7f57bd1842bc96b1f5650b66b246d7035238cab69d", [:mix], [{:ex_cldr, "~> 2.0", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:yaml_elixir, "~> 2.0", [hex: :yaml_elixir, repo: "hexpm", optional: false]}], "hexpm", "5b06f97912e298f60dd00bc6a588b1fe1ec8838b268e4fdbf4443a25511f0614"}, "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},