|
| 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" ./ |
0 commit comments