Skip to content

Commit d4a6e52

Browse files
authored
RSDK-9077: Docker containers for module development (#310)
1 parent 38feae2 commit d4a6e52

File tree

9 files changed

+60
-63
lines changed

9 files changed

+60
-63
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,15 @@ jobs:
2222
###########################################
2323
- name: build-docker-test
2424
run: |
25-
docker build -t cpp . -f etc/docker/tests/Dockerfile.debian.bullseye
26-
docker run -e BUILD_SHARED=${{ matrix.BUILD_SHARED }} --rm -i -w /tmp cpp /bin/bash
25+
docker build -t cpp . -f etc/docker/base-images/Dockerfile.debian.bullseye
26+
docker build -t cpp-test . -f etc/docker/Dockerfile.sdk-build \
27+
--build-arg BASE_TAG=cpp \
28+
--build-arg REPO_SETUP=copy \
29+
--build-arg BUILD_SHARED=${{ matrix.BUILD_SHARED }} \
30+
--build-arg BUILD_TESTS=ON \
31+
--build-arg BUILD_EXAMPLES=ON \
32+
--build-arg "EXTRA_CMAKE_ARGS=\
33+
-DVIAMCPPSDK_CLANG_TIDY=ON \
34+
-DVIAMCPPSDK_SANITIZED_BUILD=${{ matrix.BUILD_SHARED }}"
35+
36+
docker run -w /viam-cpp-sdk/build -t --entrypoint /viam-cpp-sdk/etc/docker/tests/run_test.sh cpp-test /bin/bash

etc/docker/Dockerfile.sdk-build

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This Dockerfile is meant to be built on top of an existing image from the base-images directory.
2+
# Suggested usage, from the SDK root:
3+
# docker build -t base/bullseye -f etc/docker/base-images/Dockerfile.debian.bullseye .
4+
# docker build --build-arg BASE_TAG=base/bullseye --build-arg GIT_TAG=[...] etc/docker/Dockerfile.sdk-build .
5+
# You can substitute the bullseye image for whichever you want to use as a base.
6+
# Note that it is necessary to tag the base image with `-t` and then refer to it using the `BASE_TAG` arg.
7+
8+
ARG REPO_SETUP=git
9+
10+
ARG BASE_TAG
11+
12+
# See https://stackoverflow.com/a/54245466 for the trick used below
13+
# The two possible branches are repo_setup_git and repo_setup_copy, which are conditionally executed
14+
# using ARG REPO_SETUP
15+
16+
FROM ${BASE_TAG} AS repo_setup_git
17+
ARG GIT_TAG
18+
ONBUILD RUN echo "Checking if GIT_TAG is set" && test -n "${GIT_TAG}"
19+
ONBUILD RUN git clone https://github.com/viamrobotics/viam-cpp-sdk/ -b ${GIT_TAG}
20+
21+
FROM ${BASE_TAG} AS repo_setup_copy
22+
ONBUILD COPY . /viam-cpp-sdk/
23+
24+
FROM repo_setup_${REPO_SETUP}
25+
ENV DEBIAN_FRONTEND=noninteractive
26+
27+
ARG BUILD_TYPE=RelWithDebInfo
28+
ARG BUILD_SHARED=ON
29+
ARG BUILD_TESTS=OFF
30+
ARG BUILD_EXAMPLES=OFF
31+
ARG EXTRA_CMAKE_ARGS
32+
33+
WORKDIR /viam-cpp-sdk
34+
35+
RUN mkdir build && \
36+
cd build && \
37+
cmake .. -G Ninja \
38+
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
39+
-DBUILD_SHARED_LIBS=${BUILD_SHARED} \
40+
-DVIAMCPPSDK_OFFLINE_PROTO_GENERATION=ON \
41+
-DVIAMCPPSDK_BUILD_TESTS=${BUILD_TESTS} \
42+
-DVIAMCPPSDK_BUILD_EXAMPLES=${BUILD_EXAMPLES} \
43+
${EXTRA_CMAKE_ARGS}
44+
45+
RUN cmake --build build --target install && \
46+
cmake --install build
47+
File renamed without changes.

etc/docker/tests/Dockerfile.debian.bullseye

Lines changed: 0 additions & 51 deletions
This file was deleted.

etc/docker/tests/run_test.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
#!/bin/bash
22
set -e
33

4-
mkdir build
5-
cd build
6-
cmake .. -G Ninja -DVIAMCPPSDK_USE_DYNAMIC_PROTOS=ON \
7-
-DVIAMCPPSDK_OFFLINE_PROTO_GENERATION=ON \
8-
-DVIAMCPPSDK_SANITIZED_BUILD=$BUILD_SHARED \
9-
-DVIAMCPPSDK_CLANG_TIDY=ON \
10-
-DBUILD_SHARED_LIBS=$BUILD_SHARED
11-
12-
ninja all
13-
ninja install
144
INSTALL_DIR="$(pwd)/install"
5+
BUILD_SHARED=$(grep 'BUILD_SHARED_LIBS' CMakeCache.txt | cut -d '=' -f 2)
156

167
pushd src/viam/sdk/tests
178
UBSAN_OPTIONS="print_stacktrace=1" ctest --output-on-failure

0 commit comments

Comments
 (0)