Skip to content

Commit eb36f73

Browse files
committed
feature(satellite): add postgres vectorstore for call transcriptions
1 parent d1739c7 commit eb36f73

File tree

13 files changed

+125
-8
lines changed

13 files changed

+125
-8
lines changed

Containerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ COPY imageroot /imageroot
2222
COPY --from=ui_builder /app/dist /ui
2323
ENTRYPOINT [ "/" ]
2424
LABEL org.nethserver.authorizations="traefik@any:fulladm node:fwadm,portsadm nethvoice-proxy@any:routeadm"
25-
LABEL org.nethserver.tcp-ports-demand="36"
25+
LABEL org.nethserver.tcp-ports-demand="37"
2626
LABEL org.nethserver.rootfull="0"
2727
LABEL org.nethserver.min-core="3.6.2-0"
2828
ARG REPOBASE=ghcr.io/nethserver
@@ -40,4 +40,5 @@ LABEL org.nethserver.images="${REPOBASE}/nethvoice-mariadb:${IMAGETAG} \
4040
${REPOBASE}/nethvoice-reports-api:${IMAGETAG} \
4141
${REPOBASE}/nethvoice-sftp:${IMAGETAG} \
4242
docker.io/library/eclipse-mosquitto:2 \
43-
${REPOBASE}/nethvoice-satellite:${IMAGETAG}"
43+
${REPOBASE}/nethvoice-satellite:${IMAGETAG}\
44+
docker.io/pgvector/pgvector:0.8.1-pg18-trixie"

imageroot/actions/configure-module/80start_services

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ fi
5252
if [ "$SATELLITE_CALL_TRANSCRIPTION_ENABLED" = "True" ] || [ "$SATELLITE_VOICEMAIL_TRANSCRIPTION_ENABLED" = "True" ]; then
5353
systemctl --user enable --now satellite.service
5454
systemctl --user enable --now satellite-mqtt.service
55+
systemctl --user enable --now satellite-pgsql.service
5556
else
5657
systemctl --user stop satellite.service
5758
systemctl --user disable satellite.service
5859
systemctl --user stop satellite-mqtt.service
5960
systemctl --user disable satellite-mqtt.service
61+
systemctl --user stop satellite-pgsql.service
62+
systemctl --user disable satellite-pgsql.service
6063
fi

imageroot/actions/create-module/05setenvs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ agent.set_env('ASTERISK_RECORDING_SFTP_PORT', port_list[30])
150150
agent.set_env('ASTERISK_WS_PORT', port_list[31])
151151
agent.set_env('SATELLITE_MQTT_PORT', port_list[32])
152152
agent.set_env('SATELLITE_HTTP_PORT', port_list[33])
153+
agent.set_env('SATELLITE_PGSQL_USER', 'satellite')
154+
agent.set_env('SATELLITE_PGSQL_DB', 'satellite')
155+
agent.set_env('SATELLITE_PGSQL_PORT', str(port_list[36]))
153156

154157
# Asterisk WSS
155158
agent.set_env('ASTERISK_WSS_PORT', port_list[34])
@@ -184,7 +187,8 @@ passwords = {
184187
"REPORTS_API_KEY": gen_password(),
185188
"REPORTS_SECRET": gen_password(),
186189
"SATELLITE_MQTT_PASSWORD": gen_password(),
187-
"SATELLITE_ARI_PASSWORD": gen_password()
190+
"SATELLITE_ARI_PASSWORD": gen_password(),
191+
"SATELLITE_PGSQL_PASSWORD": gen_password()
188192
}
189193

190194
agent.write_envfile("passwords.env", passwords)

imageroot/actions/restore-module/20copyenv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ restore_envs = [
113113
'TIMEZONE',
114114
'TRAEFIK_HTTP2HTTPS',
115115
'USER_DOMAIN',
116+
'SATELLITE_CALL_TRANSCRIPTION_ENABLED',
117+
'SATELLITE_VOICEMAIL_TRANSCRIPTION_ENABLED',
116118
]
117119

118120
for env in restore_envs:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (C) 2025 Nethesis S.r.l.
5+
# SPDX-License-Identifier: GPL-3.0-or-later
6+
#
7+
8+
set -e -o pipefail
9+
exec 1>&2 # Redirect any output to the journal (stderr)
10+
11+
SATELLITE_PGSQL_PASSWORD=$(grep '^SATELLITE_PGSQL_PASSWORD=' ./passwords.env) && export "${SATELLITE_PGSQL_PASSWORD?}"
12+
13+
mkdir -vp restore
14+
cat - >restore/satellite_postgresql_restore.sh <<'EOS'
15+
# Read dump file from standard input and restore all databases:
16+
psql -U postgres -f /tmp/satellite_postgresql.pg_dump
17+
ec=$?
18+
docker_temp_server_stop
19+
exit $ec
20+
EOS
21+
22+
# Override the image /docker-entrypoint-initdb.d contents, to restore the
23+
# DB dump file. The container will be stopped at the end
24+
podman run \
25+
--rm \
26+
--interactive \
27+
--network=none \
28+
--volume=./restore:/docker-entrypoint-initdb.d/:Z \
29+
--volume=satellite_pgdata:/var/lib/postgresql/data:Z \
30+
--volume=./satellite_postgresql.pg_dump:/tmp/satellite_postgresql.pg_dump:Z \
31+
--replace --name=restore_db \
32+
--env POSTGRES_USER=${SATELLITE_PGSQL_USER} \
33+
--env POSTGRES_PASSWORD=${SATELLITE_PGSQL_PASSWORD} \
34+
--env TZ=UTC \
35+
"${POSTGRES_IMAGE}"
36+
37+
38+
# If the restore is successful, clean up:
39+
rm -rfv restore/ postgresql.pg_dump

imageroot/bin/module-dump-state

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ if podman exec freepbx ls -alh /var/lib/asterisk/sounds/nethcti >/dev/null 2>&1;
5757
podman cp freepbx:/var/lib/asterisk/sounds/nethcti/. asterisk_backup/var/lib/asterisk/sounds/nethcti
5858
fi
5959

60+
# satellite postgresql dump
61+
echo "Dumping Satellite PostgreSQL database"
62+
podman exec satellite-pgsql pg_dumpall -U postgres > satellite_postgresql.pg_dump

imageroot/etc/state-include.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ volumes/pbooksources
88
volumes/phonebookcsv
99
volumes/post_scripts
1010
volumes/reports_config
11+
volumes/satellite_pgdata
1112
volumes/scripts
1213
volumes/spool
1314
volumes/tancredi
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[Unit]
2+
Description=Podman PostgreSQL service for Satellite
3+
4+
[Service]
5+
Environment=PODMAN_SYSTEMD_UNIT=%n
6+
EnvironmentFile=%S/state/environment
7+
EnvironmentFile=%S/state/passwords.env
8+
WorkingDirectory=%S/state
9+
Restart=always
10+
TimeoutStopSec=70
11+
ExecStartPre=/bin/rm -f %t/satellite-pgsql.pid %t/satellite-pgsql.ctr-id
12+
# set password for PostgreSQL
13+
ExecStartPre=-runagent satellite-pgsql-gen-config
14+
ExecStart=/usr/bin/podman run --conmon-pidfile %t/satellite-pgsql.pid \
15+
--cidfile %t/satellite-pgsql.ctr-id --cgroups=no-conmon \
16+
--replace \
17+
--detach \
18+
--name=%N \
19+
--volume=satellite_pgdata:/var/lib/postgresql/data:Z \
20+
--network=host \
21+
--env POSTGRES_PASSWORD=${SATELLITE_PGSQL_PASSWORD} \
22+
--env POSTGRES_USER=${SATELLITE_PGSQL_USER} \
23+
--env POSTGRES_DB=${SATELLITE_PGSQL_DB} \
24+
--env PGPORT=${SATELLITE_PGSQL_PORT} \
25+
--tz=${TIMEZONE} \
26+
--network=host \
27+
${PGVECTOR_IMAGE}
28+
29+
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/satellite-pgsql.ctr-id -t 10
30+
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/satellite-pgsql.ctr-id
31+
PIDFile=%t/satellite-pgsql.pid
32+
Type=forking
33+
34+
[Install]
35+
WantedBy=default.target

imageroot/systemd/user/satellite.service

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[Unit]
22
Description=Satellite call transcription for NethVoice
3-
Requires=satellite-mqtt.service
4-
After=satellite-mqtt.service
3+
Requires=satellite-mqtt.service, satellite-pgsql.service
4+
After=satellite-mqtt.service, satellite-pgsql.service
55

66
[Service]
77
Environment=PODMAN_SYSTEMD_UNIT=%n
88
EnvironmentFile=%S/state/environment
9+
EnvironmentFile=%S/state/passwords.env
910
WorkingDirectory=%S/state
1011
Restart=always
1112
ExecStartPre=/bin/rm -f %t/satellite.pid %t/satellite.ctr-id
@@ -24,6 +25,13 @@ ExecStart=runagent /usr/bin/podman run \
2425
--env=MQTT_TOPIC_PREFIX=satellite \
2526
--env=MQTT_USERNAME=${SATELLITE_MQTT_USERNAME} \
2627
--env=HTTP_PORT=${SATELLITE_HTTP_PORT} \
28+
--env=SATELLITE_ARI_PASSWORD=${SATELLITE_ARI_PASSWORD} \
29+
--env=SATELLITE_MQTT_PASSWORD=${SATELLITE_MQTT_PASSWORD} \
30+
--env=PGVECTOR_HOST=127.0.0.1 \
31+
--env=PGVECTOR_PORT=${SATELLITE_PGSQL_PORT} \
32+
--env=PGVECTOR_DB=${SATELLITE_PGSQL_DB} \
33+
--env=PGVECTOR_USER=${SATELLITE_PGSQL_USER} \
34+
--env=PGVECTOR_PASSWORD=${SATELLITE_PGSQL_PASSWORD} \
2735
--tz=${TIMEZONE} \
2836
--network=host \
2937
${NETHVOICE_SATELLITE_IMAGE}

imageroot/update-module.d/10env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,22 @@ if os.getenv('SATELLITE_ARI_USERNAME') is None:
8484
if os.getenv('SATELLITE_MQTT_USERNAME') is None:
8585
agent.set_env('SATELLITE_MQTT_USERNAME', 'satellite')
8686

87+
# Add Satellite PostgreSQL environment variables for updates
88+
if os.getenv('SATELLITE_PGSQL_PORT') is None:
89+
agent.set_env('SATELLITE_PGSQL_PORT', os.environ['SATELLITE_PGSQL_PORT'])
90+
if os.getenv('SATELLITE_PGSQL_DB') is None:
91+
agent.set_env('SATELLITE_PGSQL_DB', 'satellite')
92+
if os.getenv('SATELLITE_PGSQL_USER') is None:
93+
agent.set_env('SATELLITE_PGSQL_USER', 'satellite')
94+
8795
# Add satellite password for updates in passwords.env if not already set
8896
passwordsfile = agent.read_envfile("passwords.env")
8997
if not 'SATELLITE_MQTT_PASSWORD' in agent.read_envfile('passwords.env'):
9098
passwordsfile['SATELLITE_MQTT_PASSWORD'] = gen_password()
9199
if not 'SATELLITE_ARI_PASSWORD' in agent.read_envfile('passwords.env'):
92100
passwordsfile['SATELLITE_ARI_PASSWORD'] = gen_password()
101+
if not 'SATELLITE_PGSQL_PASSWORD' in agent.read_envfile('passwords.env'):
102+
passwordsfile['SATELLITE_PGSQL_PASSWORD'] = gen_password()
93103
agent.write_envfile('passwords.env', passwordsfile)
94104

95105
if os.getenv('NETHVOICE_MIDDLEWARE_V1_API_ENDPOINT') is None:

0 commit comments

Comments
 (0)