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
This commit is contained in:
Leif Madsen 2016-02-25 11:29:05 -05:00 committed by Matthew Fredrickson
parent 7ea1e181dc
commit 0da36fca6b
5 changed files with 140 additions and 0 deletions

1
.gitignore vendored
View File

@ -33,4 +33,5 @@ menuselect-tree
*.gcda
latex
doxygen.log
out/

View File

@ -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"]

View File

@ -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

39
contrib/docker/README.md Normal file
View File

@ -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

72
contrib/docker/make-package.sh Executable file
View File

@ -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 .