Freeswitch CI/CD with GitHub Actions, DroneCI [PART 2]

Freeswitch CI/CD with github actions / Drone CI, In this article we will build freeswitch and generate .deb file installable for ubuntu22

Freeswitch CI/CD with GitHub Actions, DroneCI [PART 2]
Photo by Josue Isai Ramos Figueroa on Unsplash

This series of articles is for Freeswitch developers, to help them achieve a better & modern CI/CD.

In the previous article (Part 1) we installed Freeswitch across Ubuntu 22.04 LTS & Debian 11 bullseye, with better handling of dependencies, also we were able to generate FreeSWITCH .deb files, and store them into an s3 bucket for future deployments.

A reminder to the goal of this series of articles is to cover :

So, let’s create a file called freeswitch-build.sh in the root folder of our repository.

This file should be called from any CI tool (Github Actions or Drone CI for our case), and will contains all the commands we saw in the part 1 of this series, in order to generate a .deb file but this time it will be automated after every push command :

#!/bin/sh 
set -e 
 
apt update -y  
apt upgrade -y  
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata 
apt install curl wget git subversion build-essential autoconf automake libtool libncurses5 libncurses5-dev make libjpeg-dev libtool libtool-bin libsqlite3-dev libpcre3-dev libspeexdsp-dev libldns-dev libedit-dev yasm liblua5.2-dev libopus-dev cmake libtiff-dev  libcodec2-dev libcodec2-dev portaudio19-dev libmagickcore-dev libmp3lame-dev libmpg123-dev libshout3-dev libvlc-dev libpq-dev libmariadb-dev libldap2-dev erlang librabbitmq-dev libsmpp34-dev libyaml-dev libmongoc-dev libopencv-dev  libmemcached-dev libavformat-dev  libh2o-dev libsoundtouch-dev libhiredis-dev libopus-dev  autoconf automake devscripts gawk gettext libcurl4-openssl-dev libdb-dev libedit-dev libgdbm-dev libldns-dev libncurses5-dev libopus-dev libopus-ocaml libpcre3-dev libperl-dev libpq-dev libspeex-dev libspeexdsp-dev libssl-dev libtiff5-dev libtool libtool-bin libvorbis0a libogg0 libsqlite3-dev libogg-dev libvorbis-dev portaudio19-dev libshout3-dev libmpg123-dev libmp3lame-dev yasm libbsd-dev flite flite1-dev libflite1 liblua5.2-0 liblua5.2-dev lua5.2 luarocks libsndfile-dev -y 
 
#gcc g++  
apt install gcc-10 g++-10 cpp-10 -y  
ln -s /usr/bin/gcc-10 /usr/bin/gcc  
ln -s /usr/bin/g++-10 /usr/bin/g++ 
 
#openssl 
mkdir -p /opt/openssl  
wget https://www.openssl.org/source/openssl-1.1.1q.tar.gz --no-check-certificate -P /opt/openssl/ 
tar -xzvf /opt/openssl/openssl-1.1.1q.tar.gz -C /opt/openssl/  
cd /opt/openssl/openssl-1.1.1q 
./config  
make install 
cp /usr/local/bin/openssl /usr/bin/openssl 
 
 
#spandsp 
cd /opt 
git clone https://github.com/freeswitch/spandsp /opt/spandsp 
cd /opt/spandsp 
./bootstrap.sh 
./configure 
make 
make install  
 
 
 
#sofia-sip 
cd /opt 
git clone https://github.com/freeswitch/sofia-sip.git /opt/sofia-sip 
cd /opt/sofia-sip 
./bootstrap.sh 
./configure 
make 
make install  
 
 
cd /opt 
git clone https://github.com/freeswitch/freeswitch.git -b v1.10.8 /opt/freeswitch 
cd /opt/freeswitch 
./bootstrap.sh -j 
CFLAGS=-Wno-error ./configure --prefix=/usr/local/freeswitch --enable-core-pgsql-support --enable-zrtp 
 
#here you can customize the modules to load in Freeswitch by editing this file : /opt/freeswitch/modules.conf 
make 
 
#generate deb file 
 
mkdir -p /opt/freeswitch/freesiwtch-v1.10.8/DEBIAN 
cat > /opt/freeswitch/freesiwtch-v1.10.8/DEBIAN/control << EOL 
Package: FreeSWITCH  
Version: v1.10.8 
Architecture: all 
Maintainer: Soufiane Bouchaara <[email protected]> 
Description: FreeSWITCH 
EOL 
 
mkdir -p /opt/freesiwtch/freesiwtch-v1.10.8/usr/local 
mkdir -p /opt/freesiwtch/freesiwtch-v1.10.8/usr/local/freesiwtch/lib/ 
mkdir -p /opt/freesiwtch/freesiwtch-v1.10.8/usr/local/bin 
mkdir -p /opt/freesiwtch/freesiwtch-v1.10.8/usr/local/freeswitch/lib 
cp /opt/freesiwtch/freeswitch /opt/freesiwtch/freesiwtch-v1.10.8/usr/local/bin/ 
cp /opt/freesiwtch/fs_cli /opt/freesiwtch/freesiwtch-v1.10.8/usr/local/bin/ 
cp -r /opt/freesiwtch/.libs /opt/freesiwtch/freesiwtch-v1.10.8/usr/local/bin/ 
cp -r /opt/freesiwtch/freesiwtch-v1.10.8/usr/local/bin/.libs /opt/freesiwtch/freesiwtch-v1.10.8/usr/local/freesiwtch/lib 
dpkg-deb --build --root-owner-group /opt/freesiwtch/freesiwtch-v1.10.8 
 
# freesiwtch-v1.10.8.deb is ready to be pushed to S3 Bucket

GitHub Actions

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline.

You can create workflows that build and test every pull request to your repository or deploy merged pull requests to production.

For that, let’s create the folder workflows inside .github folder.

Then let’s create the file build.yaml to define the build steps :

The file build.yaml should be as follow :

name: Build Freeswitch 
on: 
  push: 
  pull_request: 
 
jobs: 
  build: 
    runs-on: ubuntu-22.04 
 
    steps: 
    - uses: actions/checkout@v2 
    - run: bash freeswitch-build.sh 
         
    - name: Configure AWS credentials 
      uses: s3-actions/s3cmd@v0 
      with: 
        provider: "aws" 
        access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} 
        secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 
        region: us-east-1 
         
    - name: Copy deb file to S3 Bucket 
      run: | 
        s3cmd sync freesiwtch-v1.10.8.deb s3://xxxxxx/freeswitch/freesiwtch-v1.10.8.deb

Secrets should be stored inside your repository -> Settings -> Actions -> secrets :

then create the following 2 secrets :

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY

Drone CI

Drone CI is an open-source CI server acquired by Harness. It is used to build and test software, either on a developer’s local machine or in a continuous integration environment like any public cloud.

With Drone, you can automate your software delivery pipeline from code commit to production

Using Drone CI, the YAML configuration file should be as follow:

--- 
kind: pipeline 
type: kubernetes 
name: freeswitch 
service_account_name: drone-runner-aws-privileges 
 
steps: 
  - name: Compile Freeswitch (AMD Architecture) 
    image: ubuntu:22.04 
    resources: 
      limits: 
        cpu: 2000 
        memory: 4096MiB     
    commands: 
      - /bin/bash freeswitch-build.sh

You can also build a deb file for ARM Architecture:

- name: Compile Freeswitch (ARM Architecture) 
    image: arm64v8/ubuntu:22.04 
    resources: 
      limits: 
        cpu: 2000 
        memory: 4096MiB     
    commands: 
      - /bin/bash freeswitch.sh

to Upload your .deb file to S3 bucket :

upload: 
    image: plugins/s3 
    source: foo/bar.txt 
    target: / 
    bucket: my-test-bucket-1234 
    secrets: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY]

Thank you for your time, reading this article, the next articles will cover the following topics :

  • PART 3: Adding Freeswitch sounds & custom ringtones to the FreeSWITCH.deb installer.
  • PART 4: Continuous Deployment (CD) for FreeSWITCH deployment with Ansible.

If you face any issues, please feel free to contact me at contact[at]soufianebouchaara.com