Merge pull request #2790 from signalwire/dockerfile

[BUILD] Add Dockerfiles and related small fixes.
This commit is contained in:
Andrey Volk 2025-03-31 21:26:18 +03:00 committed by GitHub
commit 1d29b134be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 369 additions and 8 deletions

View File

@ -0,0 +1,67 @@
# Dockerfile for building Debian base-image with FreeSWITCH dependencies (repo)
# Build the image:
# docker build -t fs-base-image --build-arg FS_TOKEN=your_token_here -f docker/build/base-image-from-repo.Dockerfile .
#
# Or build using secrets (recommended for tokens):
# docker build -t fs-base-image --secret id=fs_token,env=FS_TOKEN -f docker/build/base-image-from-repo.Dockerfile .
# Stage 1: Install FreeSWITCH using fsget.sh
FROM debian:bookworm AS installer
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
# Define build arguments
ARG FS_TOKEN
ARG FS_RELEASE=release
ARG FS_INSTALL=install
# Set working directory
WORKDIR /tmp
# Copy fsget.sh script
COPY scripts/packaging/fsget.sh /usr/local/bin/fsget.sh
RUN chmod +x /usr/local/bin/fsget.sh
# Install required tools
RUN apt-get update && \
apt-get install -y --no-install-recommends \
procps \
locales
# Install FreeSWITCH using fsget.sh with token from secret or build arg
RUN --mount=type=secret,id=fs_token,target=/run/secrets/fs_token \
TOKEN=${FS_TOKEN:-$(cat /run/secrets/fs_token 2>/dev/null || echo "")} && \
if [ -z "$TOKEN" ]; then \
echo "Error: No token provided. Use --build-arg FS_TOKEN=your_token or --secret id=fs_token,env=FS_TOKEN" && \
exit 1; \
fi && \
/usr/local/bin/fsget.sh "$TOKEN" "$FS_RELEASE" "$FS_INSTALL"
# Set locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# Clean up
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
rm -f /etc/apt/sources.list.d/freeswitch.list && \
rm -f /etc/apt/auth.conf && \
rm -f /usr/local/bin/fsget.sh
# Stage 2: Final image with minimal layers
FROM debian:bookworm
# Copy everything from the installer stage
COPY --from=installer / /
# Set working directory
WORKDIR /usr/local/src/freeswitch
# Set command to bash directly
SHELL ["/bin/bash", "-c"]

View File

@ -0,0 +1,167 @@
# Dockerfile for building Debian base-image with FreeSWITCH dependencies (sources)
# Available build arguments:
# BUILD_NUMBER - Package build number (default: 42)
# LIBBROADVOICE_REF - Git ref for libbroadvoice (default: HEAD)
# LIBILBC_REF - Git ref for libilbc (default: HEAD)
# LIBSILK_REF - Git ref for libsilk (default: HEAD)
# SPANDSP_REF - Git ref for spandsp (default: HEAD)
# SOFIASIP_REF - Git ref for sofia-sip (default: HEAD)
# LIBKS_REF - Git ref for libks (default: HEAD)
# SIGNALWIRE_C_REF - Git ref for signalwire-c (default: HEAD)
# LIBV8_PACKAGING_REF - Git ref for libv8-packaging (default: HEAD)
#
# Build the image:
# docker build -t fs-base-image -f docker/build/base-image-from-source.Dockerfile .
#
# Build with specific tags:
# docker build -t fs-base-image \
# --build-arg LIBKS_REF=v1.0.0 \
# --build-arg BUILD_NUMBER=123 \
# -f docker/build/base-image-from-source.Dockerfile .
#
# Run the container with output directory mounted to host:
# mkdir -p "$HOME/DEBs"
# 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
# Stage 1: Build dependencies layer
FROM debian:bookworm AS builder
# Set bash as the default shell
SHELL ["/bin/bash", "-c"]
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV OUTPUT_DIR="/var/local/deb"
# Define build arguments with default
ARG BUILD_NUMBER=42
# Define tag arguments with defaults to HEAD
ARG LIBBROADVOICE_REF=HEAD
ARG LIBILBC_REF=HEAD
ARG LIBSILK_REF=HEAD
ARG SPANDSP_REF=HEAD
ARG SOFIASIP_REF=HEAD
ARG LIBKS_REF=HEAD
ARG SIGNALWIRE_C_REF=HEAD
ARG LIBV8_PACKAGING_REF=HEAD
# Install minimal requirements
RUN apt-get update && apt-get install -y \
git \
lsb-release
# Configure git to trust all directories
RUN git config --global --add safe.directory '*'
# Set base dir for cloned repositories
WORKDIR /usr/src
# Clone libbroadvoice
RUN [ -d "libbroadvoice" ] || (git clone https://github.com/freeswitch/libbroadvoice.git && \
cd libbroadvoice && git checkout $LIBBROADVOICE_REF)
# Clone libilbc
RUN [ -d "libilbc" ] || (git clone https://github.com/freeswitch/libilbc.git && \
cd libilbc && git checkout $LIBILBC_REF)
# Clone libsilk
RUN [ -d "libsilk" ] || (git clone https://github.com/freeswitch/libsilk.git && \
cd libsilk && git checkout $LIBSILK_REF)
# Clone spandsp (packages branch)
RUN [ -d "spandsp" ] || (git clone --branch packages https://github.com/freeswitch/spandsp.git && \
cd spandsp && git checkout $SPANDSP_REF)
# Clone sofia-sip
RUN [ -d "sofia-sip" ] || (git clone https://github.com/freeswitch/sofia-sip.git && \
cd sofia-sip && git checkout $SOFIASIP_REF)
# Clone libks
RUN [ -d "libks" ] || (git clone https://github.com/signalwire/libks.git && \
cd libks && git checkout $LIBKS_REF)
# Clone signalwire-c
RUN [ -d "signalwire-c" ] || (git clone https://github.com/signalwire/signalwire-c.git && \
cd signalwire-c && git checkout $SIGNALWIRE_C_REF)
# Clone libv8-packaging
RUN [ -d "libv8-packaging" ] || (git clone https://github.com/freeswitch/libv8-packaging.git && \
cd libv8-packaging && git checkout $LIBV8_PACKAGING_REF)
# Copy the build dependencies script
COPY scripts/packaging/build/dependencies/build-dependencies.sh /usr/local/bin/build-dependencies.sh
RUN chmod +x /usr/local/bin/build-dependencies.sh
# Create directories
RUN mkdir -p "${OUTPUT_DIR}" /usr/src/freeswitch
# Copy FreeSWITCH source tree
COPY . /usr/src/freeswitch
# Build the dependency packages
RUN /usr/local/bin/build-dependencies.sh -b "$BUILD_NUMBER" -o "$OUTPUT_DIR" -p "/usr/src" -s -a -r
# Stage 2: Install packages layer
FROM debian:bookworm AS installer
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /root
# Copy only the DEB files from builder stage
COPY --from=builder /var/local/deb/*.deb /tmp/debs/
# Install required tools for setting up local repo
RUN apt-get update && \
apt-get install -y --no-install-recommends \
apt-utils \
dpkg-dev \
gnupg \
ca-certificates \
lsb-release \
procps \
locales
# Create local repository directory
RUN mkdir -p /var/local/repo && \
cp /tmp/debs/*.deb /var/local/repo/
# Generate package index
RUN cd /var/local/repo && \
dpkg-scanpackages . > Packages && \
gzip -9c Packages > Packages.gz
# Configure local repository
RUN echo "deb [trusted=yes] file:/var/local/repo ./" > /etc/apt/sources.list.d/local.list && \
apt-get update
# Install all available packages from local repo
RUN ls -1 /var/local/repo/*.deb | sed -e 's|.*/||' -e 's|_.*||' | grep -Pv "\-dbgsym$" | xargs apt-get install -y --allow-downgrades -f
# Clean up
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/debs && \
rm -rf /var/local/repo && \
rm -f /etc/apt/sources.list.d/local.list
# Set locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# Stage 3: Final image
FROM debian:bookworm
# Copy everything from the installer stage
COPY --from=installer / /
# Set working directory
WORKDIR /usr/local/src/freeswitch
# Set command to bash directly
SHELL ["/bin/bash", "-c"]

View File

@ -0,0 +1,119 @@
# Dockerfile for building Debian packages of FreeSWITCH dependencies
#
# Available build arguments:
# BUILD_NUMBER - Package build number (default: 42)
# LIBBROADVOICE_REF - Git ref for libbroadvoice (default: HEAD)
# LIBILBC_REF - Git ref for libilbc (default: HEAD)
# LIBSILK_REF - Git ref for libsilk (default: HEAD)
# SPANDSP_REF - Git ref for spandsp (default: HEAD)
# SOFIASIP_REF - Git ref for sofia-sip (default: HEAD)
# LIBKS_REF - Git ref for libks (default: HEAD)
# SIGNALWIRE_C_REF - Git ref for signalwire-c (default: HEAD)
# LIBV8_PACKAGING_REF - Git ref for libv8-packaging (default: HEAD)
#
# Build the image:
# docker build -t fs-debian-package-builder -f docker/build/debs-from-source.Dockerfile .
#
# Build with specific tags:
# docker build -t fs-debian-package-builder \
# --build-arg LIBKS_REF=v1.0.0 \
# --build-arg BUILD_NUMBER=123 \
# -f docker/build/debs-from-source.Dockerfile .
#
# Run the container with output directory mounted to host:
# mkdir -p "$HOME/DEBs"
# docker run -v "$HOME/DEBs:/var/local/deb" fs-debian-package-builder
FROM debian:bookworm
# Set bash as the default shell
SHELL ["/bin/bash", "-c"]
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV OUTPUT_DIR="/var/local/deb"
# Define build arguments with default
ARG BUILD_NUMBER=42
# Define tag arguments with defaults to HEAD
ARG LIBBROADVOICE_REF=HEAD
ARG LIBILBC_REF=HEAD
ARG LIBSILK_REF=HEAD
ARG SPANDSP_REF=HEAD
ARG SOFIASIP_REF=HEAD
ARG LIBKS_REF=HEAD
ARG SIGNALWIRE_C_REF=HEAD
ARG LIBV8_PACKAGING_REF=HEAD
# Install minimal requirements
RUN apt-get update && apt-get install -y \
git \
lsb-release
# Configure git to trust all directories
RUN git config --global --add safe.directory '*'
# Set base dir for cloned repositories
WORKDIR /usr/src
# Clone libbroadvoice
RUN [ -d "libbroadvoice" ] || (git clone https://github.com/freeswitch/libbroadvoice.git && \
cd libbroadvoice && git checkout $LIBBROADVOICE_REF)
# Clone libilbc
RUN [ -d "libilbc" ] || (git clone https://github.com/freeswitch/libilbc.git && \
cd libilbc && git checkout $LIBILBC_REF)
# Clone libsilk
RUN [ -d "libsilk" ] || (git clone https://github.com/freeswitch/libsilk.git && \
cd libsilk && git checkout $LIBSILK_REF)
# Clone spandsp (packages branch)
RUN [ -d "spandsp" ] || (git clone --branch packages https://github.com/freeswitch/spandsp.git && \
cd spandsp && git checkout $SPANDSP_REF)
# Clone sofia-sip
RUN [ -d "sofia-sip" ] || (git clone https://github.com/freeswitch/sofia-sip.git && \
cd sofia-sip && git checkout $SOFIASIP_REF)
# Clone libks
RUN [ -d "libks" ] || (git clone https://github.com/signalwire/libks.git && \
cd libks && git checkout $LIBKS_REF)
# Clone signalwire-c
RUN [ -d "signalwire-c" ] || (git clone https://github.com/signalwire/signalwire-c.git && \
cd signalwire-c && git checkout $SIGNALWIRE_C_REF)
# Clone libv8-packaging
RUN [ -d "libv8-packaging" ] || (git clone https://github.com/freeswitch/libv8-packaging.git && \
cd libv8-packaging && git checkout $LIBV8_PACKAGING_REF)
# Copy the build dependencies script
COPY scripts/packaging/build/dependencies/build-dependencies.sh /usr/local/bin/build-dependencies.sh
RUN chmod +x /usr/local/bin/build-dependencies.sh
# Create the entrypoint script
COPY <<EOF /usr/local/bin/entrypoint.sh
#!/bin/bash
set -e
/usr/local/bin/build-dependencies.sh -b "$BUILD_NUMBER" -o "$OUTPUT_DIR" -p "/usr/src" -s -a -r && \\
chmod +x /usr/src/freeswitch/scripts/packaging/build/fsdeb.sh && \
/usr/src/freeswitch/scripts/packaging/build/fsdeb.sh -b "$BUILD_NUMBER" -o "$OUTPUT_DIR" -w "/usr/src/freeswitch"
echo "Build completed successfully."
EOF
RUN chmod +x /usr/local/bin/entrypoint.sh
# Create directories
RUN mkdir -p "${OUTPUT_DIR}" /usr/src/freeswitch
# Copy FreeSWITCH source tree
COPY . /usr/src/freeswitch
# Set working directory
WORKDIR /usr/src
# Set entrypoint
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

View File

@ -21,6 +21,8 @@ Configuring the repo is enough. Dependencies will be installed during the FreeSW
Just follow this [Dependency Building Guide](dependencies/README.md) without the need to set up the FreeSWITCH Debian repo.</br>
Although we recommend using the FreeSWITCH Debian repo as all the dependencies are already prebuilt for you.
> Note: There is a possibility to use pre-created [Dockerfile(s)](/docker/build) for building images, see comments inside each Dockerfile.
---
## Prerequisites
FreeSWITCH packages can be built when FreeSWITCH is cloned using `git` only.

View File

@ -416,7 +416,7 @@ function build_all_libraries()
esac
done
if [ "$SETUP_LOCAL_REPO" == "true" ] && [ "$NEEDS_LOCAL_REPO" == "false" ]; then
if [ "$SETUP_LOCAL_REPO" == "true" ] || [ "$NEEDS_LOCAL_REPO" == "false" ]; then
setup_local_repository
echo "Local Debian repository has been set up at $OUTPUT_DIR."
fi

View File

@ -1,6 +1,6 @@
#!/bin/bash
# lint: shfmt -w -s -bn -ci -sr -fn scripts/packaging/build/build-debs-native.sh
# lint: shfmt -w -s -bn -ci -sr -fn scripts/packaging/build/fsdeb.sh
set -e # Exit immediately if a command exits with a non-zero status
set -u # Treat unset variables as an error
@ -12,7 +12,9 @@ print_usage()
exit 1
}
WORKING_DIR=$(git rev-parse --show-toplevel 2> /dev/null || pwd -P)
BUILD_NUMBER=""
OUTPUT_DIR=""
WORKING_DIR=""
while getopts ":b:o:w:" opt; do
case ${opt} in
@ -27,12 +29,14 @@ if [ -z "${BUILD_NUMBER:-}" ] || [ -z "${OUTPUT_DIR:-}" ]; then
print_usage
fi
if [ -z "${WORKING_DIR}" ]; then
WORKING_DIR=$(git rev-parse --show-toplevel 2> /dev/null || pwd -P)
fi
if [ "$(id -u)" != "0" ]; then
echo "Non-root user detected. Execution may fail."
fi
cd "${WORKING_DIR}" || exit 1
install_deps()
{
apt-get update || echo "WARNING: apt-get update failed"
@ -64,13 +68,13 @@ export_vars()
setup_git_local()
{
git config --global --add safe.directory "${WORKING_DIR}"
if [ -z "$(git config user.email)" ]; then
git config user.email "$(id -un)@localhost"
fi
if [ -z "$(git config user.name)" ]; then
git config user.name "$(id -un)"
fi
git config --add safe.directory '*'
}
bootstrap_freeswitch()
@ -83,7 +87,7 @@ install_freeswitch_deps()
{
apt-get update || echo "WARNING: apt-get update failed"
mk-build-deps --install --remove debian/control \
--tool "apt-get --yes --no-install-recommends" || echo "WARNING: mk-build-deps failed"
--tool "apt-get -o Debug::pkgProblemResolver=yes --yes --no-install-recommends" || echo "WARNING: mk-build-deps failed"
apt-get --yes --fix-broken install || echo "WARNING: apt-get fix-broken failed"
}
@ -105,9 +109,11 @@ build_and_move()
main()
{
cd "${WORKING_DIR}" || exit 1
install_deps
export_vars
setup_git_local
export_vars
bootstrap_freeswitch
install_freeswitch_deps
build_source_package