#!/usr/bin/env bash
set -euo pipefail

VG_TAG=latest

# Путь к БД на хосте
DB_HOST_DIR="/opt/VideoGrace/Server/db"

mkdir -p "$DB_HOST_DIR"

docker rm -f vgserver >/dev/null 2>&1 || true

docker pull videograce.cr.cloud.ru/vgserver:$VG_TAG

docker run -tid \
  --cpus="4" \
  --name="vgserver" \
  -p 443:443 \
  -p 5060:5060/udp \
  -p 5061:5061/udp \
  -p 5062:5062/udp \
  -p 5063:5063/udp \
  -e VG_LOGLEVEL=2 \
  -e VG_THREADS=4 \
  -e VG_DOWNGRADECLIENTS=0 \
  -v "$DB_HOST_DIR":/home/vg_server/db \
  -e KRB5_KTNAME=/run/secrets/vgsrv.keytab \
  -v /etc/krb5.conf:/etc/krb5.conf:ro \
  -v /secure/vgsrv.keytab:/run/secrets/vgsrv.keytab:ro \
  "videograce/vgserver:$VG_TAG"
