Skip to content

Commit c2cdb98

Browse files
authored
Merge pull request #54 from microsoft/dockerbuildgithub
Add GitHub workflow to build repository using Docker image
2 parents f906b22 + 596fcd7 commit c2cdb98

File tree

8 files changed

+243
-49
lines changed

8 files changed

+243
-49
lines changed

.docker/netremote-dev/Dockerfile

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
FROM ubuntu:mantic as netremote
2+
FROM ubuntu:mantic as netremote-build
33

44
# Set arguments used only in this Dockerfile.
55
ARG build_date="2023-11-09T19:51:18Z"
@@ -21,8 +21,8 @@ LABEL org.label-schema.schema-version = "1.0"
2121
# 1. Update package cache.
2222
# sudo apt-get update
2323
#
24-
# 2. Install core build tools:
25-
# sudo apt-get install -y --no-install-recommends build-essential ca-certificates cmake curl dotnet7 git gnupg linux-libc-dev ninja-build pkg-config tar unzip zip
24+
# 2. Install core build tools and dependencies:
25+
# sudo apt-get install -y --no-install-recommends build-essential ca-certificates cmake curl dotnet7 git gnupg linux-libc-dev ninja-build pkg-config tar unzip zip libnl-3-dev libssl-dev libnl-genl-3-dev libdbus-c++-dev libnl-route-3-dev
2626
#
2727
# 3. Remove llvm 16 toolchain packages to avoid conflicts with llvm 17 toolchain.
2828
# sudo apt-get remove -y --purge clang-16* lldb-16* llvm-16*
@@ -35,13 +35,13 @@ LABEL org.label-schema.schema-version = "1.0"
3535
# rm llvm.sh
3636
#
3737
# 5. Install development dependency packages:
38-
# sudo apt-get install -y --no-install-recommends libnl-3-dev libnl-genl-3-dev libssl-dev libdbus-c++-dev libnl-route-3-dev bc bison dwarves flex libelf-dev dos2unix file gnupg2 iproute2 mtools neofetch rsync ssh sudo emacs gdb kmod nano policycoreutils-python-utils python-is-python3 vim
38+
# sudo apt-get install -y --no-install-recommends bc bison dwarves flex libelf-dev dos2unix file gnupg2 iproute2 mtools neofetch rsync ssh sudo emacs gdb kmod nano policycoreutils-python-utils python-is-python3 vim
3939
#
4040

4141
# Install packages.
4242
RUN apt-get update && \
4343
apt-get install -qq -y --no-install-recommends \
44-
# Project build dependencies.
44+
# Core project build dependencies.
4545
# build-essential ca-certificates cmake curl dotnet7 git gnupg linux-libc-dev ninja-build pkg-config tar unzip zip
4646
build-essential \
4747
ca-certificates \
@@ -55,7 +55,16 @@ RUN apt-get update && \
5555
pkg-config \
5656
tar \
5757
unzip \
58-
zip
58+
zip \
59+
# hostapd build dependencies.
60+
# libnl-3-dev libssl-dev libnl-genl-3-dev
61+
libnl-3-dev \
62+
libnl-genl-3-dev \
63+
libssl-dev \
64+
# wpa_supplicant build dependencies.
65+
# libnl-3-dev libssl-dev libnl-genl-3-dev libdbus-c++-dev libnl-route-3-dev
66+
libdbus-c++-dev \
67+
libnl-route-3-dev
5968

6069
# Install complete llvm toolchain using automatic installation script.
6170
# lsb-release, software-properties-common, and wget are required by the script.
@@ -76,20 +85,34 @@ RUN apt-get install -qq -y --no-install-recommends \
7685
RUN apt-get clean && \
7786
rm -rf /var/lib/apt/lists/*
7887

79-
FROM netremote as netremote-dev
88+
# Set environment variables for external vcpkg to support binary caching
89+
ENV VCPKG_ROOT_BASE=/vcpkg
90+
ENV VCPKG_BINARY_CACHE=${VCPKG_ROOT_BASE}/cache
91+
ENV VCPKG_ROOT=${VCPKG_ROOT_BASE}/vcpkg
92+
ENV VCPKG_DEFAULT_BINARY_CACHE=${VCPKG_BINARY_CACHE}
93+
94+
WORKDIR ${VCPKG_ROOT_BASE}
95+
96+
RUN mkdir -p ${VCPKG_BINARY_CACHE}
97+
98+
# Obtain vcpkg, bootstrap it, and install dependencies.
99+
COPY vcpkg.json .
100+
101+
RUN git clone https://github.com/microsoft/vcpkg.git --depth 1 && \
102+
./vcpkg/bootstrap-vcpkg.sh && \
103+
./vcpkg/vcpkg install --clean-buildtrees-after-build --clean-downloads-after-build
104+
105+
# Copy build entrypoint script.
106+
COPY --chmod=0755 entrypoint-build.sh /bin/entrypoint-build.sh
107+
108+
# Build the repository.
109+
ENTRYPOINT [ "/bin/entrypoint-build.sh" ]
110+
111+
FROM netremote-build as netremote-dev
80112

81113
# Install packages.
82114
RUN apt-get update && \
83115
apt-get install -y --no-install-recommends \
84-
# hostapd build dependencies.
85-
# libnl-3-dev libssl-dev libnl-genl-3-dev
86-
libnl-3-dev \
87-
libnl-genl-3-dev \
88-
libssl-dev \
89-
# wpa_supplicant build dependencies.
90-
# libnl-3-dev libssl-dev libnl-genl-3-dev libdbus-c++-dev libnl-route-3-dev
91-
libdbus-c++-dev \
92-
libnl-route-3-dev \
93116
# WSL2 kernel development dependencies.
94117
# build-essential flex bison dwarves libssl-dev libelf-dev bc
95118
bc \
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
set -euf -o pipefail
4+
5+
REPOSITORY_ROOT=${1:-${PWD}}
6+
7+
# Verify the repository root is a git repository.
8+
if [[ ! -d ${REPOSITORY_ROOT}/.git ]]; then
9+
echo "Repository root is not a git repository: ${REPOSITORY_ROOT}"
10+
exit 1
11+
fi
12+
13+
# Verify the vcpkg toolchain file is present.
14+
if [[ ! -f ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake ]]; then
15+
echo "vcpkg cmake toolchain file not found: ${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
16+
exit 1
17+
fi
18+
19+
# Assign cmake presets.
20+
# TODO: these should be passed in as arguments instead.
21+
PRESET_CONFIGURE=release-linux
22+
PRESET_BUILD=release-linux-debug
23+
BUILD_CONFIG=Debug
24+
25+
# Add the workspace directory to the safe directory list.
26+
git config --global --add safe.directory ${REPOSITORY_ROOT}
27+
28+
# Change to the root of the repo.
29+
cd ${REPOSITORY_ROOT}
30+
cmake --preset ${PRESET_CONFIGURE}
31+
cmake --build --preset ${PRESET_BUILD}
32+
cmake --install out/build/${PRESET_CONFIGURE} --config ${BUILD_CONFIG}

.docker/netremote-dev/vcpkg.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "netremote",
3+
"version-string": "1",
4+
"dependencies": [
5+
{
6+
"name": "grpc",
7+
"host": true
8+
},
9+
"cli11",
10+
"protobuf",
11+
"catch2",
12+
"plog",
13+
"magic-enum",
14+
{
15+
"name": "wil",
16+
"platform": "windows"
17+
}
18+
]
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
name: 'Build'
3+
description: 'Build the repository in a Docker container'
4+
runs:
5+
using: 'docker'
6+
image: 'docker://abeltrano/netremote-build:latest'
7+
args:
8+
- '/github/workspace'

.github/workflows/build.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
on:
3+
pull_request:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
- name: Build in container
13+
uses: ./.github/actions/build-with-docker
14+

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
66
include(vcpkg)
77

88
# Tell vcpkg to use the submodule root directory as the vcpkg root, and then configure it.
9-
set(VCPKG_SUBMODULE_ROOT ${CMAKE_CURRENT_LIST_DIR}/vcpkg)
9+
set(VCPKG_SUBMODULE_ROOT ${CMAKE_CURRENT_LIST_DIR}/vcpkg CACHE PATH "Location of vcpkg submodule root")
1010
vcpkg_configure(SUBMODULE_ROOT ${VCPKG_SUBMODULE_ROOT})
1111

1212
project(netremote

CMakePresets.json

Lines changed: 107 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@
3939
"binaryDir": "${sourceDir}/out/build/${presetName}",
4040
"installDir": "${sourceDir}/out/install/${presetName}"
4141
},
42+
{
43+
"name": "linux-base",
44+
"hidden": true,
45+
"cacheVariables": {
46+
"CMAKE_CXX_COMPILER": "/usr/bin/clang++-17",
47+
"CMAKE_C_COMPILER": "/usr/bin/clang-17",
48+
"CMAKE_GENERATOR": "Ninja"
49+
}
50+
},
51+
{
52+
"name": "windows-base",
53+
"hidden": true,
54+
"cacheVariables": {
55+
"CMAKE_GENERATOR": "Visual Studio 17 2022"
56+
}
57+
},
4258
{
4359
"name": "dev-base",
4460
"hidden": true,
@@ -63,32 +79,113 @@
6379
"description": "Development build for inner-loop on Linux",
6480
"inherits": [
6581
"os-linux",
82+
"linux-base",
6683
"dev"
67-
],
68-
"cacheVariables": {
69-
"CMAKE_CXX_COMPILER": "/usr/bin/clang++-17",
70-
"CMAKE_C_COMPILER": "/usr/bin/clang-17",
71-
"CMAKE_GENERATOR": "Ninja"
72-
}
84+
]
7385
},
7486
{
7587
"name": "dev-windows",
7688
"displayName": "Development",
7789
"description": "Development build for inner-loop on Windows",
7890
"inherits": [
7991
"os-windows",
92+
"windows-base",
8093
"dev"
94+
]
95+
},
96+
{
97+
"name": "release-base",
98+
"hidden": true,
99+
"inherits": [
100+
"in-source-build"
101+
]
102+
},
103+
{
104+
"name": "release-linux",
105+
"inherits":[
106+
"os-linux",
107+
"linux-base",
108+
"release-base"
81109
],
82110
"cacheVariables": {
83-
"CMAKE_GENERATOR": "Visual Studio 17 2022"
111+
"CMAKE_GENERATOR": "Ninja Multi-Config"
84112
}
113+
},
114+
{
115+
"name": "release-windows",
116+
"inherits":[
117+
"os-windows",
118+
"windows-base",
119+
"release-base"
120+
]
85121
}
86122
],
87123
"buildPresets": [
88124
{
89-
"name": "dev",
90-
"configurePreset": "dev",
125+
"name": "dev-linux",
126+
"configurePreset": "dev-linux"
127+
},
128+
{
129+
"name": "dev-windows",
130+
"configurePreset": "dev-windows"
131+
},
132+
{
133+
"name": "cfg-debug",
134+
"hidden": true,
91135
"configuration": "Debug"
136+
},
137+
138+
{
139+
"name": "cfg-release",
140+
"hidden": true,
141+
"configuration": "Release"
142+
},
143+
{
144+
"name": "cfg-release-with-debug",
145+
"hidden": true,
146+
"configuration": "RelWithDebInfo"
147+
},
148+
{
149+
"name": "release-linux-debug",
150+
"configurePreset": "release-linux",
151+
"inherits": [
152+
"cfg-debug"
153+
]
154+
},
155+
{
156+
"name": "release-linux-release",
157+
"configurePreset": "release-linux",
158+
"inherits": [
159+
"cfg-release"
160+
]
161+
},
162+
{
163+
"name": "release-linux-release-with-debug",
164+
"configurePreset": "release-linux",
165+
"inherits": [
166+
"cfg-release-with-debug"
167+
]
168+
},
169+
{
170+
"name": "release-windows-debug",
171+
"configurePreset": "release-windows",
172+
"inherits": [
173+
"cfg-debug"
174+
]
175+
},
176+
{
177+
"name": "release-windows-release",
178+
"configurePreset": "release-windows",
179+
"inherits": [
180+
"cfg-release"
181+
]
182+
},
183+
{
184+
"name": "release-windows-release-with-debug",
185+
"configurePreset": "release-windows",
186+
"inherits": [
187+
"cfg-release-with-debug"
188+
]
92189
}
93190
],
94191
"testPresets": [
@@ -108,6 +205,7 @@
108205
},
109206
{
110207
"name": "local-base",
208+
"hidden": true,
111209
"description": "Run tests that don't require a remote connection",
112210
"inherits": [
113211
"test-common"

cmake/vcpkg.cmake

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,30 @@ function(vcpkg_configure)
1717
${ARGN}
1818
)
1919

20-
# If the vcpkg root has been specified externally, use it.
21-
if (DEFINED ENV{VCPKG_ROOT})
22-
set(VCPKG_ROOT "$ENV{VCPKG_ROOT}")
23-
# Otherwise, use the specified submodule root.
24-
else()
25-
set(VCPKG_ROOT ${VCPKG_SUBMODULE_ROOT})
26-
27-
find_package(Git REQUIRED)
28-
29-
# Initialize vcpkg sub-module if not already done.
30-
if (NOT EXISTS ${VCPKG_SUBMODULE_ROOT}/.git)
31-
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- ${VCPKG_SUBMODULE_ROOT}
32-
WORKING_DIRECTORY ${VCPKG_SUBMODULE_ROOT}/../
33-
COMMAND_ERROR_IS_FATAL ANY)
20+
# If the vcpkg root has been specified externally, use it.
21+
if (DEFINED ENV{VCPKG_ROOT})
22+
set(VCPKG_ROOT "$ENV{VCPKG_ROOT}")
23+
# Otherwise, use the specified submodule root.
24+
else()
25+
set(VCPKG_ROOT ${VCPKG_SUBMODULE_ROOT})
26+
27+
find_package(Git REQUIRED)
28+
29+
# Initialize vcpkg sub-module if not already done.
30+
if (NOT EXISTS ${VCPKG_SUBMODULE_ROOT}/.git)
31+
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive -- ${VCPKG_SUBMODULE_ROOT}
32+
WORKING_DIRECTORY ${VCPKG_SUBMODULE_ROOT}/../
33+
COMMAND_ERROR_IS_FATAL ANY)
34+
endif()
35+
36+
# Ignore all changes to the submodule tree.
37+
get_filename_component(VCPKG_SUBMODULE_NAME ${VCPKG_SUBMODULE_ROOT} NAME)
38+
execute_process(COMMAND ${GIT_EXECUTABLE} "config submodule.${VCPKG_SUBMODULE_NAME}.ignore all"
39+
WORKING_DIRECTORY ${VCPKG_SUBMODULE_ROOT}../
40+
)
3441
endif()
3542

36-
# Ignore all changes to the submodule tree.
37-
get_filename_component(VCPKG_SUBMODULE_NAME ${VCPKG_SUBMODULE_ROOT} NAME)
38-
execute_process(COMMAND ${GIT_EXECUTABLE} "config submodule.${VCPKG_SUBMODULE_NAME}.ignore all"
39-
WORKING_DIRECTORY ${VCPKG_SUBMODULE_ROOT}../
40-
)
41-
endif()
42-
43-
# Set the CMake toolchain file to use vcpkg.
44-
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE FILEPATH "CMake toolchain file")
43+
# Set the CMake toolchain file to use vcpkg.
44+
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE FILEPATH "CMake toolchain file")
4545

4646
endfunction()

0 commit comments

Comments
 (0)