feat: add asterisk pjsip integration
- infrastructure/docker/asterisk.Dockerfile: Asterisk 22.10.1 LTS compilado do fonte oficial (Debian trixie nao distribui mais o pacote asterisk), com PJSIP, AMI, ARI, res_odbc/res_config_odbc, cdr_adaptive_odbc, cel_odbc, app_queue - infrastructure/asterisk/config: templates renderizados no entrypoint (secrets via envsubst, nunca versionados) + sorcery.conf/extconfig.conf para PJSIP realtime, dialplan de teste (extensao 600) - infrastructure/postgres/init/002-asterisk-realtime.sql: tabelas ps_endpoints/ps_auths/ps_aors/ps_contacts/ps_endpoint_id_ips/ ps_registrations/cdr/cel no schema 'asterisk' - infrastructure/nftables: protege AMI/ARI/SIP contra acesso pela LAN (interface ens18), trazido da Fase 9 do TODO para ja, sem afetar SSH nem a rede interna do Docker - docker-compose.yml: servico asterisk em network_mode: host (RTP); Postgres publicado em 127.0.0.1:5432 (nao 0.0.0.0) para o Asterisk alcanca-lo, ja que host network nao enxerga a rede Docker interna Testado: AMI login, ARI com auth (401 sem auth), pjsip realtime consultando Postgres sem erro, dialplan originate -> CDR e CEL gravados corretamente, healthcheck do compose passando.
This commit is contained in:
33
infrastructure/docker/asterisk-entrypoint.sh
Normal file
33
infrastructure/docker/asterisk-entrypoint.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
# Renderiza os templates de configuração (que contêm variáveis ${VAR}) usando
|
||||
# as variáveis de ambiente do container, para nunca versionar segredos em
|
||||
# texto puro nos arquivos .conf. /etc/asterisk já vem populado pelo `make
|
||||
# samples` no build da imagem — aqui só sobrepomos/adicionamos os arquivos
|
||||
# específicos do B2BCall (o restante dos samples permanece intacto).
|
||||
set -euo pipefail
|
||||
|
||||
CONFIG_SRC=/etc/asterisk-templates
|
||||
CONFIG_DST=/etc/asterisk
|
||||
|
||||
mkdir -p "$CONFIG_DST"
|
||||
|
||||
# odbc.ini é configuração do sistema (unixODBC), não do Asterisk.
|
||||
if [ -e "$CONFIG_SRC/odbc.ini.tpl" ]; then
|
||||
envsubst < "$CONFIG_SRC/odbc.ini.tpl" > /etc/odbc.ini
|
||||
fi
|
||||
|
||||
for tpl in "$CONFIG_SRC"/*.conf.tpl; do
|
||||
[ -e "$tpl" ] || continue
|
||||
name="$(basename "$tpl" .tpl)"
|
||||
envsubst < "$tpl" > "$CONFIG_DST/$name"
|
||||
done
|
||||
|
||||
for f in "$CONFIG_SRC"/*.conf; do
|
||||
[ -e "$f" ] || continue
|
||||
name="$(basename "$f")"
|
||||
cp "$f" "$CONFIG_DST/$name"
|
||||
done
|
||||
|
||||
chown -R asterisk:asterisk "$CONFIG_DST" /var/lib/asterisk /var/log/asterisk /var/spool/asterisk /var/run/asterisk
|
||||
|
||||
exec "$@"
|
||||
70
infrastructure/docker/asterisk.Dockerfile
Normal file
70
infrastructure/docker/asterisk.Dockerfile
Normal file
@@ -0,0 +1,70 @@
|
||||
# Asterisk 22 LTS compilado a partir do fonte oficial.
|
||||
# Debian não distribui mais o pacote `asterisk` em seus repositórios, então
|
||||
# compilamos aqui com controle total dos módulos: PJSIP (chan_sip não existe
|
||||
# mais a partir do Asterisk 21), AMI, ARI, Realtime ODBC (Postgres), CDR, CEL.
|
||||
FROM debian:trixie-slim
|
||||
|
||||
ARG ASTERISK_VERSION=22.10.1
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential wget ca-certificates git subversion patch \
|
||||
pkg-config autoconf automake libtool \
|
||||
libxml2-dev libsqlite3-dev uuid-dev libjansson-dev libedit-dev \
|
||||
unixodbc unixodbc-dev odbc-postgresql \
|
||||
libsrtp2-dev libssl-dev libncurses-dev libnewt-dev \
|
||||
libspeex-dev libspeexdsp-dev libogg-dev libvorbis-dev \
|
||||
libcurl4-openssl-dev libsystemd-dev gettext-base \
|
||||
odbc-postgresql \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /usr/src
|
||||
RUN wget -q "https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-${ASTERISK_VERSION}.tar.gz" \
|
||||
&& tar xzf asterisk-${ASTERISK_VERSION}.tar.gz \
|
||||
&& rm asterisk-${ASTERISK_VERSION}.tar.gz \
|
||||
&& mv asterisk-${ASTERISK_VERSION} asterisk
|
||||
|
||||
WORKDIR /usr/src/asterisk
|
||||
|
||||
# Instala dependências adicionais específicas da distro (detectadas pelo
|
||||
# próprio script oficial do Asterisk) sem prompts interativos.
|
||||
RUN contrib/scripts/install_prereq install --yes || true
|
||||
|
||||
RUN ./configure --with-jansson-bundled --with-pjproject-bundled --with-crypto --with-ssl=ssl
|
||||
|
||||
RUN make menuselect.makeopts \
|
||||
&& menuselect/menuselect \
|
||||
--enable res_odbc \
|
||||
--enable res_config_odbc \
|
||||
--enable cdr_odbc \
|
||||
--enable cdr_pgsql \
|
||||
--enable cel_odbc \
|
||||
--enable cel_pgsql \
|
||||
--enable app_queue \
|
||||
--enable res_pjsip \
|
||||
--enable res_pjsip_session \
|
||||
--enable res_ari \
|
||||
--enable res_ari_applications \
|
||||
--enable res_ari_channels \
|
||||
--enable res_ari_bridges \
|
||||
--enable CORE-SOUNDS-EN-WAV \
|
||||
--enable MOH-OPSOUND-WAV \
|
||||
menuselect.makeopts
|
||||
|
||||
RUN make -j"$(nproc)"
|
||||
RUN make install
|
||||
RUN make samples
|
||||
RUN ldconfig
|
||||
|
||||
RUN groupadd -r asterisk && useradd -r -g asterisk -d /var/lib/asterisk asterisk \
|
||||
&& mkdir -p /etc/asterisk /var/lib/asterisk /var/log/asterisk /var/spool/asterisk /var/run/asterisk \
|
||||
&& chown -R asterisk:asterisk /etc/asterisk /var/lib/asterisk /var/log/asterisk /var/spool/asterisk /var/run/asterisk /usr/lib/asterisk
|
||||
|
||||
EXPOSE 5060/udp 5060/tcp 5061/tcp 8088/tcp 8089/tcp 5038/tcp
|
||||
EXPOSE 10000-20000/udp
|
||||
|
||||
COPY infrastructure/docker/asterisk-entrypoint.sh /usr/local/bin/asterisk-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/asterisk-entrypoint.sh
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/asterisk-entrypoint.sh"]
|
||||
CMD ["asterisk", "-f", "-vvv", "-U", "asterisk", "-G", "asterisk"]
|
||||
Reference in New Issue
Block a user