From 4604dfbdad70735c41e8de4a31165c037ab9c53d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 22 Jan 2024 22:03:50 -0500 Subject: [PATCH] Dockerize --- docker/Dockerfile | 63 ++++++++++++++++++++++++++++++++++++++++++++ docker/entrypoint.sh | 32 ++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 docker/Dockerfile create mode 100755 docker/entrypoint.sh diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..f3fd734 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,63 @@ +FROM debian:unstable as asterisk + +ENV DEBIAN_FRONTEND=noninteractive +WORKDIR /opt +RUN sed -i 's/: deb/: deb deb-src/' /etc/apt/sources.list.d/debian.sources \ + && apt-get update \ + && apt-get -y --no-install-recommends build-dep asterisk \ + && apt-get -y --no-install-recommends install build-essential git libdpkg-perl libgit-wrapper-perl liblist-compare-perl libstring-shellquote-perl libtry-tiny-perl dgit libvpb-dev + +RUN git clone https://git.singpolyma.net/asterisk \ + && cd /opt/asterisk \ + && git checkout 3ef8fade9b1803906a9052feb380170b2a51d2f9 \ + && git config user.email "docker@example.com" \ + && git config user.name "Docker" \ + && git deborig \ + && dgit --ignore-dirty build + +FROM debian:stable as cheogram-sip + +ENV DEBIAN_FRONTEND=noninteractive +WORKDIR /opt +RUN apt-get update \ + && apt-get -y --no-install-recommends install ca-certificates git ghc cabal-install c2hs pkg-config libxml2-dev libgsasl-dev libgnutls28-dev + +RUN git clone https://git.singpolyma.net/cheogram-sip \ + && cd cheogram-sip \ + && git checkout 290130e42955ccc2406a224b6bc05792258d2eb3 \ + && cabal update \ + && cabal build + +FROM debian:unstable + +ENV DEBIAN_FRONTEND=noninteractive + +COPY --from=asterisk /opt/asterisk-modules_16*.deb /root/ +COPY --from=asterisk /opt/asterisk-config_16*.deb /root/ +COPY --from=asterisk /opt/asterisk_16*.deb /root/ +COPY --from=cheogram-sip /opt/cheogram-sip/dist-newstyle/build/x86_64-linux/ghc-9.0.2/cheogram-sip-0.1.0/x/cheogram-sip/build/cheogram-sip/cheogram-sip /bin/ + +RUN apt-get update \ + && apt-get -y --no-install-recommends install /root/asterisk*.deb \ + && apt-get -y --no-install-recommends install libxml2 libgsasl18 libgnutls30 \ + && rm -rf /var/cache /root/asterisk*.deb + +COPY --from=cheogram-sip /opt/cheogram-sip/asterisk-conf/motif.conf /etc/asterisk/motif.conf +COPY --from=cheogram-sip /opt/cheogram-sip/asterisk-conf/xmpp.conf /etc/asterisk/xmpp.conf +COPY --from=cheogram-sip /opt/cheogram-sip/asterisk-conf/extensions.lua /etc/asterisk/extensions.lua + +ENV COMPONENT_DOMAIN= +ENV COMPONENT_SECRET= +ENV ASTERISK_COMPONENT_DOMAIN=asterisk +ENV ASTERISK_COMPONENT_SECRET= +ENV CONNECT_IP=127.0.0.1 +ENV CONNECT_PORT=5347 + +# Optional SIP host registration +ENV SIP_HOST= +ENV SIP_USER= +ENV SIP_PASSWORD= +ENV SIP_JID= + +ADD entrypoint.sh /bin/entrypoint.sh +ENTRYPOINT ["/bin/entrypoint.sh"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..8f0270b --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +sed -i "s/^serverhost=.*/serverhost=$CONNECT_IP/" /etc/asterisk/xmpp.conf +sed -i "s/^port=.*/port=$CONNECT_PORT/" /etc/asterisk/xmpp.conf +sed -i "s/^username=.*/username=$ASTERISK_COMPONENT_DOMAIN/" /etc/asterisk/xmpp.conf +sed -i "s/sip.cheogram.com/$COMPONENT_DOMAIN/g" /etc/asterisk/extensions.lua +sed -i "s/^secret=.*/secret=$ASTERISK_COMPONENT_SECRET/" /etc/asterisk/xmpp.conf +if [ -n "$SIP_HOST" ]; then + if ! grep "@$SIP_HOST" /etc/asterisk/sip.conf; then + sed -i "/^;register => 1234/a register => $SIP_USER:$SIP_PASSWORD@$SIP_HOST/\"$SIP_JID\"" /etc/asterisk/sip.conf + echo "[$SIP_HOST]" >> /etc/asterisk/sip.conf + echo "type=peer" >> /etc/asterisk/sip.conf + echo "insecure=invite" >> /etc/asterisk/sip.conf + echo "nat=yes" >> /etc/asterisk/sip.conf + echo "srvlookup=yes" >> /etc/asterisk/sip.conf + echo "host=$SIP_HOST" >> /etc/asterisk/sip.conf + echo "realm=$SIP_HOST" >> /etc/asterisk/sip.conf + echo "secret=$SIP_PASSWORD" >> /etc/asterisk/sip.conf + echo "username=$SIP_USER" >> /etc/asterisk/sip.conf + echo "fromuser=$SIP_USER" >> /etc/asterisk/sip.conf + echo "fromdomain=$SIP_HOST" >> /etc/asterisk/sip.conf + + sed -i "s/-- outbound calls/if from ~= \"$SIP_JID\" then return end/" /etc/asterisk/extensions.lua + fi +fi +/usr/sbin/asterisk & + +if [ -n "$SIP_HOST" ]; then + /bin/cheogram-sip "$COMPONENT_DOMAIN" "$CONNECT_IP" "$CONNECT_PORT" "$COMPONENT_SECRET" "$REDIS_URL" "$ASTERISK_COMPONENT_DOMAIN" "$SIP_HOST" +else + /bin/cheogram-sip "$COMPONENT_DOMAIN" "$CONNECT_IP" "$CONNECT_PORT" "$COMPONENT_SECRET" "$REDIS_URL" "$ASTERISK_COMPONENT_DOMAIN" +fi -- 2.45.2