From 3627352fa1645d1af50254bc791c09a6d142b40b Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Mon, 26 Jan 2026 11:25:07 +0900 Subject: [PATCH] [build] add docker and devcontainer consistent build environment. Signed-off-by: Tomoya Fujita --- .devcontainer/devcontainer.json | 19 ++++++ README.md | 2 +- docker/Dockerfile | 54 +++++++++++++++++ docs/build/build-container.md | 100 ++++++++++++++++++++++++++++++++ scripts/codespell/codespell.cfg | 2 +- 5 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 docker/Dockerfile create mode 100644 docs/build/build-container.md diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..9736fe321 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,19 @@ +{ + "name": "SRT Development", + "dockerFile": "../docker/Dockerfile", + "workspaceFolder": "/srt_build_env", + "workspaceMount": "source=${localWorkspaceFolder},target=/srt_build_env,type=bind", + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.defaultProfile.linux": "bash" + }, + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "twxs.cmake" + ] + } + }, + "remoteUser": "srt-dev" +} diff --git a/README.md b/README.md index b0df582af..727e75ed9 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ In live streaming configurations, the SRT protocol maintains a constant end-to-e ## Build Instructions -[Linux (Ubuntu/CentOS)](./docs/build/build-linux.md) | [Windows](./docs/build/build-win.md) | [macOS](./docs/build/build-macOS.md) | [iOS](./docs/build/build-iOS.md) | [Android](./docs/build/build-android.md) | [Package Managers](./docs/build/package-managers.md) +[Linux (Ubuntu/CentOS)](./docs/build/build-linux.md) | [Windows](./docs/build/build-win.md) | [macOS](./docs/build/build-macOS.md) | [iOS](./docs/build/build-iOS.md) | [Android](./docs/build/build-android.md) | [Package Managers](./docs/build/package-managers.md) | [Devcontainer/Docker](./docs/build/build-devcontainer.md) ### Requirements diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..088f3a234 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,54 @@ +# SRT Build Environment - Ubuntu 22.04 (Jammy) +# This Dockerfile can be used standalone or as part of a devcontainer setup + +FROM ubuntu:22.04 + +# Set non-interactive mode for apt +ENV DEBIAN_FRONTEND=noninteractive + +# Install build dependencies +RUN apt-get update && apt-get install -y \ + # Build essentials + build-essential \ + cmake \ + gcc \ + g++ \ + make \ + pkg-config \ + # SRT dependencies + tclsh \ + libssl-dev \ + # Testing and code coverage + gcovr \ + lcov \ + # Spell checking + python3 \ + python3-pip \ + # Git for source control + git \ + && rm -rf /var/lib/apt/lists/* + +# Install codespell using pip +RUN pip3 install --no-cache-dir codespell + +# Create a non-root user for development +ARG USERNAME=srt-dev +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ + && apt-get update \ + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME \ + && rm -rf /var/lib/apt/lists/* + +# Set the default user +USER $USERNAME + +# Set working directory +WORKDIR /srt_build_env + +# Default command +CMD ["/bin/bash"] diff --git a/docs/build/build-container.md b/docs/build/build-container.md new file mode 100644 index 000000000..b8a0d3e1f --- /dev/null +++ b/docs/build/build-container.md @@ -0,0 +1,100 @@ +# Building SRT Using Devcontainer or Docker + +This guide describes how to use the provided Devcontainer or Dockerfile to set up a consistent build environment for SRT. + +## VS Code Devcontainer (Recommended) + +The devcontainer provides the easiest and most integrated development experience with VS Code. + +### Prerequisites + +- [Visual Studio Code](https://code.visualstudio.com/) +- [Docker Desktop](https://www.docker.com/products/docker-desktop) or Docker Engine +- [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for VS Code + +### Steps + +1. Open the SRT repository in VS Code + + ```console + $ code + ``` + +2. Open in Container + + - VS Code should prompt you to "Reopen in Container" + - Alternatively, press `F1` and select `Dev Containers: Reopen in Container` + +3. Run Spell Check + + ```console + $ cd + $ codespell --config scripts/codespell/codespell.cfg + ``` + +4. Build SRT Inside the Container + + ```console + $ mkdir _build && cd _build + $ cmake ../ -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=ON -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON -DENABLE_TESTING=ON -DENABLE_EXAMPLES=ON -DENABLE_CODE_COVERAGE=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + $ cmake --build . --parallel + ``` + +5. Run Tests + + ```console + $ cd _build + $ ctest --extra-verbose + ``` + +## Dockerfile + +If you prefer not to use VS Code or want to use the Dockerfile independently, you can build and run the container manually. + +### Prerequisites + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) or Docker Engine + +### Steps + +1. Build the Docker Image + + ```console + $ cd + $ docker build -t srt-build-env -f docker/Dockerfile . + ``` + +2. Run the Container + + Mount the SRT source directory into the container: + ```console + $ docker run -it --rm -v "$(pwd)":/srt_build_env -w /srt_build_env srt-build-env + ``` + +3. Run Spell Check + + ```console + $ cd + $ codespell --config scripts/codespell/codespell.cfg + ``` + +4. Build SRT Inside the Container + + ```console + $ mkdir _build && cd _build + $ cmake ../ -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DENABLE_STDCXX_SYNC=ON -DENABLE_ENCRYPTION=ON -DENABLE_UNITTESTS=ON -DENABLE_BONDING=ON -DENABLE_TESTING=ON -DENABLE_EXAMPLES=ON -DENABLE_CODE_COVERAGE=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + $ cmake --build . --parallel + ``` + +5. Run Tests + + ```console + $ cd _build + $ ctest --extra-verbose + ``` + +6. Exit the Container + + ```console + $ exit + ``` diff --git a/scripts/codespell/codespell.cfg b/scripts/codespell/codespell.cfg index a33874609..2622a7e45 100644 --- a/scripts/codespell/codespell.cfg +++ b/scripts/codespell/codespell.cfg @@ -11,4 +11,4 @@ ignore-words = ./scripts/codespell/codespell_whitelist.txt dictionary = ./scripts/codespell/codespell_dictionary.txt,- # Skip checking files or directories. -skip = ./build/*,./.git/* +skip = ./build/*,./_build/*,./.git/*