[Asterisk-code-review] Add initial support to build Docker images (asterisk[master])

Matthew Fredrickson asteriskteam at digium.com
Thu Mar 17 09:53:57 CDT 2016


Matthew Fredrickson has uploaded a new change for review.

  https://gerrit.asterisk.org/2428

Change subject: Add initial support to build Docker images
......................................................................

Add initial support to build Docker images

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
---
M .gitignore
A contrib/docker/Dockerfile.asterisk
A contrib/docker/Dockerfile.packager
A contrib/docker/README.md
A contrib/docker/make-package.sh
5 files changed, 140 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/28/2428/1

diff --git a/.gitignore b/.gitignore
index 0281e10..1a6deef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,4 +33,5 @@
 *.gcda
 latex
 doxygen.log
+out/
 
diff --git a/contrib/docker/Dockerfile.asterisk b/contrib/docker/Dockerfile.asterisk
new file mode 100644
index 0000000..41bf435
--- /dev/null
+++ b/contrib/docker/Dockerfile.asterisk
@@ -0,0 +1,19 @@
+# Version 0.0.3
+FROM centos:7
+MAINTAINER Leif Madsen <leif at 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
index 0000000..3588210
--- /dev/null
+++ b/contrib/docker/Dockerfile.packager
@@ -0,0 +1,9 @@
+FROM alanfranz/fwd-centos-7:latest
+MAINTAINER Leif Madsen <leif at 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
index 0000000..2a9bd66
--- /dev/null
+++ b/contrib/docker/README.md
@@ -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
index 0000000..261df60
--- /dev/null
+++ b/contrib/docker/make-package.sh
@@ -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 .

-- 
To view, visit https://gerrit.asterisk.org/2428
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifa070706d40e56755797097b6ed72c1e243bd0d1
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Matthew Fredrickson <creslin at digium.com>



More information about the asterisk-code-review mailing list