From fcca80d18538a4245588731e82f0e72aac41d5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=9Aled=C5=BA?= Date: Fri, 22 Sep 2023 12:36:24 +0200 Subject: [PATCH] Remove JF_HOST_PORT. Update comments in .env.sample. --- .env.sample | 52 ++++++++++----------------------------------- config/runtime.exs | 32 ++++++++++++++-------------- docker-compose.yaml | 3 ++- 3 files changed, 29 insertions(+), 58 deletions(-) diff --git a/.env.sample b/.env.sample index d0da0cf8..e541861f 100644 --- a/.env.sample +++ b/.env.sample @@ -1,46 +1,15 @@ -# JF_IP and JF_PORT defines ip and port -# our HTTP endpoint socket will listen to. -# The default for Docker builds is 0.0.0.0 to allow -# access from the outside of container. -# Note that this cannot be 127.0.0.1 as -# in Docker it only allows for traffic -# from within the container. -# For other builds, it is 127.0.0.1 not to -# accidentaly expose Jellyfish to the outside world -# when it runs behind some proxy like nginx. -# +# IP and PORT an HTTP endpoint will listen to # JF_IP=0.0.0.0 # JF_PORT=5002 -# JF_HOST and JF_HOST_PORT defines how Jellyfish -# should be seen from the outside. -# When you run Jellyfish behind proxy, your -# Jellyfish will run on 127.0.0.1 or 0.0.0.0 -# (see JF_IP and JF_PORT for more information) -# but you don't want to and in fact you can't -# use those addresses for generating URLs, or -# telling Jellyfish Client to which server instance it -# should connect to (when running Jellyfish in a cluster). -# That's why we have separate environment variables. -# -# Example -# -# You run Jellyfish on a machine with some public -# ip address `PUB_IP` and domain `DOMAIN`. -# You most likely want to provide the following -# configuration when running Jellyfish using Docker -# -# JF_HOST=$DOMAIN or $PUB_IP -# JF_HOST_PORT=443 -# JF_IP = 0.0.0.0 -# JF_PORT = 5002 -# -# JF_IP and JF_PORT are set by default -# so everything you need to set is JF_HOST and JF_HOST_PORT -# -JF_HOST=localhost -JF_HOST_PORT=443 +# Defines how Jellyfish is seen from the outside. +# It can be in one of the following forms: +# * ip:port +# * fqdn:port +# * fqdn +# By default, it is equal to "JF_IP:JF_PORT". +JF_HOST=localhost:5002 # JF_METRICS_IP=0.0.0.0 # JF_METRICS_PORT=9568 @@ -49,7 +18,7 @@ JF_HOST_PORT=443 JF_SERVER_API_TOKEN=jellyfish_docker_token # Used by the server e.g. to create client tokens. -# If not set, it will be generated +# If not set, it will be generated. # JF_SECRET_KEY_BASE=super-secret-key # Decide if jellyfish will check origin of requests @@ -71,6 +40,7 @@ JF_WEBRTC_USED=true # TURN default configuration # note: loopback address as INTEGRATED_TURN_IP cannot be used inside a Docker container +# note: when running locally, JF_INTEGRATED_TURN_IP can be your private ip address JF_INTEGRATED_TURN_IP= JF_INTEGRATED_TURN_LISTEN_IP=0.0.0.0 -JF_INTEGRATED_TURN_PORT_RANGE=50000-59_999 +JF_INTEGRATED_TURN_PORT_RANGE=50000-50050 diff --git a/config/runtime.exs b/config/runtime.exs index 2f35f58b..9d48fb21 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -35,14 +35,14 @@ port = host = case System.get_env("JF_HOST") do - nil -> :inet.ntoa(ip) |> to_string() + nil -> "#{:inet.ntoa(ip)}:#{port}" other -> other end -host_port = - case ConfigReader.read_port("JF_HOST_PORT") do - nil -> port - other -> other +{host_name, host_port} = + case String.split(host, ":") do + [host_name, host_port] -> {host_name, String.to_integer(host_port)} + _ -> {host, 443} end config :jellyfish, @@ -55,20 +55,10 @@ config :jellyfish, integrated_turn_tcp_port: ConfigReader.read_port("JF_INTEGRATED_TURN_TCP_PORT"), jwt_max_age: 24 * 3600, output_base_path: System.get_env("JF_OUTPUT_BASE_PATH", "jellyfish_output") |> Path.expand(), - address: "#{host}:#{host_port}", + address: "#{host}", metrics_ip: ConfigReader.read_ip("JF_METRICS_IP") || {127, 0, 0, 1}, metrics_port: ConfigReader.read_port("JF_METRICS_PORT") || 9568 -config :jellyfish, JellyfishWeb.Endpoint, - secret_key_base: - System.get_env("JF_SECRET_KEY_BASE") || Base.encode64(:crypto.strong_rand_bytes(48)), - http: [ip: ip, port: port], - url: [host: host, port: host_port] - -if check_origin = ConfigReader.read_boolean("JF_CHECK_ORIGIN") do - config :jellyfish, JellyfishWeb.Endpoint, check_origin: check_origin -end - case System.get_env("JF_SERVER_API_TOKEN") do nil when prod? == true -> raise """ @@ -84,6 +74,16 @@ case System.get_env("JF_SERVER_API_TOKEN") do config :jellyfish, server_api_token: token end +config :jellyfish, JellyfishWeb.Endpoint, + secret_key_base: + System.get_env("JF_SECRET_KEY_BASE") || Base.encode64(:crypto.strong_rand_bytes(48)), + http: [ip: ip, port: port], + url: [host: host_name, port: host_port] + +if check_origin = ConfigReader.read_boolean("JF_CHECK_ORIGIN") do + config :jellyfish, JellyfishWeb.Endpoint, check_origin: check_origin +end + if prod? do config :jellyfish, JellyfishWeb.Endpoint, url: [scheme: "https"] end diff --git a/docker-compose.yaml b/docker-compose.yaml index 6d24f71c..c58b38ff 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,7 +5,6 @@ x-jellyfish-template: &jellyfish-template environment: &jellyfish-environment ERLANG_COOKIE: "panuozzo-pollo-e-pancetta" JF_SERVER_API_TOKEN: "development" - JF_HOST: "localhost" JF_NODES: "app@app1 app@app2" networks: - net1 @@ -37,6 +36,7 @@ services: <<: *jellyfish-environment RELEASE_NODE: app@app1 NODE_NAME: app@app1 + JF_HOST: "localhost:4001" JF_PORT: 4001 ports: - 4001:4001 @@ -47,6 +47,7 @@ services: <<: *jellyfish-environment RELEASE_NODE: app@app2 NODE_NAME: app@app2 + JF_HOST: "localhost:4002" JF_PORT: 4002 ports: - 4002:4002