Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/__CD__build-publish-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
workflow_call:
inputs:
app-name:
required: true
type: string

env:
REGISTRY: ghcr.io

jobs:
build-publish-image:
name: "Build and publish image"
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4
with:
sparse-checkout: ${{ inputs.app-name }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ inputs.app-name }}
tags: type=match,pattern=${{ inputs.app-name }}-v(.*),group=1

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./${{ inputs.app-name }}
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
38 changes: 38 additions & 0 deletions .github/workflows/__CD__deploy-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
on:
workflow_call:
inputs:
app-name:
required: true
type: string
secrets:
ssh-host:
required: true
ssh-username:
required: true
ssh-priv-key:
required: true
secret-key-base:
required: true
phx-host:
required: true
ice-port-range:
required: true

jobs:
deploy-image:
name: Deploy image
runs-on: ubuntu-latest
steps:
- name: Run docker via remote SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.ssh-host }}
username: ${{ secrets.ssh-username }}
key: ${{ secrets.ssh-priv-key }}
script: |
export TAG=${{ github.ref_name }}
export TAG=${TAG#*-v}
docker stop ${{ inputs.app-name }}
docker rm ${{ inputs.app-name }}
docker run -d --restart unless-stopped --name ${{ inputs.app-name }} -e SECRET_KEY_BASE=${{ secrets.secret-key-base }} -e PHX_HOST=${{ secrets.phx-host }} -e ICE_PORT_RANGE=${{ secrets.ice-port-range }} --network host ghcr.io/elixir-webrtc/apps/${{ inputs.app-name }}:${TAG}
docker image prune --all --force
30 changes: 30 additions & 0 deletions .github/workflows/__CD__recognizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Recognizer CD

on:
push:
tags:
- "recognizer-v*.*.*"

permissions:
contents: read
packages: write

jobs:
build-publish-recognizer-image:
name: "Build and publish Recognizer image"
uses: ./.github/workflows/__CD__build-publish-image.yml
with:
app-name: recognizer
deploy-recognizer:
name: "Deploy Recognizer image"
needs: build-publish-recognizer-image
uses: ./.github/workflows/__CD__deploy-image.yml
with:
app-name: recognizer
secrets:
ssh-host: ${{ secrets.RECOGNIZER_SSH_HOST }}
ssh-username: ${{ secrets.RECOGNIZER_SSH_USERNAME }}
ssh-priv-key: ${{ secrets.RECOGNIZER_SSH_PRIV_KEY }}
secret-key-base: ${{ secrets.RECOGNIZER_SECRET_KEY_BASE }}
phx-host: ${{ secrets.RECOGNIZER_PHX_HOST }}
ice-port-range: ${{ secrets.RECOGNIZER_ICE_PORT_RANGE }}
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml → .github/workflows/__CI__all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ permissions:
jobs:
build_check_recognizer:
name: Recognizer CI
uses: ./.github/workflows/build-check-app.yml
uses: ./.github/workflows/__CI__build-check-app.yml
with:
workdir: recognizer
with-ffmpeg: true

build_check_broadcaster:
name: Broadcaster CI
uses: ./.github/workflows/build-check-app.yml
uses: ./.github/workflows/__CI__build-check-app.yml
with:
workdir: broadcaster

build_check_nexus:
name: Nexus CI
uses: ./.github/workflows/build-check-app.yml
uses: ./.github/workflows/__CI__build-check-app.yml
with:
workdir: nexus
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ jobs:
with:
node-version: 22

- name: Install libsrtp2
working-directory: .
run: |
sudo apt-get update
sudo apt-get install -y libsrtp2-dev

- name: Install FFmpeg development libraries
if: ${{ inputs.with-ffmpeg }}
working-directory: .
Expand Down
1 change: 0 additions & 1 deletion recognizer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20231009-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.16.0-erlang-26.2.1-debian-bullseye-20231009-slim

ARG ELIXIR_VERSION=1.17.2
ARG OTP_VERSION=27.0.1
ARG DEBIAN_VERSION=bookworm-20240701-slim
Expand Down
2 changes: 1 addition & 1 deletion recognizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Now you can visit [`localhost:5002`](http://localhost:5002) from your browser.

You can also run Recognizer using Docker.

Build an image:
Build an image (or use `ghcr.io/elixir-webrtc/apps/recognizer:latest`):

```
docker build -t recognizer .
Expand Down
16 changes: 16 additions & 0 deletions recognizer/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,26 @@ import Config
#
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
# script that automatically sets the env var above.

read_ice_port_range! = fn ->
case System.get_env("ICE_PORT_RANGE") do
nil ->
[0]

raw_port_range ->
case String.split(raw_port_range, "-", parts: 2) do
[from, to] -> String.to_integer(from)..String.to_integer(to)
_other -> raise "ICE_PORT_RANGE has to be in form of FROM-TO, passed: #{raw_port_range}"
end
end
end

if System.get_env("PHX_SERVER") do
config :recognizer, RecognizerWeb.Endpoint, server: true
end

config :recognizer, ice_port_range: read_ice_port_range!.()

if config_env() == :prod do
# The secret key base is used to sign/encrypt cookies and other secrets.
# A default value is used in config/dev.exs and config/test.exs but you
Expand Down
9 changes: 8 additions & 1 deletion recognizer/lib/recognizer/room.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ defmodule Recognizer.Room do
@impl true
def handle_call({:connect, channel_pid}, _from, %{channel: nil} = state) do
Process.monitor(channel_pid)
{:ok, pc} = PeerConnection.start_link(video_codecs: @video_codecs)

ice_port_range = Application.fetch_env!(:recognizer, :ice_port_range)

{:ok, pc} =
PeerConnection.start_link(
video_codecs: @video_codecs,
ice_port_range: ice_port_range
)

state =
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ defmodule RecognizerWeb.RoomController do
use RecognizerWeb, :controller

def room(conn, _params) do
render(conn, :room)
render(conn, :room, page_title: "Room")
end
end
1 change: 1 addition & 0 deletions recognizer/lib/recognizer_web/live/lobby_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ defmodule RecognizerWeb.LobbyLive do

{:error, :max_rooms, position} ->
Process.send_after(self(), :update_eta, @eta_update_interval_ms)
socket = assign(socket, page_title: "Lobby")
socket = assign(socket, position: position)
socket = assign(socket, eta: position * @session_time)
socket = assign(socket, last_check: System.monotonic_time(:millisecond))
Expand Down
1 change: 1 addition & 0 deletions recognizer/lib/recognizer_web/live/recognizer_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule RecognizerWeb.RecognizerLive do
end

def mount(_params, _session, socket) do
socket = assign(socket, :page_title, "Home")
{:ok, socket}
end

Expand Down
6 changes: 3 additions & 3 deletions recognizer/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Recognizer.MixProject do
def project do
[
app: :recognizer,
version: "0.1.0",
version: "0.1.0-dev",
elixir: "~> 1.14",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down Expand Up @@ -52,8 +52,8 @@ defmodule Recognizer.MixProject do
{:jason, "~> 1.2"},
{:dns_cluster, "~> 0.1.1"},
{:plug_cowboy, "~> 2.5"},
{:ex_webrtc, "~> 0.3.0"},
{:ex_webrtc_dashboard, "~> 0.3.0"},
{:ex_webrtc, github: "elixir-webrtc/ex_webrtc"},
{:ex_webrtc_dashboard, github: "elixir-webrtc/ex_webrtc_dashboard"},
{:xav, "~> 0.4.0"},
{:bumblebee, "~> 0.5.3"},
{:exla, "~> 0.7.1"},
Expand Down
4 changes: 2 additions & 2 deletions recognizer/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"ex_sdp": {:hex, :ex_sdp, "0.17.0", "4c50e7814f01f149c0ccf258fba8428f8567dffecf1c416ec3f6aaaac607a161", [:mix], [{:bunch, "~> 1.3", [hex: :bunch, repo: "hexpm", optional: false]}, {:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}], "hexpm", "c7fe0625902be2a835b5fe6834a189f7db7639d2625c8e9d8b3564e6d704145f"},
"ex_stun": {:hex, :ex_stun, "0.2.0", "feb1fc7db0356406655b2a617805e6c712b93308c8ea2bf0ba1197b1f0866deb", [:mix], [], "hexpm", "1e01ba8290082ccbf37acaa5190d1f69b51edd6de2026a8d6d51368b29d115d0"},
"ex_turn": {:hex, :ex_turn, "0.1.0", "177405aadf3d754567d0d37cf881a83f9cacf8f45314d188633b04c4a9e7c1ec", [:mix], [{:ex_stun, "~> 0.2.0", [hex: :ex_stun, repo: "hexpm", optional: false]}], "hexpm", "d677737fb7d45274d5dac19fe3c26b9038b6effbc0a6b3e7417bccc76b6d1cd3"},
"ex_webrtc": {:hex, :ex_webrtc, "0.3.0", "283f5b31d539f65238596793aabcefe32d221618ceb751ae68951712a486cac2", [:mix], [{:crc, "~> 0.10", [hex: :crc, repo: "hexpm", optional: false]}, {:ex_dtls, "~> 0.15.0", [hex: :ex_dtls, repo: "hexpm", optional: false]}, {:ex_ice, "~> 0.7.0", [hex: :ex_ice, repo: "hexpm", optional: false]}, {:ex_libsrtp, "~> 0.7.1", [hex: :ex_libsrtp, repo: "hexpm", optional: false]}, {:ex_rtcp, "~> 0.4.0", [hex: :ex_rtcp, repo: "hexpm", optional: false]}, {:ex_rtp, "~> 0.4.0", [hex: :ex_rtp, repo: "hexpm", optional: false]}, {:ex_sdp, "~> 0.17.0", [hex: :ex_sdp, repo: "hexpm", optional: false]}], "hexpm", "a8a4f38cdcacae170615d6abb83d8c42220b6ac0133d84b900f4994d5eff7143"},
"ex_webrtc_dashboard": {:hex, :ex_webrtc_dashboard, "0.3.0", "f38cc5847a6e7617b950119c46dd090b420c0be90a22113f37e51cd2056a3c19", [:mix], [{:ex_webrtc, "~> 0.3.0", [hex: :ex_webrtc, repo: "hexpm", optional: false]}, {:phoenix_live_dashboard, "~> 0.8.3", [hex: :phoenix_live_dashboard, repo: "hexpm", optional: false]}], "hexpm", "73ce31ee429c05455090443eb4d573bef5c69fbc170fb83825587eafbb04881e"},
"ex_webrtc": {:git, "https://github.com/elixir-webrtc/ex_webrtc.git", "ef355c055574f498afd448783d7fd510da7b4d20", []},
"ex_webrtc_dashboard": {:git, "https://github.com/elixir-webrtc/ex_webrtc_dashboard.git", "40b67a6399dab5eebaa0434edad74fbc747187bd", []},
"exla": {:hex, :exla, "0.7.3", "51310270a0976974fc758f7b28ebd6ca8e099b3d6fc78b0d484c808e977cb914", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:nx, "~> 0.7.1", [hex: :nx, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:xla, "~> 0.6.0", [hex: :xla, repo: "hexpm", optional: false]}], "hexpm", "5b3d5741a24aada21d3b0feb4b99d1fc3c8457f995a63ea16684d8d5678b96ff"},
"expo": {:hex, :expo, "0.5.2", "beba786aab8e3c5431813d7a44b828e7b922bfa431d6bfbada0904535342efe2", [:mix], [], "hexpm", "8c9bfa06ca017c9cb4020fabe980bc7fdb1aaec059fd004c2ab3bff03b1c599c"},
"file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
Expand Down