Skip to content

Commit 40b4dfa

Browse files
authored
[build] add docker and devcontainer consistent build environment. (#3277)
Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
1 parent 5be7315 commit 40b4dfa

5 files changed

Lines changed: 175 additions & 2 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "SRT Development",
3+
"dockerFile": "../docker/Dockerfile",
4+
"workspaceFolder": "/srt_build_env",
5+
"workspaceMount": "source=${localWorkspaceFolder},target=/srt_build_env,type=bind",
6+
"customizations": {
7+
"vscode": {
8+
"settings": {
9+
"terminal.integrated.defaultProfile.linux": "bash"
10+
},
11+
"extensions": [
12+
"ms-vscode.cpptools",
13+
"ms-vscode.cmake-tools",
14+
"twxs.cmake"
15+
]
16+
}
17+
},
18+
"remoteUser": "srt-dev"
19+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ In live streaming configurations, the SRT protocol maintains a constant end-to-e
163163

164164
## Build Instructions
165165

166-
[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)
166+
[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)
167167

168168
### Requirements
169169

docker/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# SRT Build Environment - Ubuntu 22.04 (Jammy)
2+
# This Dockerfile can be used standalone or as part of a devcontainer setup
3+
4+
FROM ubuntu:22.04
5+
6+
# Set non-interactive mode for apt
7+
ENV DEBIAN_FRONTEND=noninteractive
8+
9+
# Install build dependencies
10+
RUN apt-get update && apt-get install -y \
11+
# Build essentials
12+
build-essential \
13+
cmake \
14+
gcc \
15+
g++ \
16+
make \
17+
pkg-config \
18+
# SRT dependencies
19+
tclsh \
20+
libssl-dev \
21+
# Testing and code coverage
22+
gcovr \
23+
lcov \
24+
# Spell checking
25+
python3 \
26+
python3-pip \
27+
# Git for source control
28+
git \
29+
&& rm -rf /var/lib/apt/lists/*
30+
31+
# Install codespell using pip
32+
RUN pip3 install --no-cache-dir codespell
33+
34+
# Create a non-root user for development
35+
ARG USERNAME=srt-dev
36+
ARG USER_UID=1000
37+
ARG USER_GID=$USER_UID
38+
39+
RUN groupadd --gid $USER_GID $USERNAME \
40+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
41+
&& apt-get update \
42+
&& apt-get install -y sudo \
43+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
44+
&& chmod 0440 /etc/sudoers.d/$USERNAME \
45+
&& rm -rf /var/lib/apt/lists/*
46+
47+
# Set the default user
48+
USER $USERNAME
49+
50+
# Set working directory
51+
WORKDIR /srt_build_env
52+
53+
# Default command
54+
CMD ["/bin/bash"]

docs/build/build-container.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Building SRT Using Devcontainer or Docker
2+
3+
This guide describes how to use the provided Devcontainer or Dockerfile to set up a consistent build environment for SRT.
4+
5+
## VS Code Devcontainer (Recommended)
6+
7+
The devcontainer provides the easiest and most integrated development experience with VS Code.
8+
9+
### Prerequisites
10+
11+
- [Visual Studio Code](https://code.visualstudio.com/)
12+
- [Docker Desktop](https://www.docker.com/products/docker-desktop) or Docker Engine
13+
- [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for VS Code
14+
15+
### Steps
16+
17+
1. Open the SRT repository in VS Code
18+
19+
```console
20+
$ code </path/to/srt>
21+
```
22+
23+
2. Open in Container
24+
25+
- VS Code should prompt you to "Reopen in Container"
26+
- Alternatively, press `F1` and select `Dev Containers: Reopen in Container`
27+
28+
3. Run Spell Check
29+
30+
```console
31+
$ cd </path/to/srt>
32+
$ codespell --config scripts/codespell/codespell.cfg
33+
```
34+
35+
4. Build SRT Inside the Container
36+
37+
```console
38+
$ mkdir _build && cd _build
39+
$ 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
40+
$ cmake --build . --parallel
41+
```
42+
43+
5. Run Tests
44+
45+
```console
46+
$ cd _build
47+
$ ctest --extra-verbose
48+
```
49+
50+
## Dockerfile
51+
52+
If you prefer not to use VS Code or want to use the Dockerfile independently, you can build and run the container manually.
53+
54+
### Prerequisites
55+
56+
- [Docker Desktop](https://www.docker.com/products/docker-desktop) or Docker Engine
57+
58+
### Steps
59+
60+
1. Build the Docker Image
61+
62+
```console
63+
$ cd </path/to/srt>
64+
$ docker build -t srt-build-env -f docker/Dockerfile .
65+
```
66+
67+
2. Run the Container
68+
69+
Mount the SRT source directory into the container:
70+
```console
71+
$ docker run -it --rm -v "$(pwd)":/srt_build_env -w /srt_build_env srt-build-env
72+
```
73+
74+
3. Run Spell Check
75+
76+
```console
77+
$ cd </path/to/srt>
78+
$ codespell --config scripts/codespell/codespell.cfg
79+
```
80+
81+
4. Build SRT Inside the Container
82+
83+
```console
84+
$ mkdir _build && cd _build
85+
$ 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
86+
$ cmake --build . --parallel
87+
```
88+
89+
5. Run Tests
90+
91+
```console
92+
$ cd _build
93+
$ ctest --extra-verbose
94+
```
95+
96+
6. Exit the Container
97+
98+
```console
99+
$ exit
100+
```

scripts/codespell/codespell.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ ignore-words = ./scripts/codespell/codespell_whitelist.txt
1111
dictionary = ./scripts/codespell/codespell_dictionary.txt,-
1212

1313
# Skip checking files or directories.
14-
skip = ./build/*,./.git/*
14+
skip = ./build/*,./_build/*,./.git/*

0 commit comments

Comments
 (0)