From 763875f2aef85b1438d073cd1d3145b8d527fe53 Mon Sep 17 00:00:00 2001 From: Maksym Sobolyev Date: Wed, 10 Jul 2024 21:13:50 -0700 Subject: [PATCH] Add simple build system. --- .github/workflows/build.yml | 73 +++++++++++++++++++++++++++++++++++++ Dockerfile | 20 ++++++++++ build.sh | 25 +++++++++++++ openssl.cnf | 22 +++++++++++ patches/SIP.js.diff | 13 +++++++ run.sh | 35 ++++++++++++++++++ 6 files changed, 188 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile create mode 100755 build.sh create mode 100644 openssl.cnf create mode 100644 patches/SIP.js.diff create mode 100755 run.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..824c770 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,73 @@ +name: Build Docker image + +# Controls when the action will run. +on: + # Triggers the workflow on all push or pull request events + push: + pull_request: + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + + schedule: + - cron: "0 0 * * *" + +# added using https://github.com/step-security/secure-repo +permissions: + contents: read + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + Docker: + name: Build&Push to DockerHub + runs-on: ubuntu-latest + env: + DOCKER_REPO: sippylabs/webrtc_phone + PLATFORMS: linux/amd64 #,linux/i386,linux/arm/v7,linux/arm64 + BASE_IMAGE: sippylabs/rtpproxy:RFC5245_ICE + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v3 + with: + platforms: arm64,arm + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.DOCKER_REPO }} + tags: | + type=schedule + type=ref,event=branch + type=ref,event=tag + type=ref,event=pr + type=raw,value=latest,enable={{is_default_branch}} + type=sha + + - name: Build Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + build-args: BASE_IMAGE=${{ env.BASE_IMAGE }} + push: true + tags: | + ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ env.PLATFORMS }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..08ad653 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +ARG BASE_IMAGE +FROM --platform=$TARGETPLATFORM $BASE_IMAGE as build +LABEL maintainer="Maksym Sobolyev " + +USER root + +# Set Environment Variables +ENV DEBIAN_FRONTEND=noninteractive + +WORKDIR /webrtc_phone +COPY . /webrtc_phone/ + +# Build & install everything +RUN /webrtc_phone/build.sh + +EXPOSE 443 +EXPOSE 9876 +EXPOSE 32000-34000/udp + +ENTRYPOINT [ "/webrtc_phone/run.sh" ] diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..0ee9623 --- /dev/null +++ b/build.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +set -x +set -e + +apt-get -y update -qq +apt-get -y install git python-is-python3 python3-pip npm + +git clone -b RFC7118 https://github.com/sippy/b2bua +git clone https://github.com/onsip/SIP.js.git + +python3 -m pip install --break-system-packages -U -r b2bua/requirements.txt + +git -C SIP.js apply "`pwd`/patches/SIP.js.diff" +cd SIP.js/demo +npm install +npm run build-demo +cd - +npm install http-server + +openssl req -newkey rsa:2048 -nodes -keyout server.key -x509 -days 365 -out server.crt -config openssl.cnf + +apt-get -y remove git +apt-get -y autoremove +apt-get -y clean diff --git a/openssl.cnf b/openssl.cnf new file mode 100644 index 0000000..b06fd4f --- /dev/null +++ b/openssl.cnf @@ -0,0 +1,22 @@ +[req] +default_bits = 2048 +prompt = no +default_md = sha256 +distinguished_name = dn +x509_extensions = v3_req +req_extensions = v3_req + +[dn] +C = US +ST = California +L = San Francisco +O = My Company +OU = My Division +CN = localhost +emailAddress = email@example.com + +[v3_req] +subjectAltName = @alt_names + +[alt_names] +DNS.1 = localhost diff --git a/patches/SIP.js.diff b/patches/SIP.js.diff new file mode 100644 index 0000000..b8e0bd7 --- /dev/null +++ b/patches/SIP.js.diff @@ -0,0 +1,13 @@ +diff --git a/demo/demo-1.ts b/demo/demo-1.ts +index ffc09dbd..79ca0bae 100644 +--- a/demo/demo-1.ts ++++ b/demo/demo-1.ts +@@ -16,7 +16,7 @@ const holdCheckbox = getInput("hold"); + const muteCheckbox = getInput("mute"); + + // WebSocket Server URL +-const webSocketServer = "wss://edge.sip.onsip.com"; ++const webSocketServer = `wss://${window.location.hostname}:9876`; + serverSpan.innerHTML = webSocketServer; + + // Destination URI diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..a390600 --- /dev/null +++ b/run.sh @@ -0,0 +1,35 @@ +#!/usr/bin/bash + +set -e +set -x + +CFILE="/webrtc_phone/server.crt" +KFILE="/webrtc_phone/server.key" +WROOT="/webrtc_phone/SIP.js/demo" +PNUM=443 +MIN_RTP_PORT=32000 +MAX_RTP_PORT=34000 +OUTBOUND_ROUTE="${OUTBOUND_ROUTE:-"0100@192.168.23.52;auth=nopass"}" + +RSOCK="/webrtc_phone/rtpproxy.sock" +RLLVL="dbug" +RMODDIR="/usr/local/lib/rtpproxy" + +BDIR="/webrtc_phone/b2bua" + +npm exec -- http-server -S -C "${CFILE}" -K "${KFILE}" -p ${PNUM} "${WROOT}" & +HSERV_PID="${!}" + +/usr/local/bin/rtpproxy_debug -f -F -s "${RSOCK}" \ + --dso "${RMODDIR}/rtpp_ice_lite_debug.so" \ + --dso "${RMODDIR}/rtpp_dtls_gw_debug.so" \ + -d "${RLLVL}" -m "${MIN_RTP_PORT}" -M "${MAX_RTP_PORT}" & +RTPP_PID="${!}" + +PYTHONPATH="${BDIR}" python "${BDIR}/sippy/b2bua_radius.py" \ + --auth_enable=off --acct_enable=off --static_route="${OUTBOUND_ROUTE}" \ + -f --b2bua_socket=/tmp/b.sock --rtp_proxy_clients="${RSOCK}" \ + --allowed_pts=0,8,9,126,101 --wss_socket="0.0.0.0:9876:${CFILE}:${KFILE}" & +B2B_PID="${!}" + +wait -n