Slink notes
Mix.install([
{:kino, "~> 0.16.0"},
{:kino_db, "~> 0.3.0"},
{:postgrex, "~> 0.18"},
{:kino_explorer, "~> 0.1.20"},
{:merquery, "~> 0.3.0"}
])
Knonw bugs
- unspport non chrome-extension://xxxx like non-http links in code
Test accounts
ref test/support/fixtures.ex
- a1@b.c / 123456123456
- adm1@b.c / same above for adminers
Node info
%{
node: Node.self,
cookie: Node.get_cookie(),
nodes: Node.list
} |> Kino.Tree.new()
Local app links
Remote execution
in slink project run:
node6:
env:
# RELEASE_DISTRIBUTION: name
ERL_AFLAGS: "-proto_dist inet6_tcp -kernel shell_history enabled"
cmds:
- |
iex --name slink@::1 --cookie slink -S mix
require Kino.RPC
node = :"slink@::1"
Node.set_cookie(node, :slink)
Kino.RPC.eval_string(node, ~S"Slink.Links.Link.first", file: __ENV__.file)
DB explore
opts = [
hostname: "localhost",
port: 5432,
username: "postgres",
password: "postgres",
database: "slink_dev"
]
{:ok, local_conn} = Kino.start_child({Postgrex, opts})
local_links =
Postgrex.query!(local_conn, ~S"select * from links order by id desc limit 5", [])
Flyio app links
- https://slink.fly.dev
- http://slink.internal:8080/api/ping
- fly dig AAAA slink.internal
API requests
req =
Req.new(
method: :get,
url: "http://slink.internal:8080/api/ping",
headers: %{},
params: %{"http://slink.internal:8080/api/ping" => ""}
)
req = Req.merge(req, inet6: true)
{req, flyio_resp} = Req.request(req)
flyio_resp.body|>Kino.Tree.new()
DB connection
使用fly 6PN地址,如 shareup-db.internal
- 注意开启IPv6开关
opts = [
hostname: "shareup-db.internal",
port: 5432,
username: "slink",
password: System.fetch_env!("LB_FLY_SLINK_DB_PASSWORD"),
database: "slink",
socket_options: [:inet6]
]
{:ok, flyio_conn} = Kino.start_child({Postgrex, opts})
flyio_links =
Postgrex.query!(
flyio_conn,
~S"select * from links order by updated_at desc limit 3",
[]
)
Remote execution
- http://[fdaa:2:686c:a7b:17c:2499:7edf:2]:8080/api/ping
- s@fdaa:2:686c:a7b:17c:2499:7edf:2
- s@slink.internal
- e82d339f725618.vm.slink.internal
req =
Req.new(
method: :get,
url: "http://slink.internal:8080/api/ping",
headers: %{},
params: %{"http://slink.internal:8080/api/ping" => ""}
)
req = Req.merge(req, inet6: true)
{req, flyio_resp} = Req.request(req)
flyio_resp.body |> Kino.Tree.new
Below remote-execution require local livebook running in inet6 mode, like
node6:
env:
LIVEBOOK_DISTRIBUTION: name
# Note: should use inet6 when connect to Flyio app?
LIVEBOOK_NODE: "lv@::1"
LIVEBOOK_COOKIE: "livebook"
ERL_AFLAGS: "-proto_dist inet6_tcp -kernel shell_history enabled"
cmds:
- |
iex -S mix phx.server
require Kino.RPC
node = :"slink@slink.internal"
Node.set_cookie(node, :slinkfuncookie)
ss = Kino.RPC.eval_string(node, ~S"Slink.Links.Link.last", file: __ENV__.file)