FICUSONLINE F9E
Flexisip + Account Manager on Docker (Ubuntu 22.04)
This is a summary of a forum article about installing the latest version of the Flexisip server on Ubuntu 22.04 by installing the SDK and building from source. For troubleshooting and more detailed information (flexisip.conf, redis.conf and so on), please refer to the forum article (see link below). After building the binary, a new Docker image file for Flexisip is created, which is combined with other Docker image files necessary for operating the Flexisip server to configure the entire system.
Takanobu FuseAdministrator

17 min read

2 years ago

Linux

This is a summary of a forum article about installing the latest version of the Flexisip server on Ubuntu 22.04 by installing the SDK and building from source. For troubleshooting and more detailed information (flexisip.conf, redis.conf and so on), please refer to the forum article (see link below). After building the binary, a new Docker image file for Flexisip is created, which is combined with other Docker image files necessary for operating the Flexisip server to configure the entire system.

Docker Flexisip System

  1. Creating a Linphone SDK Docker image
    Creating a Linphone SDK Docker image will help resolve dependencies for Flexisip.

  2. Building Flexisip and creating a DEB package
    Build Flexisip and create a DEB package.

  3. Creating a Flexisip Docker image
    Create a new Docker image file using the binary built for Flexisip.

  4. SSL/TLS authentication procedure with Certbot Docker container
    Obtain an SSL/TLS certificate using a Certbot Docker container.

  5. Preparing for Flexisip Account Manager installation
    Prepare the necessary files for installing Flexisip Account Manager.

  6. Creating a Docker Compose file
    Create a Docker Compose file to configure the Flexisip server.

  7. Starting and operating in containers
    Use Docker Compose to start the Flexisip server and perform any necessary operations inside the container.

Link to related forum article:Linphone-SDK Ubuntu 22.04 Dockerイメージの作成とアプリのビルド(IPv6対応)


1. Creating a Linphone SDK Docker image(Ubuntu 22.04)

To build the Linphone app and Flexisip server within a Linphone SDK Docker container, you will need to create a Linphone SDK Docker image. To do this, you will need to download the docker-files directory from the following source:

$ git clone https://gitlab.linphone.org/BC/public/linphone-sdk.git

Create a new file that is compatible with Ubuntu 22.04 based on the bc-dev-ubuntu-rolling file in the docker-files directory.

bc-dev-ubuntu-22-04-lts

FROM ubuntu:22.04

MAINTAINER Takanobu Fuse  [email protected]>

# Configure locale
RUN apt-get update && \
    apt-get install -y locales && \
    apt-get clean && \
    echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
    locale-gen
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'
ENV TZ=Europe/Paris
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ARG DEBIAN_FRONTEND=noninteractive

ENV SHELL=/bin/bash
#ENV PS1='\[\e[33m\]\u@bc-dev-ubuntu-22-04-lts>\[\e[0m\] '

# Install common general tools
RUN apt-get update && \
    apt-get install -y nano sudo vim && \
    apt-get clean

# Install development tools
RUN apt-get update && \
    apt-get install -y alien at autoconf bison ccache clang cmake doxygen elfutils g++ gdb git graphviz intltool libtool lsb-release make nasm ninja-build openssh-client patch python3-pip python3-pystache python-six yasm && \
    apt-get clean

# Install linphone & flexisip dependencies development packages
RUN apt-get update && \
    apt-get install -y libasound2-dev libavcodec-dev libavutil-dev libbsd-dev libegl1-mesa-dev libglew-dev libgsm1-dev libjansson-dev libmariadb-dev-compat libmbedtls-dev libopus-dev libpq-dev libprotobuf-dev libpulse-dev libqt5svg5-dev libsnmp-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libsrtp2-dev libssl-dev libswscale-dev libturbojpeg0-dev libv4l-dev libvpx-dev libxerces-c-dev libxml2-dev libxv-dev protobuf-compiler qt3d5-dev qtbase5-dev qtbase5-dev-tools qtchooser qt5-qmake qtconnectivity5-dev qtdeclarative5-dev qtdeclarative5-dev-tools qtdeclarative5-dev-tools qtquickcontrols2-5-dev qttools5-dev qttools5-dev-tools xsdcxx && \
    apt-get clean

# Configure user bc
RUN useradd -ms /bin/bash bc && \
    echo 'bc:cotcot' | chpasswd && \
    echo 'bc ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER bc
WORKDIR /home/bc
COPY --chown=bc rpmmacros /home/bc/.rpmmacros
CMD bash

Edit Makefike ( add the section of ubutnu 22.04)

.....
.....
ubuntu-22.04-LTS:
	docker build -f bc-dev-ubuntu-22-04-lts -t $(BASE_NAME)/bc-dev-ubuntu:22.04 --rm .
.....
.....

Build( or build directory by docker build command )

$ make ubuntu-22.04-LTS

Confirm Docker Image

$ docker images
REPOSITORY                                                      TAG          IMAGE ID       CREATED          SIZE
gitlab.linphone.org:4567/bc/public/linphone-sdk/bc-dev-ubuntu   22.04        6ee9dee48674   47 minutes ago   2.28GB

Launch a container using the above image in any folder (where you will build Linphone or Flexisip)

$ docker run --name linphone-sdk -v $PWD:/home/bc -it gitlab.linphone.org:4567/bc/public/linphone-sdk/bc-dev-ubuntu:22.04
bc@616cdfa4bb84:~$

2. Building Flexisip and creating a DEB package

Start a container from linphone-sdk image.

$ docker run --name linphone-sdk -v $PWD:/home/bc -it gitlab.linphone.org:4567/bc/public/linphone-sdk/bc-dev-ubuntu:22.04

The following is a task to be performed inside a container. Download the source code of flexisip within the container.

$ git clone https://gitlab.linphone.org/BC/public/flexisip.git --recursive

Next, install the necessary packages for building flexisip by referring to the following file, and build and install them.

Additional Packages

$ sudo apt install file llvm libboost-dev libboost-system-dev libboost-thread-dev libhiredis-dev libjsoncpp-dev mariadb-server libnghttp2-dev redis-server

Build and install for the additional package by the scrypt.

$ cd flexisip/docker
$ sudo ./libnghttp2_asio_install.sh 1.43.0

Once you have completed the above preparations, you can build flexisip using the following flow.

$ mkdir build
$ cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX=/opt/belledonne-communications -DCMAKE_BUILD_TYPE=RelWithDebInfo -DSYSCONF_INSTALL_DIR=/etc -DCPACK_GENERATOR=DEB
$ make package

If everything goes well, two types of packages will be created as follows.

bc-flexisip_2.3.0-0.*_amd64.deb
bc-flexisip-dbgsym_2.3.0-0.*_amd64.ddeb


Note) Installation of flexisip from official repositories for different operating systems.

For those who do not wish to build flexisip from source and want to register the repository to create a new flexisip Docker image, please refer to the following instructions. This is applicable for CentOS, RockyLinux, Ubuntu, and Debian.

/etc/apt/sources.list.d/belledonne.list Ex):Ubuntu 22.04

deb [arch=amd64] http://linphone.org/snapshots/ubuntu jammy stable # hotfix beta alpha

Install flow

$ wget https://www.linphone.org/snapshots/ubuntu/pubkey.gpg -O - | sudo apt-key add -
# Not doing this can result in the following error : "[SOCI] connection pool open error: Failed to find shared library for backend mysql"
$ sudo apt install libmariadb-dev
# Update & Install
$ sudo apt update
$ sudo apt install bc-flexisip

3. Creating a Flexisip Docker image

Copy the created packages below to the flexisip/docker directory to proceed with the work.

bc-flexisip_2.3.0-0.*_amd64.deb
bc-flexisip-dbgsym_2.3.0-0.*_amd64.ddeb

Create a Dockerfile named "flex-from-ubuntu-deb" based on Ubuntu 22.04 by referring to flex-from-deb. Then add the build command to the Makefile. The installation of snmp-mibs-downloader, snmp, and snmpd is optional. By using SNMP, you can check and rewrite the settings of each section in the flexisip configuration file.

flex-from-ubuntu-deb

FROM ubuntu:22.04
MAINTAINER  Takanobu Fuse  [email protected]>

# Prepare dependencies
RUN apt-get update
RUN apt-get install -y nano xsdcxx gdb libmariadb3 snmp-mibs-downloader snmp snmpd iproute2

# Get flexisip package
COPY *.deb *.ddeb deb-packages/
RUN apt-get install -y /deb-packages/*
RUN rm -rf /deb-packages

# Add it to the default path
ENV PATH=$PATH:/opt/belledonne-communications/bin

WORKDIR /opt/belledonne-communications

# Generate a default configuration
RUN flexisip --dump-default all > /etc/flexisip/flexisip.conf

VOLUME /etc/opt/belledonne-communications/flexisip
VOLUME /var/opt/belledonne-communications/log/flexisip
COPY flexisip-entrypoint.sh /
COPY backtrace.gdb /
RUN chmod a+x /flexisip-entrypoint.sh

# Script to wait db before launch flexisip [Licence Apache2]
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait /wait
RUN chmod +x /wait

ENTRYPOINT ["/flexisip-entrypoint.sh"]
CMD flexisip

Makefile Note)Write down only additional sections

.....
.....

# For Ubuntu 22.04
flexisip-ubuntu-deb-before:
	$(eval DOCKER_FILE = flex-from-ubuntu-deb)
	# forcing context to .
	# at the moment of the condition above being executed, $DOCKER_FILE doesn't have the right value
	$(eval CONTEXT = .)
	$(eval DOCKER_TAG = $(DOCKER_TAG)-deb)

.....
.....
.....

# For Ubuntu 22.04
flexisip-ubuntu-deb-build: flexisip-ubuntu-deb-before flexisip-build

flexisip-ubuntu-deb-push: flexisip-ubuntu-deb-before flexisip-push

flexisip-ubuntu-deb-clean: flexisip-ubuntu-deb-before flexisip-clean

.....

Build

Note)Fixed "ulimit -c unlimited*" in flexisip-entrypoint.sh, delete '*'.

$ make flexisip-ubuntu-deb-build

Check image file

$ docker images
REPOSITORY                                                      TAG                            IMAGE ID       CREATED       SIZE
gitlab.linphone.org:4567/bc/public/flexisip                     2.3.0-alpha-29-gb19a1ce5-deb   b3e1a47e3efd   9 hours ago   775MB

Start container

Since the configuration file is not defined, only the proxy mode can be launched from this image. To output the configuration file "flexisip.conf", start the container in proxy mode.

Start the container and run flexisip in proxy mode to output the default configuration.

$ docker run -d --network host --name ubuntu-flexisip  IMAGE_ID> --server proxy
$ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED       STATUS       PORTS     NAMES
0fd6f8e90621   b3e1a47e3efd   "/flexisip-entrypoin…"   9 hours ago   Up 9 hours             ubuntu-flexisip

Copy flexisip.conf

$ docker cp ubuntu-flexisip:/etc/flexisip/flexisip.conf ./

4. SSL/TLS authentication procedure with Certbot Docker container

The following tasks are to be performed on the host machine.

SSL (TLS) authentication is essential for operating a system with flexisip. Please obtain it in advance using Docker containers and reflect it in the settings of nginx and flexisip.

Note) $PWD: directory in which executed command.

$ docker run -it --rm --name certbot -v "$PWD/letsencrypt:/etc/letsencrypt" -p 80:80 certbot/certbot certonly --standalone -d www.example.com

Add the following renew command using the Certbot Docker container to the host machine's cron job.

Note) When specifying a directory, please use an absolute path.

$ docker stop nginx && docker run -it --rm --name certbot -v "/??/??/.../letsencrypt:/etc/letsencrypt" -p 80:80 certbot/certbot renew && docker start nginx

The SSL certificate is valid for 90 days, so we recommend renewing it every 60 days to ensure uninterrupted service.

Configure in flexisip.conf as follows.

tls-certificates-file=/etc/letsencrypt/live/sip.example.com/fullchain.pem
tls-certificates-private-key=/etc/letsencrypt/live/sip.example.com/privkey.pem
tls-certificates-ca-file=/etc/letsencrypt/live/sip.example.com/cert.pem

5. Preparing for Flexisip Account Manager installation

flexisip-account-manage designed by Laravel (php framework)

Create a dockerfile for building a custom image called php-fpm-alpine-laravel that can be used as a service in a Docker Compose file:

To install Composer and PHP extensions, we can use docker-php-extension-installer, which is recommended by the official PHP page on DockerHub.

php-fpm-alpine-laravel

FROM php:fpm-alpine

# Set working directory
WORKDIR /var/www/html

RUN apk add --no-cache bash nano libpng-dev freetype-dev libjpeg-turbo-dev libxml2-dev

# Install Composer and PHP extensions
RUN curl -sSLf \
        -o /usr/local/bin/install-php-extensions \
        https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions && \
    chmod +x /usr/local/bin/install-php-extensions && \
    install-php-extensions redis mysqli xmlrpc pdo_mysql @composer && \
    IPE_GD_WITHOUTAVIF=1 install-php-extensions gd

# Installing Laravel
RUN chown -R www-data:www-data /var/www/html
RUN composer global require laravel/installer \
    && ln -s /root/.config/composer/vendor/laravel/installer/bin/laravel /usr/local/bin/laravel

Download flexisip-account-manager in the same directory as the docker-compose.yml file that will be created later.

$ git clone https://github.com/BelledonneCommunications/flexisip-account-manager.git

6. Creating a Docker Compose file

docker-compose.yml

version: '3.5'

services:
##### redis-server
  redis:
    container_name: redis
    image: redis:alpine
    volumes:
        - ./redis:/etc/redis
    # need to download default config file:redis.conf from https://redis.io/topics/config
    # then modify it to enable the auth access(password), and input it into /redis/etc directory.
    command: ["redis-server", "/etc/redis/redis.conf"]
    privileged: true
    restart: always
    networks: 
      proxy-tier:

##### nginx
  nginx:
    container_name: nginx
    image: nginx:alpine
    tty: true
    ports:
      - "80:80"
      - "443:443"
    volumes:
      # nginx config
      - ./nginx:/etc/nginx/conf.d
      # certbot letsencrypt certification. Created by docker_hub certbot/certbot
      # $ docker run -it --rm --name certbot -v "$PWD/letsencrypt:/etc/letsencrypt" -p 80:80 certbot/certbot certonly --standalone -d www.example.com
      # Add the below cronjob into the host crontab.
      # docker run -it --rm --name certbot -v "/??/??/.../letsencrypt:/etc/letsencrypt" -p 80:80 certbot/certbot renew
      - ./letsencrypt:/etc/letsencrypt
      # shared the directory /flexisip-account-manager in php-fpm-laravel container
      - ./flexisip-account-manager/flexiapi:/var/www/html/flexiapi
      # shared the directory /var/www/html in phpmysql-fpm container
      - phpmyadmin:/var/www/html/phpmyadmin
    restart: always
    networks: 
      proxy-tier:     

##### mariadb
  flexisip-mariadb:
    container_name: flexisip-mariadb
    image: mariadb
    restart: always
    volumes:
      - ./db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    networks: 
      proxy-tier:

### flexisip
  ubuntu-flexisip:
    container_name: ubuntu-flexisip
    image: gitlab.linphone.org:4567/bc/public/flexisip:2.3.0-alpha-29-gb19a1ce5-deb  
    volumes:
      - ./letsencrypt:/etc/letsencrypt
      # previously need to add "flexisip" directory and input "flexisip.conf" into it.
      - ./flexisip_conf:/etc/flexisip
      # for conference server linphone db directory
      - ./linphone:/root/.local/share/linphone
    extra_hosts:
      - "sip.example.com:192.168.xx.xx"
    depends_on:
      - redis
      - nginx
      - flexisip-mariadb
    restart: always
    # https://github.com/BelledonneCommunications/flexisip/blob/master/docker/flexisip-entrypoint.sh
    # for starting only "proxy" server
    command: ["--server","proxy"]
    # for starting "proxy, presence, conference" servers
    #command: [""]
        ## allow the privilege of network to the container
    cap_add:
      - NET_ADMIN
      - SYS_RESOURCE
    network_mode: "host"
    
##### phpmyadmin-fpm
  phpmyadmin-fpm:
    container_name: phpmyadmin-fpm
    image: phpmyadmin/phpmyadmin:fpm-alpine
    tty: true
    expose: 
      - "9000"
    environment:
      - PMA_HOST=flexisip-mariadb
      - PMA_PORT=3306
      - PMA_ABSOLUTE_URI=http://localhost/phpmyadmin
    volumes:
      - phpmyadmin:/var/www/html
      - /sessions
    depends_on:
      - flexisip-mariadb
    restart: always
    networks: 
      proxy-tier:
        
##### php-fpm-laravel
  php-fpm-laravel:
    container_name: php-fpm-laravel
    build: 
      context: ./docker_files
      dockerfile: php-fpm-alpine-laravel      
    tty: true
    expose: 
      - "9000"
    # "php artisan serve" commmand default port
    ports:
      - 8000:8000
    volumes:
      # for laravel php framework
      - ./flexisip-account-manager/flexiapi:/var/www/html/flexiapi
      # provisioning config
      - ./xmlrpc:/opt/belledonne-communications/share/flexisip-account-manager/xmlrpc
      # Flexisip-account-manager log
      - ./log:/var/opt/belledonne-communications/log
    depends_on:
      - ubuntu-flexisip
    restart: always
    networks: 
      proxy-tier:

networks:
  proxy-tier:
    name: containers-network-ipv6
    external: true

### $ docker volume create phpmyadmin  
volumes:
  phpmyadmin:
    external: true

Note) Docker network and phpMyAdmin volume should be created in advance.

Create Bridge Network

$ docker network create --gateway 172.xx.0.1 --gateway fdxx:xxxx:xxxx:1::1 --subnet 172.xx.0.0/24 -- subnet fdxx:xxxx:xxxx:1::0/80 --ipv6 containers-network-ipv6

Create Volume

$ docker volume create phpmyadmin

7. Starting and operating in containers

Start up

$ docker compose up -d

The following tasks will be performed inside the container : php-fpm-laravel

$ docker compose exec php-fpm-laravel sh
# cd flexiapi

① Download the necessary dependency packages for flexisip-account-manager

# composer install --no-dev

② Create a .env file and apply a security key. Configure authentication SMTP mail server, database, etc. in the .env file.

# cp env.example .env
# php artisan key:generate

③ Create database for Linphone user accounts

# php artisan migrate

④ Register users from the web frontend.

Ficus Home.myvnc.com Register Email

Configure administrator user: Set the registered user as an administrator in the flexisip-account-manager

# php artisan accounts:set-admin {account_id}

Note)

# php artisan --help 
# php artisan cache:clear

Note) The front-end is composed of the flexisip-account-manager/flexiapi directory created with Laravel (the flexisip-account-manager/xmlrpc directory is not needed).

The configuration files are stored in the flexisip-account-manager/flexiapi/config directory. The .env file is used to override the variables in this configuration file.

Ficus Home.myvnc.com Admin Accounts

Ficus Home.myvnc.com Admin Accounts Show

2023/04/26 Additional Note)  

It is possible to implement account authentication via SMS transmission by installing the VONAGE package that corresponds to the Laravel Notification class. Prior registration for a VONAGE account (which includes a trial SMS transmission service for up to 2 euros without requiring credit card registration) is required.

Once registered, an API key and API secret will be provided, which should be recorded in the .env file.

.env

# Vonage SMS API
VONAGE_KEY=xxxxxxxxxx
VONAGE_SECRET=xxxxxxxxxxxxxxx
VONAGE_SMS_FROM=1234567890 (During the trial period, any phone number can be used)

Install the necessary package using composer:

# composer require laravel/vonage-notification-channel

To create a new class called VonageSMS for sending SMS messages by extending the Notification class:

# php artisan make:notification VonageSMS

This command will create a new file called VonageSMS.php in the app/Notifications directory. You can then modify this file to customize the SMS message and the logic for sending it using the VONAGE API.

New File

app/Notifications/VonageSMS.php

Modified Files

app/Alias.php
app/PhoneChangeCode.php
app/Http/Controllers/Account/RegisterController.php
app/Http/Controllers/Account/AuthenticateController.php
app/Http/Controllers/Api/AccountController.php
app/Http/Controllers/Api/AccountPhoneController.php

If you have any further requests or need more details, please refer to the contact page and get in touch with us.

Register by Phone

 

Sms Validate Pin

 

Vonage Received