Add initial support to build Docker images
authorLeif Madsen <leif@leifmadsen.com>
Thu, 25 Feb 2016 16:29:05 +0000 (11:29 -0500)
committerMatthew Fredrickson <creslin@digium.com>
Thu, 17 Mar 2016 14:53:57 +0000 (09:53 -0500)
This work-in-progress is the first step to being able to reliably
build Asterisk containers from the Asterisk source. I'm submitting
this based on feedback gained at AstriDevCon 2015.

Information about how to use this is provided in contrib/docker/README.md
and will result in a local Asterisk container being built right from
your source. I believe this can eventually be automated via
hub.docker.com.

Change-Id: Ifa070706d40e56755797097b6ed72c1e243bd0d1

.gitignore
contrib/docker/Dockerfile.asterisk [new file with mode: 0644]
contrib/docker/Dockerfile.packager [new file with mode: 0644]
contrib/docker/README.md [new file with mode: 0644]
contrib/docker/make-package.sh [new file with mode: 0755]

index 0281e10..1a6deef 100644 (file)
@@ -33,4 +33,5 @@ menuselect-tree
 *.gcda
 latex
 doxygen.log
+out/
 
diff --git a/contrib/docker/Dockerfile.asterisk b/contrib/docker/Dockerfile.asterisk
new file mode 100644 (file)
index 0000000..41bf435
--- /dev/null
@@ -0,0 +1,19 @@
+# Version 0.0.3
+FROM centos:7
+MAINTAINER Leif Madsen <leif@leifmadsen.com>
+ENV REFRESHED_AT 2016-02-25
+ENV STARTDIR /tmp
+ENV RPMPATH ./out
+
+# copy is required because you can't mount volumes during build
+COPY $RPMPATH/*.rpm $STARTDIR
+
+# install dependencies and Asterisk RPM
+RUN yum install epel-release -y && \
+    yum install -y *.rpm && \
+    yum clean all && \
+    yum autoremove -y && \
+    /sbin/ldconfig
+
+ENTRYPOINT ["/usr/sbin/asterisk"]
+CMD ["-c", "-vvvv", "-g"]
diff --git a/contrib/docker/Dockerfile.packager b/contrib/docker/Dockerfile.packager
new file mode 100644 (file)
index 0000000..3588210
--- /dev/null
@@ -0,0 +1,9 @@
+FROM alanfranz/fwd-centos-7:latest
+MAINTAINER Leif Madsen <leif@leifmadsen.com>
+ENV REFRESHED_AT 2016-02-25
+ADD contrib/scripts/install_prereq /tmp/install_prereq
+RUN yum clean metadata && \
+    yum -y update && \
+    yum install epel-release -y && \
+    yum clean all &&\
+    /tmp/install_prereq install
diff --git a/contrib/docker/README.md b/contrib/docker/README.md
new file mode 100644 (file)
index 0000000..2a9bd66
--- /dev/null
@@ -0,0 +1,39 @@
+# Building Asterisk into a Docker Container Image
+The following set of steps should leave you with a Docker container that
+is relatively small, built from your local checked out source, and even
+provides you with a nice little RPM too!
+
+## Build the package container image
+Build the package container image. This uses FPM[1] so no `spec` files and
+such are necessary.
+```
+docker build --pull -f contrib/docker/Dockerfile.packager -t asterisk-build .
+```
+
+## Build your Asterisk RPM from source
+Build the Asterisk RPM from the resulting container image.
+```
+docker run -ti \
+    -v $(pwd):/application:ro \
+    -v $(pwd)/out:/build \
+    -w /application asterisk-build \
+    /application/contrib/docker/make-package.sh 13.6.0
+```
+> **NOTE**: If you need to build this on a system that has SElinux enabled
+> you'll need to use the following command instead:
+> ```
+> docker run -ti \
+>     -v $(pwd):/application:Z \
+>     -v $(pwd)/out:/build:Z \
+>     -w /application asterisk-build \
+>     /application/contrib/docker/make-package.sh 13.6.0
+> ```
+
+## Create your Asterisk container image
+Now create your own Asterisk container image from the resulting RPM.
+```
+docker build --rm -t madsen/asterisk:13.6.0-1 -f contrib/docker/Dockerfile.asterisk .
+```
+
+# References
+[1] https://github.com/jordansissel/fpm
diff --git a/contrib/docker/make-package.sh b/contrib/docker/make-package.sh
new file mode 100755 (executable)
index 0000000..261df60
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/bash
+# This script intended to be run from the packager container. Please see the
+# README.md file for more information on how this script is used.
+#
+set -ex
+[ -n "$1" ]
+mkdir -p /opt
+
+# move into the application directory where Asterisk source exists
+cd /application
+
+# strip the source of any Git-isms
+rsync -av --exclude='.git' . /tmp/application
+
+# move to the build directory and build Asterisk
+cd /tmp/application
+./configure
+cd menuselect
+make menuselect
+cd ..
+make menuselect-tree
+
+menuselect/menuselect --check-deps menuselect.makeopts
+
+# Do not include sound files. You should be mounting these from and external
+# volume.
+sed -i -e 's/MENUSELECT_MOH=.*$/MENUSELECT_MOH=/' menuselect.makeopts
+sed -i -e 's/MENUSELECT_CORE_SOUNDS=.*$/MENUSELECT_CORE_SOUNDS=/' menuselect.makeopts
+
+# Build it!
+make all install DESTDIR=/tmp/installdir
+
+rm -rf /tmp/application
+cd /build
+
+# Use the Fine Package Management system to build us an RPM without all that
+# reeking effort.
+fpm -t rpm -s dir -n asterisk-custom --version "$1" \
+    --depends libedit \
+    --depends libxslt \
+    --depends jansson \
+    --depends pjproject \
+    --depends openssl \
+    --depends libxml2 \
+    --depends unixODBC \
+    --depends libcurl \
+    --depends libogg \
+    --depends libvorbis \
+    --depends speex \
+    --depends spandsp \
+    --depends freetds \
+    --depends net-snmp \
+    --depends iksemel \
+    --depends corosynclib \
+    --depends newt \
+    --depends lua \
+    --depends sqlite \
+    --depends freetds \
+    --depends radiusclient-ng \
+    --depends postgresql \
+    --depends neon \
+    --depends libical \
+    --depends openldap \
+    --depends sqlite2 \
+    --depends mysql \
+    --depends bluez \
+    --depends gsm \
+    --depends libuuid \
+    --depends libsrtp \
+    -C /tmp/installdir etc usr var
+
+chown -R --reference /application/contrib/docker/make-package.sh .