Skip to content

Commit 2a8f062

Browse files
authored
Build Janus Debian package via dedicated repo (#1)
* Build Janus Debian package. * Add leading v to Janus branch name. * Refactor PKG_BUILD_NUMBER. * Add leading v to Janus branch name. * Fix Janus clone. * Fix README clone instructions.
1 parent 0ec783b commit 2a8f062

File tree

4 files changed

+320
-1
lines changed

4 files changed

+320
-1
lines changed

.circleci/config.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
version: 2.1
2+
jobs:
3+
build_deb_pkg:
4+
docker:
5+
- image: cimg/base:stable
6+
environment:
7+
PKG_VERSION: "1.0.1"
8+
steps:
9+
- checkout
10+
- setup_remote_docker:
11+
version: 20.10.11
12+
- run:
13+
name: Enable multiarch builds with QEMU
14+
command: |
15+
docker run \
16+
--rm \
17+
--privileged \
18+
multiarch/qemu-user-static \
19+
--reset \
20+
-p yes
21+
- run:
22+
name: Create multiarch build context
23+
command: docker context create builder
24+
- run:
25+
name: Create multiplatform builder
26+
command: |
27+
docker buildx create builder \
28+
--name builder \
29+
--driver docker-container \
30+
--use
31+
- run:
32+
name: Ensure builder has booted
33+
command: docker buildx inspect --bootstrap
34+
- run:
35+
name: Build docker image with .deb package
36+
command: |
37+
docker buildx build \
38+
--platform linux/arm/v7 \
39+
--build-arg PKG_VERSION \
40+
--build-arg "PKG_BUILD_NUMBER=$(date '+%Y%m%d')" \
41+
--target=artifact \
42+
--output type=local,dest=$(pwd)/releases/ \
43+
.
44+
- store_artifacts:
45+
path: releases
46+
workflows:
47+
build:
48+
jobs:
49+
- build_deb_pkg

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Docker artifacts.
2+
/releases

Dockerfile

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# syntax=docker/dockerfile:1.4
2+
# Enable here-documents:
3+
# https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/syntax.md#here-documents
4+
5+
FROM debian:buster-20220418-slim AS build
6+
7+
ARG PKG_NAME="janus"
8+
ARG PKG_VERSION="0.0.0"
9+
ARG PKG_BUILD_NUMBER="1"
10+
ARG PKG_ARCH="armhf"
11+
ARG PKG_ID="${PKG_NAME}_${PKG_VERSION}-${PKG_BUILD_NUMBER}_${PKG_ARCH}"
12+
ARG PKG_DIR="/releases/${PKG_ID}"
13+
ARG INSTALL_DIR="/opt/janus"
14+
ARG LIBNICE_VERSION="0.1.18"
15+
ARG LIBSRTP_VERSION="2.2.0"
16+
ARG LIBWEBSOCKETS_VERSION="v3.2-stable"
17+
18+
COPY . /app
19+
20+
RUN set -x && \
21+
apt-get update && \
22+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
23+
dpkg-dev
24+
25+
# Install general-purpose packages.
26+
RUN apt-get install -y --no-install-recommends \
27+
git \
28+
wget \
29+
python3-pip \
30+
cmake \
31+
pkg-config
32+
33+
# Install additional libnice dependency packages.
34+
RUN apt-get install -y --no-install-recommends \
35+
libglib2.0-dev \
36+
libssl-dev \
37+
ninja-build
38+
39+
RUN pip3 install meson
40+
41+
# Install additional Janus dependency packages.
42+
RUN apt-get install -y --no-install-recommends \
43+
automake \
44+
libtool \
45+
libjansson-dev \
46+
libconfig-dev \
47+
gengetopt
48+
49+
# libince is recommended to be installed from source because the version
50+
# installed via apt is too low.
51+
RUN git clone https://gitlab.freedesktop.org/libnice/libnice \
52+
--branch "${LIBNICE_VERSION}" \
53+
--single-branch && \
54+
cd libnice && \
55+
meson --prefix=/usr build && \
56+
ninja -C build && \
57+
ninja -C build install
58+
59+
RUN wget "https://github.com/cisco/libsrtp/archive/v${LIBSRTP_VERSION}.tar.gz" && \
60+
tar xfv "v${LIBSRTP_VERSION}.tar.gz" && \
61+
cd "libsrtp-${LIBSRTP_VERSION}" && \
62+
./configure --prefix=/usr \
63+
--enable-openssl && \
64+
make shared_library && \
65+
make install
66+
67+
RUN git clone https://libwebsockets.org/repo/libwebsockets \
68+
--branch "${LIBWEBSOCKETS_VERSION}" \
69+
--single-branch && \
70+
cd libwebsockets && \
71+
mkdir build && \
72+
cd build && \
73+
cmake \
74+
# https://github.com/meetecho/janus-gateway/issues/732
75+
-DLWS_MAX_SMP=1 \
76+
# https://github.com/meetecho/janus-gateway/issues/2476
77+
-DLWS_WITHOUT_EXTENSIONS=0 \
78+
-DCMAKE_INSTALL_PREFIX:PATH=/usr \
79+
-DCMAKE_C_FLAGS="-fpic" \
80+
.. && \
81+
make && \
82+
make install
83+
84+
# Compile Janus.
85+
RUN git clone https://github.com/meetecho/janus-gateway.git \
86+
--branch "v${PKG_VERSION}" \
87+
--single-branch && \
88+
cd janus-gateway && \
89+
sh autogen.sh && \
90+
./configure --prefix="${INSTALL_DIR}" \
91+
--disable-all-plugins \
92+
--disable-all-transports \
93+
--disable-all-handlers \
94+
--disable-all-loggers \
95+
--enable-websockets && \
96+
make && \
97+
make install
98+
99+
# Allow Janus C header files to be included when compiling third-party plugins.
100+
# Issue: https://github.com/tiny-pilot/ansible-role-tinypilot/issues/192
101+
RUN sed -i -e 's|^#include "refcount.h"$|#include "../refcount.h"|g' \
102+
"${INSTALL_DIR}/include/janus/plugins/plugin.h" && \
103+
ln -s "${INSTALL_DIR}/include/janus" /usr/include/ || true
104+
105+
# Ensure Janus default library directories exist.
106+
RUN mkdir --parents "${INSTALL_DIR}/lib/janus/plugins" \
107+
"${INSTALL_DIR}/lib/janus/transports" \
108+
"${INSTALL_DIR}/lib/janus/loggers"
109+
110+
# Use Janus sample config.
111+
RUN mv "${INSTALL_DIR}/etc/janus/janus.jcfg.sample" \
112+
"${INSTALL_DIR}/etc/janus/janus.jcfg" && \
113+
mv "${INSTALL_DIR}/etc/janus/janus.transport.websockets.jcfg.sample" \
114+
"${INSTALL_DIR}/etc/janus/janus.transport.websockets.jcfg"
115+
116+
# Overwrite Janus WebSocket config.
117+
RUN cat > "${INSTALL_DIR}/etc/janus/janus.transport.websockets.jcfg" <<EOF
118+
general: {
119+
ws = true
120+
ws_ip = "127.0.0.1"
121+
ws_port = 8002
122+
}
123+
EOF
124+
125+
RUN cat > "/lib/systemd/system/janus.service" <<EOF
126+
[Unit]
127+
Description=Janus WebRTC gateway
128+
After=network.target
129+
Documentation=https://janus.conf.meetecho.com/docs/index.html
130+
131+
[Service]
132+
Type=forking
133+
ExecStart=${INSTALL_DIR}/bin/janus --disable-colors --daemon --log-stdout
134+
Restart=on-failure
135+
LimitNOFILE=65536
136+
137+
[Install]
138+
WantedBy=multi-user.target
139+
EOF
140+
141+
RUN mkdir --parents "${PKG_DIR}"
142+
143+
# Add Janus files to the Debian package.
144+
RUN cp --parents --recursive --no-dereference "${INSTALL_DIR}/etc/janus" \
145+
"${INSTALL_DIR}/bin/janus" \
146+
"${INSTALL_DIR}/bin/janus-cfgconv" \
147+
"${INSTALL_DIR}/lib/janus" \
148+
"${INSTALL_DIR}/include/janus" \
149+
/usr/include/janus \
150+
"${INSTALL_DIR}/share/janus" \
151+
"${INSTALL_DIR}/share/doc/janus-gateway" \
152+
"${INSTALL_DIR}/share/man/man1/janus.1" \
153+
"${INSTALL_DIR}/share/man/man1/janus-cfgconv.1" \
154+
/lib/systemd/system/janus.service \
155+
"${PKG_DIR}/"
156+
157+
# Add Janus compiled shared library dependencies to the Debian package.
158+
RUN cp --parents --no-dereference /usr/lib/arm-linux-gnueabihf/libnice.so* \
159+
/usr/lib/libsrtp2.so* \
160+
/usr/lib/libwebsockets.so* \
161+
"${PKG_DIR}/"
162+
163+
RUN mkdir "${PKG_DIR}/DEBIAN"
164+
165+
WORKDIR "${PKG_DIR}/DEBIAN"
166+
167+
RUN cat > control <<EOF
168+
Package: ${PKG_NAME}
169+
Version: ${PKG_VERSION}
170+
Maintainer: TinyPilot Support <[email protected]>
171+
Depends: libconfig9, libglib2.0-0, libjansson4, libssl1.1, libc6, libsystemd0
172+
Conflicts: libnice10, libsrtp2-1, libwebsockets16
173+
Architecture: ${PKG_ARCH}
174+
Homepage: https://janus.conf.meetecho.com/
175+
Description: An open source, general purpose, WebRTC server
176+
EOF
177+
178+
RUN cat > triggers <<EOF
179+
# Reindex shared libraries.
180+
activate-noawait ldconfig
181+
EOF
182+
183+
RUN cat > preinst <<EOF
184+
#!/bin/bash
185+
systemctl disable --now janus.service > /dev/null 2>&1 || true
186+
EOF
187+
RUN chmod 0555 preinst
188+
189+
RUN cat > postinst <<EOF
190+
#!/bin/bash
191+
systemctl enable --now janus.service > /dev/null 2>&1 || true
192+
EOF
193+
RUN chmod 0555 postinst
194+
195+
RUN cat > postrm <<EOF
196+
#!/bin/bash
197+
systemctl disable --now janus.service > /dev/null 2>&1 || true
198+
EOF
199+
RUN chmod 0555 postrm
200+
201+
RUN dpkg --build "${PKG_DIR}"
202+
203+
FROM scratch as artifact
204+
205+
COPY --from=build "/releases/*.deb" ./

README.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,69 @@
1-
# janus-debian
1+
# Janus Debian Package
22

33
[![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](LICENSE)
44
[![CircleCI](https://circleci.com/gh/tiny-pilot/janus-debian/tree/master.svg?style=svg)](https://circleci.com/gh/tiny-pilot/janus-debian/tree/master)
55

66
Use CircleCI to build an ARMv7 Debian package for the Janus WebRTC server.
7+
8+
## Overview
9+
10+
We use Docker as a build context for creating an ARMv7 (armhf) Debian package, with precompiled Janus binaries (see the [Dockerfile](Dockerfile) for the complete build procedure). The resulting artifact is emitted to the `releases/` folder. For example:
11+
12+
```bash
13+
releases/janus_1.0.1-20220513_armhf.deb
14+
```
15+
16+
## Pre-requisites
17+
18+
* Raspberry Pi OS (32bit) Buster
19+
* Docker
20+
* Git
21+
22+
## Build
23+
24+
On the device, run the following commands:
25+
26+
```bash
27+
# Set the Janus version.
28+
export PKG_VERSION='1.0.1'
29+
export PKG_BUILD_NUMBER="$(date '+%Y%m%d')"
30+
# Enable new Docker BuildKit commands:
31+
# https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/syntax.md
32+
export DOCKER_BUILDKIT=1
33+
# Build Debian package.
34+
pushd "$(mktemp -d)" && \
35+
git clone https://github.com/tiny-pilot/janus-debian.git . && \
36+
docker build \
37+
--build-arg PKG_VERSION \
38+
--build-arg PKG_BUILD_NUMBER \
39+
--target=artifact \
40+
--output "type=local,dest=$(pwd)/releases/" \
41+
.
42+
```
43+
44+
## Install
45+
46+
On the device, run the following command:
47+
48+
```bash
49+
# Install Janus. This is expected to fail, if there are missing dependencies.
50+
# This leaves Janus installed, but unconfigured.
51+
sudo dpkg --install \
52+
"releases/janus_${PKG_VERSION}-${PKG_BUILD_NUMBER}_armhf.deb"
53+
# Install the missing dependencies and complete the Janus configuration.
54+
sudo apt-get install --fix-broken --yes
55+
```
56+
57+
You can confirm that the Janus systemd service is running, by executing the following command:
58+
59+
```bash
60+
sudo systemctl status janus.service
61+
```
62+
63+
## Uninstall
64+
65+
On the device, run the following command:
66+
67+
```bash
68+
sudo dpkg --purge janus
69+
```

0 commit comments

Comments
 (0)