Skip to content

Commit 1d29b13

Browse files
authored
Merge pull request #2790 from signalwire/dockerfile
[BUILD] Add Dockerfiles and related small fixes.
2 parents a189aaa + 04dc456 commit 1d29b13

File tree

6 files changed

+369
-8
lines changed

6 files changed

+369
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Dockerfile for building Debian base-image with FreeSWITCH dependencies (repo)
2+
3+
# Build the image:
4+
# docker build -t fs-base-image --build-arg FS_TOKEN=your_token_here -f docker/build/base-image-from-repo.Dockerfile .
5+
#
6+
# Or build using secrets (recommended for tokens):
7+
# docker build -t fs-base-image --secret id=fs_token,env=FS_TOKEN -f docker/build/base-image-from-repo.Dockerfile .
8+
9+
# Stage 1: Install FreeSWITCH using fsget.sh
10+
FROM debian:bookworm AS installer
11+
12+
# Set environment variables
13+
ENV DEBIAN_FRONTEND=noninteractive
14+
15+
# Define build arguments
16+
ARG FS_TOKEN
17+
ARG FS_RELEASE=release
18+
ARG FS_INSTALL=install
19+
20+
# Set working directory
21+
WORKDIR /tmp
22+
23+
# Copy fsget.sh script
24+
COPY scripts/packaging/fsget.sh /usr/local/bin/fsget.sh
25+
RUN chmod +x /usr/local/bin/fsget.sh
26+
27+
# Install required tools
28+
RUN apt-get update && \
29+
apt-get install -y --no-install-recommends \
30+
procps \
31+
locales
32+
33+
# Install FreeSWITCH using fsget.sh with token from secret or build arg
34+
RUN --mount=type=secret,id=fs_token,target=/run/secrets/fs_token \
35+
TOKEN=${FS_TOKEN:-$(cat /run/secrets/fs_token 2>/dev/null || echo "")} && \
36+
if [ -z "$TOKEN" ]; then \
37+
echo "Error: No token provided. Use --build-arg FS_TOKEN=your_token or --secret id=fs_token,env=FS_TOKEN" && \
38+
exit 1; \
39+
fi && \
40+
/usr/local/bin/fsget.sh "$TOKEN" "$FS_RELEASE" "$FS_INSTALL"
41+
42+
# Set locale
43+
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
44+
locale-gen
45+
46+
ENV LANG en_US.UTF-8
47+
ENV LANGUAGE en_US:en
48+
ENV LC_ALL en_US.UTF-8
49+
50+
# Clean up
51+
RUN apt-get clean && \
52+
rm -rf /var/lib/apt/lists/* && \
53+
rm -f /etc/apt/sources.list.d/freeswitch.list && \
54+
rm -f /etc/apt/auth.conf && \
55+
rm -f /usr/local/bin/fsget.sh
56+
57+
# Stage 2: Final image with minimal layers
58+
FROM debian:bookworm
59+
60+
# Copy everything from the installer stage
61+
COPY --from=installer / /
62+
63+
# Set working directory
64+
WORKDIR /usr/local/src/freeswitch
65+
66+
# Set command to bash directly
67+
SHELL ["/bin/bash", "-c"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Dockerfile for building Debian base-image with FreeSWITCH dependencies (sources)
2+
3+
# Available build arguments:
4+
# BUILD_NUMBER - Package build number (default: 42)
5+
# LIBBROADVOICE_REF - Git ref for libbroadvoice (default: HEAD)
6+
# LIBILBC_REF - Git ref for libilbc (default: HEAD)
7+
# LIBSILK_REF - Git ref for libsilk (default: HEAD)
8+
# SPANDSP_REF - Git ref for spandsp (default: HEAD)
9+
# SOFIASIP_REF - Git ref for sofia-sip (default: HEAD)
10+
# LIBKS_REF - Git ref for libks (default: HEAD)
11+
# SIGNALWIRE_C_REF - Git ref for signalwire-c (default: HEAD)
12+
# LIBV8_PACKAGING_REF - Git ref for libv8-packaging (default: HEAD)
13+
#
14+
# Build the image:
15+
# docker build -t fs-base-image -f docker/build/base-image-from-source.Dockerfile .
16+
#
17+
# Build with specific tags:
18+
# docker build -t fs-base-image \
19+
# --build-arg LIBKS_REF=v1.0.0 \
20+
# --build-arg BUILD_NUMBER=123 \
21+
# -f docker/build/base-image-from-source.Dockerfile .
22+
#
23+
# Run the container with output directory mounted to host:
24+
# mkdir -p "$HOME/DEBs"
25+
# docker run -it --rm -v "$HOME/DEBs:/var/local/deb" -v "$(pwd):/usr/local/src/freeswitch" fs-base-image scripts/packaging/build/fsdeb.sh -b 42 -o /var/local/deb
26+
27+
# Stage 1: Build dependencies layer
28+
FROM debian:bookworm AS builder
29+
30+
# Set bash as the default shell
31+
SHELL ["/bin/bash", "-c"]
32+
33+
# Set environment variables
34+
ENV DEBIAN_FRONTEND=noninteractive
35+
ENV OUTPUT_DIR="/var/local/deb"
36+
37+
# Define build arguments with default
38+
ARG BUILD_NUMBER=42
39+
40+
# Define tag arguments with defaults to HEAD
41+
ARG LIBBROADVOICE_REF=HEAD
42+
ARG LIBILBC_REF=HEAD
43+
ARG LIBSILK_REF=HEAD
44+
ARG SPANDSP_REF=HEAD
45+
ARG SOFIASIP_REF=HEAD
46+
ARG LIBKS_REF=HEAD
47+
ARG SIGNALWIRE_C_REF=HEAD
48+
ARG LIBV8_PACKAGING_REF=HEAD
49+
50+
# Install minimal requirements
51+
RUN apt-get update && apt-get install -y \
52+
git \
53+
lsb-release
54+
55+
# Configure git to trust all directories
56+
RUN git config --global --add safe.directory '*'
57+
58+
# Set base dir for cloned repositories
59+
WORKDIR /usr/src
60+
61+
# Clone libbroadvoice
62+
RUN [ -d "libbroadvoice" ] || (git clone https://github.com/freeswitch/libbroadvoice.git && \
63+
cd libbroadvoice && git checkout $LIBBROADVOICE_REF)
64+
65+
# Clone libilbc
66+
RUN [ -d "libilbc" ] || (git clone https://github.com/freeswitch/libilbc.git && \
67+
cd libilbc && git checkout $LIBILBC_REF)
68+
69+
# Clone libsilk
70+
RUN [ -d "libsilk" ] || (git clone https://github.com/freeswitch/libsilk.git && \
71+
cd libsilk && git checkout $LIBSILK_REF)
72+
73+
# Clone spandsp (packages branch)
74+
RUN [ -d "spandsp" ] || (git clone --branch packages https://github.com/freeswitch/spandsp.git && \
75+
cd spandsp && git checkout $SPANDSP_REF)
76+
77+
# Clone sofia-sip
78+
RUN [ -d "sofia-sip" ] || (git clone https://github.com/freeswitch/sofia-sip.git && \
79+
cd sofia-sip && git checkout $SOFIASIP_REF)
80+
81+
# Clone libks
82+
RUN [ -d "libks" ] || (git clone https://github.com/signalwire/libks.git && \
83+
cd libks && git checkout $LIBKS_REF)
84+
85+
# Clone signalwire-c
86+
RUN [ -d "signalwire-c" ] || (git clone https://github.com/signalwire/signalwire-c.git && \
87+
cd signalwire-c && git checkout $SIGNALWIRE_C_REF)
88+
89+
# Clone libv8-packaging
90+
RUN [ -d "libv8-packaging" ] || (git clone https://github.com/freeswitch/libv8-packaging.git && \
91+
cd libv8-packaging && git checkout $LIBV8_PACKAGING_REF)
92+
93+
# Copy the build dependencies script
94+
COPY scripts/packaging/build/dependencies/build-dependencies.sh /usr/local/bin/build-dependencies.sh
95+
RUN chmod +x /usr/local/bin/build-dependencies.sh
96+
97+
# Create directories
98+
RUN mkdir -p "${OUTPUT_DIR}" /usr/src/freeswitch
99+
100+
# Copy FreeSWITCH source tree
101+
COPY . /usr/src/freeswitch
102+
103+
# Build the dependency packages
104+
RUN /usr/local/bin/build-dependencies.sh -b "$BUILD_NUMBER" -o "$OUTPUT_DIR" -p "/usr/src" -s -a -r
105+
106+
# Stage 2: Install packages layer
107+
FROM debian:bookworm AS installer
108+
109+
# Set environment variables
110+
ENV DEBIAN_FRONTEND=noninteractive
111+
WORKDIR /root
112+
113+
# Copy only the DEB files from builder stage
114+
COPY --from=builder /var/local/deb/*.deb /tmp/debs/
115+
116+
# Install required tools for setting up local repo
117+
RUN apt-get update && \
118+
apt-get install -y --no-install-recommends \
119+
apt-utils \
120+
dpkg-dev \
121+
gnupg \
122+
ca-certificates \
123+
lsb-release \
124+
procps \
125+
locales
126+
127+
# Create local repository directory
128+
RUN mkdir -p /var/local/repo && \
129+
cp /tmp/debs/*.deb /var/local/repo/
130+
131+
# Generate package index
132+
RUN cd /var/local/repo && \
133+
dpkg-scanpackages . > Packages && \
134+
gzip -9c Packages > Packages.gz
135+
136+
# Configure local repository
137+
RUN echo "deb [trusted=yes] file:/var/local/repo ./" > /etc/apt/sources.list.d/local.list && \
138+
apt-get update
139+
140+
# Install all available packages from local repo
141+
RUN ls -1 /var/local/repo/*.deb | sed -e 's|.*/||' -e 's|_.*||' | grep -Pv "\-dbgsym$" | xargs apt-get install -y --allow-downgrades -f
142+
143+
# Clean up
144+
RUN apt-get clean && \
145+
rm -rf /var/lib/apt/lists/* /tmp/debs && \
146+
rm -rf /var/local/repo && \
147+
rm -f /etc/apt/sources.list.d/local.list
148+
149+
# Set locale
150+
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
151+
locale-gen
152+
153+
ENV LANG en_US.UTF-8
154+
ENV LANGUAGE en_US:en
155+
ENV LC_ALL en_US.UTF-8
156+
157+
# Stage 3: Final image
158+
FROM debian:bookworm
159+
160+
# Copy everything from the installer stage
161+
COPY --from=installer / /
162+
163+
# Set working directory
164+
WORKDIR /usr/local/src/freeswitch
165+
166+
# Set command to bash directly
167+
SHELL ["/bin/bash", "-c"]
+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Dockerfile for building Debian packages of FreeSWITCH dependencies
2+
#
3+
# Available build arguments:
4+
# BUILD_NUMBER - Package build number (default: 42)
5+
# LIBBROADVOICE_REF - Git ref for libbroadvoice (default: HEAD)
6+
# LIBILBC_REF - Git ref for libilbc (default: HEAD)
7+
# LIBSILK_REF - Git ref for libsilk (default: HEAD)
8+
# SPANDSP_REF - Git ref for spandsp (default: HEAD)
9+
# SOFIASIP_REF - Git ref for sofia-sip (default: HEAD)
10+
# LIBKS_REF - Git ref for libks (default: HEAD)
11+
# SIGNALWIRE_C_REF - Git ref for signalwire-c (default: HEAD)
12+
# LIBV8_PACKAGING_REF - Git ref for libv8-packaging (default: HEAD)
13+
#
14+
# Build the image:
15+
# docker build -t fs-debian-package-builder -f docker/build/debs-from-source.Dockerfile .
16+
#
17+
# Build with specific tags:
18+
# docker build -t fs-debian-package-builder \
19+
# --build-arg LIBKS_REF=v1.0.0 \
20+
# --build-arg BUILD_NUMBER=123 \
21+
# -f docker/build/debs-from-source.Dockerfile .
22+
#
23+
# Run the container with output directory mounted to host:
24+
# mkdir -p "$HOME/DEBs"
25+
# docker run -v "$HOME/DEBs:/var/local/deb" fs-debian-package-builder
26+
27+
FROM debian:bookworm
28+
29+
# Set bash as the default shell
30+
SHELL ["/bin/bash", "-c"]
31+
32+
# Set environment variables
33+
ENV DEBIAN_FRONTEND=noninteractive
34+
ENV OUTPUT_DIR="/var/local/deb"
35+
36+
# Define build arguments with default
37+
ARG BUILD_NUMBER=42
38+
39+
# Define tag arguments with defaults to HEAD
40+
ARG LIBBROADVOICE_REF=HEAD
41+
ARG LIBILBC_REF=HEAD
42+
ARG LIBSILK_REF=HEAD
43+
ARG SPANDSP_REF=HEAD
44+
ARG SOFIASIP_REF=HEAD
45+
ARG LIBKS_REF=HEAD
46+
ARG SIGNALWIRE_C_REF=HEAD
47+
ARG LIBV8_PACKAGING_REF=HEAD
48+
49+
# Install minimal requirements
50+
RUN apt-get update && apt-get install -y \
51+
git \
52+
lsb-release
53+
54+
# Configure git to trust all directories
55+
RUN git config --global --add safe.directory '*'
56+
57+
# Set base dir for cloned repositories
58+
WORKDIR /usr/src
59+
60+
# Clone libbroadvoice
61+
RUN [ -d "libbroadvoice" ] || (git clone https://github.com/freeswitch/libbroadvoice.git && \
62+
cd libbroadvoice && git checkout $LIBBROADVOICE_REF)
63+
64+
# Clone libilbc
65+
RUN [ -d "libilbc" ] || (git clone https://github.com/freeswitch/libilbc.git && \
66+
cd libilbc && git checkout $LIBILBC_REF)
67+
68+
# Clone libsilk
69+
RUN [ -d "libsilk" ] || (git clone https://github.com/freeswitch/libsilk.git && \
70+
cd libsilk && git checkout $LIBSILK_REF)
71+
72+
# Clone spandsp (packages branch)
73+
RUN [ -d "spandsp" ] || (git clone --branch packages https://github.com/freeswitch/spandsp.git && \
74+
cd spandsp && git checkout $SPANDSP_REF)
75+
76+
# Clone sofia-sip
77+
RUN [ -d "sofia-sip" ] || (git clone https://github.com/freeswitch/sofia-sip.git && \
78+
cd sofia-sip && git checkout $SOFIASIP_REF)
79+
80+
# Clone libks
81+
RUN [ -d "libks" ] || (git clone https://github.com/signalwire/libks.git && \
82+
cd libks && git checkout $LIBKS_REF)
83+
84+
# Clone signalwire-c
85+
RUN [ -d "signalwire-c" ] || (git clone https://github.com/signalwire/signalwire-c.git && \
86+
cd signalwire-c && git checkout $SIGNALWIRE_C_REF)
87+
88+
# Clone libv8-packaging
89+
RUN [ -d "libv8-packaging" ] || (git clone https://github.com/freeswitch/libv8-packaging.git && \
90+
cd libv8-packaging && git checkout $LIBV8_PACKAGING_REF)
91+
92+
# Copy the build dependencies script
93+
COPY scripts/packaging/build/dependencies/build-dependencies.sh /usr/local/bin/build-dependencies.sh
94+
RUN chmod +x /usr/local/bin/build-dependencies.sh
95+
96+
# Create the entrypoint script
97+
COPY <<EOF /usr/local/bin/entrypoint.sh
98+
#!/bin/bash
99+
set -e
100+
101+
/usr/local/bin/build-dependencies.sh -b "$BUILD_NUMBER" -o "$OUTPUT_DIR" -p "/usr/src" -s -a -r && \\
102+
chmod +x /usr/src/freeswitch/scripts/packaging/build/fsdeb.sh && \
103+
/usr/src/freeswitch/scripts/packaging/build/fsdeb.sh -b "$BUILD_NUMBER" -o "$OUTPUT_DIR" -w "/usr/src/freeswitch"
104+
105+
echo "Build completed successfully."
106+
EOF
107+
RUN chmod +x /usr/local/bin/entrypoint.sh
108+
109+
# Create directories
110+
RUN mkdir -p "${OUTPUT_DIR}" /usr/src/freeswitch
111+
112+
# Copy FreeSWITCH source tree
113+
COPY . /usr/src/freeswitch
114+
115+
# Set working directory
116+
WORKDIR /usr/src
117+
118+
# Set entrypoint
119+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

scripts/packaging/build/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Configuring the repo is enough. Dependencies will be installed during the FreeSW
2121
Just follow this [Dependency Building Guide](dependencies/README.md) without the need to set up the FreeSWITCH Debian repo.</br>
2222
Although we recommend using the FreeSWITCH Debian repo as all the dependencies are already prebuilt for you.
2323

24+
> Note: There is a possibility to use pre-created [Dockerfile(s)](/docker/build) for building images, see comments inside each Dockerfile.
25+
2426
---
2527
## Prerequisites
2628
FreeSWITCH packages can be built when FreeSWITCH is cloned using `git` only.

scripts/packaging/build/dependencies/build-dependencies.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ function build_all_libraries()
416416
esac
417417
done
418418

419-
if [ "$SETUP_LOCAL_REPO" == "true" ] && [ "$NEEDS_LOCAL_REPO" == "false" ]; then
419+
if [ "$SETUP_LOCAL_REPO" == "true" ] || [ "$NEEDS_LOCAL_REPO" == "false" ]; then
420420
setup_local_repository
421421
echo "Local Debian repository has been set up at $OUTPUT_DIR."
422422
fi

0 commit comments

Comments
 (0)