Google Compute Engine Cluster Strategy
This Cluster Strategy can be used with libcluster to automatically connect nodes running on GCE instances within the same Instance Group.
You can follow the GCP tutorial for setting up an instance group for Elixir. Once up and running, this strategy uses the instance metadata HTTP endpoint and the Google Cloud API to discover other instances within the instance group and will automatically connect with any it finds.
Usage
Add the libclusetr_gcp_strategy package to your dependencies:
defp deps do
[
{:libcluster_gce_strategy, "~> 0.1"}
]
endand add the Cluster Supervisor to your application’s supervision tree.
defmodule MyApp.Application do
use Application
require Logger
def start(_type, _args) do
topologies = [
gce: [
strategy: Cluster.Strategy.GoogleComputeEngine,
config: [
release_name: :myapp
]
]
]
children = [
MyAppWeb.Endpoint,
{Cluster.Supervisor, [topologies, [name: Ding.ClusterSupervisor]]}
]
Supervisor.start_link(children, [strategy: :one_for_one, name: MyApp.Supervisor])
end
endNotes
This implementation was heavily influenced by the GAE Implementation by @alexgaribay.