Skip to content

Commit

Permalink
improvement: direct use dns_cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
cao7113 committed Jul 20, 2024
1 parent c8d0234 commit be30952
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 108 deletions.
1 change: 1 addition & 0 deletions Taskfile-fly-io.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tasks:
# Opening https://fly.io/apps/hello-phx-up
board: fly dashboard
# Add a dedicated ipv4 with: fly ips allocate-v4
ips: fly ip private

## DB
# fly checks list -a hello-phx-up-db
Expand Down
3 changes: 2 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ tasks:
lv-help: task lv-start -- --help
lv-install: mix archive.install hex livebook
# https://fly.io/docs/elixir/advanced-guides/clustering-from-home-to-your-app-in-fly/
lv-fly-remote: ./cluster-with-remote.sh
lv-fly-remote: run/cluster-with-remote.sh
dns-query: dig hello-phx-up.internal aaaa

## DB Setup
pgcli: pgcli postgresql://postgres:postgres@localhost:5433
Expand Down
28 changes: 14 additions & 14 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ if config_env() == :prod do
# app_name =
# System.get_env("FLY_APP_NAME") ||
# raise "FLY_APP_NAME not available"
if app_name =
System.get_env("FLY_APP_NAME") do
config :libcluster,
topologies: [
fly6pn: [
strategy: Cluster.Strategy.DNSPoll,
config: [
polling_interval: 5_000,
query: "#{app_name}.internal",
node_basename: app_name
]
]
]
end
# if app_name =
# System.get_env("FLY_APP_NAME") do
# config :libcluster,
# topologies: [
# fly6pn: [
# strategy: Cluster.Strategy.DNSPoll,
# config: [
# polling_interval: 5_000,
# query: "#{app_name}.internal",
# node_basename: app_name
# ]
# ]
# ]
# end

# ## SSL Support
#
Expand Down
39 changes: 20 additions & 19 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,30 @@ kill_signal = 'SIGTERM'
[build]

[deploy]
release_command = '/app/bin/migrate'
release_command = '/app/bin/migrate'

[env]
PHX_HOST = 'hello-phx-up.fly.dev'
PORT = '8080'
# https://fly.io/docs/elixir/getting-started/#important-ipv6-settings
ERL_AFLAGS = "-proto_dist inet6_tcp"
ECTO_IPV6 = "true"
RELEASE_COOKIE = "73TPJVMoeacSQ0uK-vyJOp4tL9dRYk2wmwq7tmHtaX0HWfl-59NWLw=="
PHX_HOST = 'hello-phx-up.fly.dev'
PORT = '8080'
# https://fly.io/docs/elixir/getting-started/#important-ipv6-settings
DNS_CLUSTER_QUERY=
ERL_AFLAGS = "-proto_dist inet6_tcp"
ECTO_IPV6 = "true"
RELEASE_COOKIE = "73TPJVMoeacSQ0uK-vyJOp4tL9dRYk2wmwq7tmHtaX0HWfl-59NWLw=="

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 1
processes = ['app']
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[http_service.concurrency]
type = 'connections'
hard_limit = 1000
soft_limit = 1000
[http_service.concurrency]
type = 'connections'
hard_limit = 1000
soft_limit = 1000

[[vm]]
size = 'shared-cpu-1x'
memory = "512mb"
size = 'shared-cpu-1x'
memory = "512mb"
4 changes: 2 additions & 2 deletions lib/hello_phx/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule HelloPhx.Application do

@impl true
def start(_type, _args) do
topologies = Application.get_env(:libcluster, :topologies) || []
# topologies = Application.get_env(:libcluster, :topologies) || []

children = [
HelloPhxWeb.Telemetry,
Expand All @@ -17,7 +17,7 @@ defmodule HelloPhx.Application do
# Start the Finch HTTP client for sending emails
{Finch, name: HelloPhx.Finch},
# setup for clustering
{Cluster.Supervisor, [topologies, [name: HelloPhx.ClusterSupervisor]]},
# {Cluster.Supervisor, [topologies, name: HelloPhx.ClusterSupervisor]},
# Start a worker by calling: HelloPhx.Worker.start_link(arg)
# {HelloPhx.Worker, arg},
# Start to serve requests, typically the last entry
Expand Down
2 changes: 1 addition & 1 deletion lib/hello_phx_web/controllers/page_html/home.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<% end %>
</p>
<p>
Mode: <%= HelloPhx.build_mode() %> || <%= HelloPhx.commit() |> inspect %> on v<%= HelloPhx.vsn() %> || Locale: <%= @locale %>
Mode: <%= HelloPhx.build_mode() %> || v<%= HelloPhx.vsn() %> commit at: <%= HelloPhx.commit().commit_time %> head: <%= HelloPhx.commit().commit_id |> String.slice(0, 6) %> || Locale: <%= @locale %>
</p>

<p class="text-[2rem] mt-4 font-semibold leading-10 tracking-tighter text-zinc-900 text-balance">
Expand Down
12 changes: 0 additions & 12 deletions lib/mix/tasks/gen.cookie.ex

This file was deleted.

4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ defmodule HelloPhx.MixProject do
# {:timex, "~> 3.7"},
{:git_ops, "~> 2.6", only: [:dev], runtime: false},

## cluster
{:libcluster, "~> 3.3"},
# ## cluster
# {:libcluster, "~> 3.3"},

# Graphing/charting - for Livebook or analysis
{:vega_lite, "~> 0.1.9"},
Expand Down
55 changes: 0 additions & 55 deletions mix.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions rel/env.sh.eex
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
# export RELEASE_DISTRIBUTION=name
# export RELEASE_NODE=<%= @release.name %>

## support libcluster on fly.io
## support cluster on fly.io
if [ -n "$FLY_APP_NAME" ]; then
echo "==>running app: ${FLY_APP_NAME} cluster on fly.io"
export RELEASE_DISTRIBUTION="name"
# ip=$(grep fly-local-6pn /etc/hosts | cut -f 1)
ip=$FLY_PRIVATE_IP
export RELEASE_NODE=$FLY_APP_NAME@$ip
# export RELEASE_NODE="${FLY_APP_NAME}-${FLY_IMAGE_REF##*-}@${FLY_PRIVATE_IP}"
# export DNS_CLUSTER_QUERY="${FLY_APP_NAME}.internal"
export DNS_CLUSTER_QUERY="${FLY_APP_NAME}.internal"
fi
File renamed without changes.

0 comments on commit be30952

Please sign in to comment.