Skip to content

Commit 278901c

Browse files
authored
🎉 v1.0.0 (#1)
1 parent df7b710 commit 278901c

File tree

6 files changed

+291
-1
lines changed

6 files changed

+291
-1
lines changed

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 rtckit
3+
Copyright (c) 2021 Ciprian Dosoftei
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Diff for: README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<a href="#build-minimal-freeswitch-docker-images">
2+
<img loading="lazy" src="https://raw.github.com/rtckit/media/master/slimswitch/readme-splash.png" alt="slimswitch" class="width-full">
3+
</a>
4+
5+
# Build minimal FreeSWITCH Docker images
6+
7+
[![Docker Pulls](https://img.shields.io/docker/pulls/rtckit/slimswitch-builder.svg)](https://hub.docker.com/r/rtckit/slimswitch-builder)
8+
[![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
9+
10+
Tooling for creating lean FreeSWITCH Docker images; resulting containers are efficient and expose a reduced attack surface. This is achieved by layering only the FreeSWITCH core and modules alongside their its runtime dependencies.
11+
12+
## Quickstart
13+
14+
Decide which FreeSWITCH modules should be included and provide a basic XML core/modules configuration file!
15+
16+
```sh
17+
git clone https://github.com/rtckit/slimswitch.git
18+
cd slimswitch
19+
20+
./bin/mkslim.sh \
21+
-m mod_commands -m mod_dptools -m mod_sofia \
22+
-s local/awesome-switch
23+
docker run --rm -it \
24+
-v "$(pwd)/freeswitch.xml":/etc/freeswitch/freeswitch.xml \
25+
local/awesome-switch:v1.10.7
26+
```
27+
28+
![Quickstart](https://raw.github.com/rtckit/media/master/slimswitch/demo.gif)
29+
30+
## Requirements
31+
32+
[Docker](https://docs.docker.com/get-docker/) and [docker-slim](https://dockersl.im/install.html) must be installed in the building environment.
33+
34+
## How it works
35+
36+
A generic reusable [builder image](etc/Dockerfile) is created first; the goal is to build the FreeSWITCH core and most of its modules, so then they can be mixed-and-matched as needed. The resulting image can also serve as a base for compiling third party modules. This phase is handled by the [./bin/mkbuilder.sh](./bin/mkbuilder.sh) script. Images corresponding to official FreeSWITCH releases are also [publicly available](https://hub.docker.com/r/rtckit/slimswitch-builder).
37+
38+
The trimming is achieved via the [./bin/mkslim.sh](./bin/mkslim.sh) script, which is essentially a wrapper for docker-slim; specifically, it leverages its static analysis features so dynamic dependencies are accounted for when the final image is created.
39+
40+
## License
41+
42+
MIT, see [LICENSE file](LICENSE).
43+
44+
### Acknowledgments
45+
46+
* [FreeSWITCH](https://github.com/signalwire/freeswitch), FreeSWITCH is a registered trademark of Anthony Minessale II
47+
* [Docker](https://docker.com), Docker is a registered trademark of Docker, Inc
48+
* [docker-slim](https://github.com/docker-slim/docker-slim)
49+
50+
### Contributing
51+
52+
Bug reports (and small patches) can be submitted via the [issue tracker](https://github.com/rtckit/slimswitch/issues). Forking the repository and submitting a Pull Request is preferred for substantial patches.

Diff for: bin/mkbuilder.sh

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/sh
2+
3+
ETC_PATH="`dirname $0`"/../etc
4+
5+
. ${ETC_PATH}/config.sh
6+
7+
if [ ! -x "$(command -v docker)" ]; then
8+
printf "Cannot find docker\n"
9+
exit 1
10+
fi
11+
12+
# Process arguments
13+
while :; do
14+
case $1 in
15+
-d)
16+
if [ -n "$2" ]; then
17+
DEBIAN_RELEASE=$2
18+
shift
19+
else
20+
printf "Cannot pass -d without Debian release argument (e.g. ${DEBIAN_RELEASE})\n" >&2
21+
exit 1
22+
fi
23+
;;
24+
-t)
25+
if [ -n "$2" ]; then
26+
FREESWITCH_TAG=$2
27+
shift
28+
else
29+
printf "Cannot pass -t without FreeSWITCH tag argument (e.g. ${FREESWITCH_TAG})\n" >&2
30+
exit 1
31+
fi
32+
;;
33+
-r)
34+
if [ -n "$2" ]; then
35+
BUILDER_REPOSITORY=$2
36+
shift
37+
else
38+
printf "Cannot pass -r without builder Docker image repository name argument (e.g. ${BUILDER_REPOSITORY})\n" >&2
39+
exit 1
40+
fi
41+
;;
42+
-h)
43+
printf "slimswitch mkbuilder.sh utility\n"
44+
printf "https://github.com/rtckit/slimswitch\n\n"
45+
printf "Usage: %s [-d <Debian release>] [-t <FreeSWITCH tag>] [-r <Builder image repository>]\n" "$0"
46+
printf "\t-d Base Debian image tag (default: %s)\n" "${DEBIAN_RELEASE}"
47+
printf "\t-t Builder image tag (default: %s)\n" "${FREESWITCH_TAG}"
48+
printf "\t-r Builder image repository (default: %s)\n" "${BUILDER_REPOSITORY}"
49+
exit 0
50+
;;
51+
-?*)
52+
printf "Unknown argument %s\n" "$1" >&2
53+
exit 1
54+
;;
55+
*)
56+
break
57+
esac
58+
59+
shift
60+
done
61+
62+
docker build \
63+
--build-arg FREESWITCH_TAG=${FREESWITCH_TAG} \
64+
-t ${BUILDER_REPOSITORY}:${FREESWITCH_TAG} \
65+
-f ${ETC_PATH}/Dockerfile ${ETC_PATH}

Diff for: bin/mkslim.sh

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/bin/sh
2+
3+
ETC_PATH="`dirname $0`"/../etc
4+
5+
. ${ETC_PATH}/config.sh
6+
7+
if [ ! -x "$(command -v docker)" ]; then
8+
printf "Cannot find docker\n"
9+
exit 1
10+
fi
11+
12+
if [ ! -x "$(command -v docker-slim)" ]; then
13+
printf "Cannot find docker-slim\n"
14+
exit 1
15+
fi
16+
17+
SLIM_REPOSITORY=""
18+
MODULE_FLAGS=""
19+
INCLUDE_FLAGS=""
20+
21+
# Process arguments
22+
while :; do
23+
case $1 in
24+
-t)
25+
if [ -n "$2" ]; then
26+
FREESWITCH_TAG=$2
27+
shift
28+
else
29+
printf "Cannot pass -t without FreeSWITCH tag argument (e.g. ${FREESWITCH_TAG})\n" >&2
30+
exit 1
31+
fi
32+
;;
33+
-r)
34+
if [ -n "$2" ]; then
35+
BUILDER_REPOSITORY=$2
36+
shift
37+
else
38+
printf "Cannot pass -r without builder Docker image repository name argument (e.g. ${BUILDER_REPOSITORY})\n" >&2
39+
exit 1
40+
fi
41+
;;
42+
-s)
43+
if [ -n "$2" ]; then
44+
SLIM_REPOSITORY=$2
45+
shift
46+
else
47+
printf "Cannot pass -s without slim Docker image repository name argument\n" >&2
48+
exit 1
49+
fi
50+
;;
51+
-m)
52+
if [ -n "$2" ]; then
53+
MODULE_FLAGS="${MODULE_FLAGS} --include-exe=/usr/lib/freeswitch/mod/$2.so"
54+
shift
55+
else
56+
printf "Cannot pass -m without FreeSWSITCH module name argument (e.g. mod_commands)\n" >&2
57+
exit 1
58+
fi
59+
;;
60+
-i)
61+
if [ -n "$2" ]; then
62+
INCLUDE_FLAGS="${INCLUDE_FLAGS} --include-path=$2"
63+
shift
64+
else
65+
printf "Cannot pass -i without include path argument (e.g. /usr/share/freeswitch/sounds)\n" >&2
66+
exit 1
67+
fi
68+
;;
69+
-h)
70+
printf "slimswitch mkslim.sh utility\n"
71+
printf "https://github.com/rtckit/slimswitch\n\n"
72+
printf "Usage: %s [-t <FreeSWITCH tag>] [-r <Builder image repository>] [-s <Slim image repository>] [-m <FreeSWITCH module>] [-i <Path>]\n" "$0"
73+
printf "\t-t Builder image tag (default: %s)\n" "${FREESWITCH_TAG}"
74+
printf "\t-r Builder image repository (default: %s)\n" "${BUILDER_REPOSITORY}"
75+
printf "\t-s Slim image repository (e.g. -s my-org/telco-project)\n"
76+
printf "\t-m FreeSWITCH module, can be used multiple times (e.g. -m mod_mariadb -m mod_shout)\n"
77+
printf "\t-i Keep path from builder image, can be used multiple times (e.g. -i /usr/share/freeswitch/sounds)\n"
78+
exit 0
79+
;;
80+
-?*)
81+
printf "Unknown argument %s\n" "$1" >&2
82+
exit 1
83+
;;
84+
*)
85+
break
86+
esac
87+
88+
shift
89+
done
90+
91+
docker image inspect ${BUILDER_REPOSITORY}:${FREESWITCH_TAG} > /dev/null 2>&1
92+
LOCAL_BUILDER=$?
93+
94+
if [ $LOCAL_BUILDER -ne 0 ]; then
95+
printf "Local builder image not found, checking public DockerHub images ...\n"
96+
97+
curl --silent -f -lSL https://index.docker.io/v1/repositories/${BUILDER_REPOSITORY}/tags/${FREESWITCH_TAG} > /dev/null 2>&1
98+
DOCKERHUB_BUILDER=$?
99+
100+
if [ $DOCKERHUB_BUILDER -ne 0 ]; then
101+
printf "Builder image not found on DockerHub, creating it locally ...\n"
102+
"`dirname $0`"/mkbuilder.sh
103+
else
104+
printf "Pulling builder image from DockerHub ...\n"
105+
docker pull ${BUILDER_REPOSITORY}:${FREESWITCH_TAG}
106+
fi
107+
else
108+
printf "Using local builder docker image ...\n"
109+
fi
110+
111+
if [ -z "$SLIM_REPOSITORY" ]; then
112+
SLIM_REPOSITORY=$(printf '%s' "$BUILDER_REPOSITORY" | sed -e 's/-builder/-slim/g')
113+
fi
114+
115+
docker-slim build \
116+
--http-probe-off \
117+
--continue-after 1 \
118+
--include-cert-all \
119+
--entrypoint=/bin/true \
120+
--include-exe=/usr/bin/freeswitch ${MODULE_FLAGS} \
121+
${INCLUDE_FLAGS} \
122+
--exclude-pattern=/bin/true \
123+
--target ${BUILDER_REPOSITORY}:${FREESWITCH_TAG} \
124+
--tag ${SLIM_REPOSITORY}:${FREESWITCH_TAG}

Diff for: etc/Dockerfile

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
ARG DEBIAN_RELEASE=bullseye
2+
3+
FROM debian:${DEBIAN_RELEASE}
4+
5+
ARG FREESWITCH_TAG=v1.10.7
6+
7+
# Prerequisites
8+
RUN apt-get update && \
9+
apt-get install -y gnupg2 wget lsb-release && \
10+
wget -O /usr/share/keyrings/freeswitch-archive-keyring.gpg https://files.freeswitch.org/repo/deb/debian-release/freeswitch-archive-keyring.gpg && \
11+
echo "deb [signed-by=/usr/share/keyrings/freeswitch-archive-keyring.gpg] http://files.freeswitch.org/repo/deb/debian-release/ `lsb_release -sc` main" > /etc/apt/sources.list.d/freeswitch.list && \
12+
echo "deb-src [signed-by=/usr/share/keyrings/freeswitch-archive-keyring.gpg] http://files.freeswitch.org/repo/deb/debian-release/ `lsb_release -sc` main" >> /etc/apt/sources.list.d/freeswitch.list && \
13+
apt-get update && \
14+
apt-get build-dep -y freeswitch
15+
16+
# Pull desired code base
17+
RUN mkdir -p /usr/src && \
18+
cd /usr/src && \
19+
wget https://codeload.github.com/signalwire/freeswitch/tar.gz/refs/tags/${FREESWITCH_TAG} -O - | tar zvx
20+
21+
# Configure
22+
RUN cd /usr/src/freeswitch* && \
23+
./bootstrap.sh -j && \
24+
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-debug
25+
26+
# Enable most modules
27+
RUN cd /usr/src/freeswitch* && \
28+
cp ./build/modules.conf.most modules.conf && \
29+
sed -i \
30+
-e "s/#databases\/mod_mariadb/databases\/mod_mariadb/g" \
31+
-e "s/applications\/mod_mongo/#applications\/mod_mongo/g" \
32+
-e "s/applications\/mod_mp4/#applications\/mod_mp4/g" \
33+
-e "s/codecs\/mod_sangoma_codec/#codecs\/mod_sangoma_codec/g" \
34+
-e "s/codecs\/mod_siren/#codecs\/mod_siren/g" \
35+
modules.conf
36+
37+
# Build and install
38+
RUN cd /usr/src/freeswitch* && make -j && make install
39+
40+
# Install audio files
41+
RUN cd /usr/src/freeswitch* && make sounds-install && make moh-install
42+
43+
ENTRYPOINT ["/usr/bin/freeswitch", "-nonat"]

Diff for: etc/config.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
# Default configuration
4+
export DEBIAN_RELEASE=bullseye
5+
export FREESWITCH_TAG=v1.10.7
6+
export BUILDER_REPOSITORY=rtckit/slimswitch-builder

0 commit comments

Comments
 (0)