Skip to content

Commit f6a60ac

Browse files
committed
[Recognizer] Setup Recognizer CD
1 parent 395f5dc commit f6a60ac

File tree

9 files changed

+150
-7
lines changed

9 files changed

+150
-7
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
app-name:
5+
required: true
6+
type: string
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
11+
jobs:
12+
build-publish-image:
13+
name: "Build and publish image"
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout the code
17+
uses: actions/checkout@v4
18+
with:
19+
sparse-checkout: ${{ inputs.app-name }}
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v2
23+
24+
- name: Login to Container Registry
25+
uses: docker/login-action@v2
26+
with:
27+
registry: ${{ env.REGISTRY }}
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Extract metadata (tags, labels) for Docker
32+
id: meta
33+
uses: docker/metadata-action@v4
34+
with:
35+
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ inputs.app-name }}
36+
tags: type=match,pattern=${{ inputs.app-name }}-v(.*),group=1
37+
38+
- name: Build and push Docker image
39+
uses: docker/build-push-action@v4
40+
with:
41+
context: ./${{ inputs.app-name }}
42+
platforms: linux/amd64
43+
push: true
44+
tags: ${{ steps.meta.outputs.tags }}
45+
cache-from: type=gha
46+
cache-to: type=gha,mode=max
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
app-name:
5+
required: true
6+
type: string
7+
secrets:
8+
ssh-host:
9+
required: true
10+
ssh-username:
11+
required: true
12+
ssh-priv-key:
13+
required: true
14+
secret-key-base:
15+
required: true
16+
phx-host:
17+
required: true
18+
ice-port-range:
19+
required: true
20+
21+
jobs:
22+
deploy-image:
23+
name: Deploy image
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout the code
27+
uses: actions/checkout@v4
28+
with:
29+
sparse-checkout: ${{ inputs.app-name }}
30+
31+
- name: Run docker via remote SSH
32+
uses: appleboy/ssh-action@v1.0.3
33+
with:
34+
host: ${{ secrets.ssh-host }}
35+
username: ${{ secrets.ssh-username }}
36+
key: ${{ secrets.ssh-priv-key }}
37+
script: |
38+
export TAG=${{ github.ref_name }}
39+
export TAG=${TAG#*-v}
40+
docker stop ${{ inputs.app-name }}
41+
docker rm ${{ inputs.app-name }}
42+
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}
43+
docker image prune --all --force
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Recognizer CD
2+
3+
on:
4+
push:
5+
tags:
6+
- "recognizer-v*.*.*"
7+
8+
permissions:
9+
contents: read
10+
packages: write
11+
12+
jobs:
13+
build-publish-recognizer-image:
14+
name: "Build and publish Recognizer image"
15+
uses: ./.github/workflows/__CD__build-publish-image.yml
16+
with:
17+
app-name: recognizer
18+
deploy-recognizer:
19+
name: "Deploy Recognizer image"
20+
needs: build-publish-recognizer-image
21+
uses: ./.github/workflows/__CD__deploy-image.yml
22+
with:
23+
app-name: recognizer
24+
secrets:
25+
ssh-host: ${{ secrets.RECOGNIZER_SSH_HOST }}
26+
ssh-username: ${{ secrets.RECOGNIZER_SSH_USERNAME }}
27+
ssh-priv-key: ${{ secrets.RECOGNIZER_SSH_PRIV_KEY }}
28+
secret-key-base: ${{ secrets.RECOGNIZER_SECRET_KEY_BASE }}
29+
phx-host: ${{ secrets.RECOGNIZER_PHX_HOST }}
30+
ice-port-range: ${{ secrets.RECOGNIZER_ICE_PORT_RANGE }}

.github/workflows/ci.yml renamed to .github/workflows/__CI__all.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ permissions:
88
jobs:
99
build_check_recognizer:
1010
name: Recognizer CI
11-
uses: ./.github/workflows/build-check-app.yml
11+
uses: ./.github/workflows/__CI__build-check-app.yml
1212
with:
1313
workdir: recognizer
1414
with-ffmpeg: true
1515

1616
build_check_broadcaster:
1717
name: Broadcaster CI
18-
uses: ./.github/workflows/build-check-app.yml
18+
uses: ./.github/workflows/__CI__build-check-app.yml
1919
with:
2020
workdir: broadcaster
2121

2222
build_check_nexus:
2323
name: Nexus CI
24-
uses: ./.github/workflows/build-check-app.yml
24+
uses: ./.github/workflows/__CI__build-check-app.yml
2525
with:
2626
workdir: nexus

recognizer/config/runtime.exs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,26 @@ import Config
1616
#
1717
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
1818
# script that automatically sets the env var above.
19+
20+
read_ice_port_range! = fn ->
21+
case System.get_env("ICE_PORT_RANGE") do
22+
nil ->
23+
[0]
24+
25+
raw_port_range ->
26+
case String.split(raw_port_range, "-", parts: 2) do
27+
[from, to] -> String.to_integer(from)..String.to_integer(to)
28+
_other -> raise "ICE_PORT_RANGE has to be in form of FROM-TO, passed: #{raw_port_range}"
29+
end
30+
end
31+
end
32+
1933
if System.get_env("PHX_SERVER") do
2034
config :recognizer, RecognizerWeb.Endpoint, server: true
2135
end
2236

37+
config :recognizer, ice_port_range: read_ice_port_range!.()
38+
2339
if config_env() == :prod do
2440
# The secret key base is used to sign/encrypt cookies and other secrets.
2541
# A default value is used in config/dev.exs and config/test.exs but you

recognizer/lib/recognizer/room.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ defmodule Recognizer.Room do
5959
@impl true
6060
def handle_call({:connect, channel_pid}, _from, %{channel: nil} = state) do
6161
Process.monitor(channel_pid)
62-
{:ok, pc} = PeerConnection.start_link(video_codecs: @video_codecs)
62+
63+
ice_port_range = Application.fetch_env!(:recognizer, :ice_port_range)
64+
65+
{:ok, pc} =
66+
PeerConnection.start_link(
67+
video_codecs: @video_codecs,
68+
ice_port_range: ice_port_range
69+
)
6370

6471
state =
6572
state

recognizer/mix.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Recognizer.MixProject do
44
def project do
55
[
66
app: :recognizer,
7-
version: "0.1.0",
7+
version: "0.1.0-dev",
88
elixir: "~> 1.14",
99
elixirc_paths: elixirc_paths(Mix.env()),
1010
start_permanent: Mix.env() == :prod,
@@ -52,7 +52,8 @@ defmodule Recognizer.MixProject do
5252
{:jason, "~> 1.2"},
5353
{:dns_cluster, "~> 0.1.1"},
5454
{:plug_cowboy, "~> 2.5"},
55-
{:ex_webrtc, "~> 0.3.0"},
55+
# {:ex_webrtc, "~> 0.3.0"},
56+
{:ex_webrtc, github: "elixir-webrtc/ex_webrtc", branch: "ice-port-range", override: true},
5657
{:ex_webrtc_dashboard, "~> 0.3.0"},
5758
{:xav, "~> 0.4.0"},
5859
{:bumblebee, "~> 0.5.3"},

recognizer/mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"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"},
2828
"ex_stun": {:hex, :ex_stun, "0.2.0", "feb1fc7db0356406655b2a617805e6c712b93308c8ea2bf0ba1197b1f0866deb", [:mix], [], "hexpm", "1e01ba8290082ccbf37acaa5190d1f69b51edd6de2026a8d6d51368b29d115d0"},
2929
"ex_turn": {:hex, :ex_turn, "0.1.0", "177405aadf3d754567d0d37cf881a83f9cacf8f45314d188633b04c4a9e7c1ec", [:mix], [{:ex_stun, "~> 0.2.0", [hex: :ex_stun, repo: "hexpm", optional: false]}], "hexpm", "d677737fb7d45274d5dac19fe3c26b9038b6effbc0a6b3e7417bccc76b6d1cd3"},
30-
"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"},
30+
"ex_webrtc": {:git, "https://github.com/elixir-webrtc/ex_webrtc.git", "3d6edd7612f2d90258da4faf1ee397775048459d", [branch: "ice-port-range"]},
3131
"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"},
3232
"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"},
3333
"expo": {:hex, :expo, "0.5.2", "beba786aab8e3c5431813d7a44b828e7b922bfa431d6bfbada0904535342efe2", [:mix], [], "hexpm", "8c9bfa06ca017c9cb4020fabe980bc7fdb1aaec059fd004c2ab3bff03b1c599c"},

0 commit comments

Comments
 (0)