From 1a3c20b4cb57c0ab78b8c19b159e05368bf61adc Mon Sep 17 00:00:00 2001 From: Dominic Grimm Date: Fri, 20 Dec 2024 15:53:12 +0100 Subject: [PATCH] t38modem Dockerfile --- docker/t38modem/.dockerignore | 2 + docker/t38modem/Dockerfile | 81 ++++++++++++++++++++++++++++ docker/t38modem/services/socat.sh | 6 +++ docker/t38modem/services/t38modem.sh | 22 ++++++++ docker/t38modem/start.sh | 11 ++++ 5 files changed, 122 insertions(+) create mode 100644 docker/t38modem/.dockerignore create mode 100644 docker/t38modem/Dockerfile create mode 100644 docker/t38modem/services/socat.sh create mode 100644 docker/t38modem/services/t38modem.sh create mode 100644 docker/t38modem/start.sh diff --git a/docker/t38modem/.dockerignore b/docker/t38modem/.dockerignore new file mode 100644 index 0000000..45e1bbd --- /dev/null +++ b/docker/t38modem/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +docker-compose.yml diff --git a/docker/t38modem/Dockerfile b/docker/t38modem/Dockerfile new file mode 100644 index 0000000..8cfbfe7 --- /dev/null +++ b/docker/t38modem/Dockerfile @@ -0,0 +1,81 @@ +ARG PTLIB_VERSION="2.18.6" +ARG PTLIB_VERSION_PATH="v3.18 Cygni/Stable 6/ptlib-2.18.6" + +ARG OPAL_VERSION="3.18.6" +ARG OPAL_VERSION_PATH="v3.18 Cygni/Stable 6/opal-3.18.6" + +ARG T38MODEM_VERSION="4.6.2" + +FROM docker.io/debian:12.8-slim AS builder +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y --no-install-recommends ca-certificates build-essential pkg-config wget libssl-dev libsrtp2-dev libspandsp-dev + +WORKDIR /usr/src +RUN mkdir /opt/t38modem +ENV PKG_CONFIG_PATH=/opt/t38modem/lib/pkgconfig +ENV LD_LIBRARY_PATH=/opt/t38modem/lib + +ARG PTLIB_VERSION +ARG PTLIB_VERSION_PATH +RUN wget -q -O- "https://sourceforge.net/projects/opalvoip/files/${PTLIB_VERSION_PATH}.tar.bz2" \ + | tar xj \ + && cd "ptlib-${PTLIB_VERSION}" \ + && CPPFLAGS="-O3 -flto=auto" LDFLAGS="-O3 -flto=auto" ./configure --prefix=/opt/t38modem \ + && make -j$(nproc) \ + && make install \ + && rm -rf "/usr/src/ptlib-${PTLIB_VERSION}" + +ARG OPAL_VERSION +ARG OPAL_VERSION_PATH +RUN wget -q -O- "https://sourceforge.net/projects/opalvoip/files/${OPAL_VERSION_PATH}.tar.bz2" \ + | tar xj \ + && cd "opal-${OPAL_VERSION}" \ + && CPPFLAGS="-O3" ./configure --prefix=/opt/t38modem \ + && make -j$(nproc) \ + && make install \ + && rm -rf "/usr/src/opal-${OPAL_VERSION}" + +ARG T38MODEM_VERSION +RUN wget -q -O- "https://github.com/hehol/t38modem/archive/refs/tags/${T38MODEM_VERSION}.tar.gz" \ + | tar xz \ + && cd "t38modem-${T38MODEM_VERSION}" \ + && CPPFLAGS="-O3 -flto=auto -Wno-narrowing" LDFLAGS="-O3 -flto=auto" make \ + && mv t38modem /opt/t38modem/bin \ + && rm -rf "/usr/src/t38modem-${T38MODEM_VERSION}" + +FROM docker.io/debian:12.8-slim AS runner +LABEL maintainer="dominic@dergrimm.net" \ + org.opencontainers.image.title="t38modem" \ + org.opencontainers.image.description="t38modem bridged over socat TCP" \ + org.opencontainers.image.authors="Dominic Grimm" \ + org.opencontainers.image.source="https://git.dergrimm.net/dergrimm/linux-fax-stack.git" + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y ca-certificates socat libssl-dev libsrtp2-dev libspandsp-dev \ + && apt-get clean -y \ + && apt-get autoremove -y \ + && apt-get autoclean -y \ + && rm -rf /tmp/* \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /usr/local/t38modem +COPY --from=builder /opt/t38modem/lib /usr/local/t38modem/lib +COPY --from=builder /opt/t38modem/bin/t38modem /usr/local/t38modem/bin/t38modem +COPY services services +COPY start.sh . +RUN chmod +x /usr/local/t38modem/services/t38modem.sh /usr/local/t38modem/services/socat.sh /usr/local/t38modem/start.sh + +RUN rm -rf /tmp/* + +ENV PATH="$PATH:/usr/local/t38modem/bin" +ENV PREFIX="/usr/local/t38modem" +ENV LD_LIBRARY_PATH="/usr/local/t38modem/lib" +ARG PTLIB_VERSION +ARG OPAL_VERSION +ENV PTLIBPLUGINDIR="/usr/local/t38modem/lib/ptlib-${PTLIB_VERSION}:/usr/local/t38modem/lib/opal-${OPAL_VERSION}" + +ENTRYPOINT [ "/usr/local/t38modem/start.sh" ] diff --git a/docker/t38modem/services/socat.sh b/docker/t38modem/services/socat.sh new file mode 100644 index 0000000..2943066 --- /dev/null +++ b/docker/t38modem/services/socat.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# $1: PTTY ID +# $2: TCP server port + +socat -d -d "file:${1},raw,echo=0" "TCP-LISTEN:${2},reuseaddr" diff --git a/docker/t38modem/services/t38modem.sh b/docker/t38modem/services/t38modem.sh new file mode 100644 index 0000000..28ecd98 --- /dev/null +++ b/docker/t38modem/services/t38modem.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +PTTY=$(seq -f "+${1}-%g" -s "," "${T38MODEM_MODEM_COUNT}") + +CMD=( + "t38modem" + "--ptty" "${PTTY}" + "--sip-proxy" "${T38MODEM_SIP_USERNAME}:${T38MODEM_SIP_PASSWORD}@${T38MODEM_SIP_SERVER}" + "--sip-register" "${T38MODEM_SIP_USERNAME}@${T38MODEM_SIP_SERVER},${T38MODEM_SIP_PASSWORD}" + "--sip-listen" "udp\$:5060" + "--stun" "${T38MODEM_STUN_SERVER}" + "--route" "t38:.*=sip:@${T38MODEM_SIP_SERVER}" + "--route" "sip:.*=t38:" +) + +if [ "$T38MODEM_DISABLE_T38" = true ]; then + cmd+=("--disable-t38-mode" "--audio") +fi + +CMD+=("${T38MODEM_CMD_ARGS}") + +exec "${CMD[@]}" diff --git a/docker/t38modem/start.sh b/docker/t38modem/start.sh new file mode 100644 index 0000000..fb86e53 --- /dev/null +++ b/docker/t38modem/start.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +exec "${PREFIX}/services/t38modem.sh" /dev/ttyT38 & +sleep 5 + +for i in $(seq "${T38MODEM_MODEM_COUNT}"); do + PORT="$(("${T38MODEM_START_PORT}" + i - 1))" + exec "${PREFIX}/services/socat.sh" "/dev/ttyT38-${i}" "${PORT}" & +done + +wait