Skip to content

Commit

Permalink
RSDK-9077: Docker containers for module development (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
lia-viam authored Oct 29, 2024
1 parent 38feae2 commit d4a6e52
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 63 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,15 @@ jobs:
###########################################
- name: build-docker-test
run: |
docker build -t cpp . -f etc/docker/tests/Dockerfile.debian.bullseye
docker run -e BUILD_SHARED=${{ matrix.BUILD_SHARED }} --rm -i -w /tmp cpp /bin/bash
docker build -t cpp . -f etc/docker/base-images/Dockerfile.debian.bullseye
docker build -t cpp-test . -f etc/docker/Dockerfile.sdk-build \
--build-arg BASE_TAG=cpp \
--build-arg REPO_SETUP=copy \
--build-arg BUILD_SHARED=${{ matrix.BUILD_SHARED }} \
--build-arg BUILD_TESTS=ON \
--build-arg BUILD_EXAMPLES=ON \
--build-arg "EXTRA_CMAKE_ARGS=\
-DVIAMCPPSDK_CLANG_TIDY=ON \
-DVIAMCPPSDK_SANITIZED_BUILD=${{ matrix.BUILD_SHARED }}"
docker run -w /viam-cpp-sdk/build -t --entrypoint /viam-cpp-sdk/etc/docker/tests/run_test.sh cpp-test /bin/bash
47 changes: 47 additions & 0 deletions etc/docker/Dockerfile.sdk-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This Dockerfile is meant to be built on top of an existing image from the base-images directory.
# Suggested usage, from the SDK root:
# docker build -t base/bullseye -f etc/docker/base-images/Dockerfile.debian.bullseye .
# docker build --build-arg BASE_TAG=base/bullseye --build-arg GIT_TAG=[...] etc/docker/Dockerfile.sdk-build .
# You can substitute the bullseye image for whichever you want to use as a base.
# Note that it is necessary to tag the base image with `-t` and then refer to it using the `BASE_TAG` arg.

ARG REPO_SETUP=git

ARG BASE_TAG

# See https://stackoverflow.com/a/54245466 for the trick used below
# The two possible branches are repo_setup_git and repo_setup_copy, which are conditionally executed
# using ARG REPO_SETUP

FROM ${BASE_TAG} AS repo_setup_git
ARG GIT_TAG
ONBUILD RUN echo "Checking if GIT_TAG is set" && test -n "${GIT_TAG}"
ONBUILD RUN git clone https://github.com/viamrobotics/viam-cpp-sdk/ -b ${GIT_TAG}

FROM ${BASE_TAG} AS repo_setup_copy
ONBUILD COPY . /viam-cpp-sdk/

FROM repo_setup_${REPO_SETUP}
ENV DEBIAN_FRONTEND=noninteractive

ARG BUILD_TYPE=RelWithDebInfo
ARG BUILD_SHARED=ON
ARG BUILD_TESTS=OFF
ARG BUILD_EXAMPLES=OFF
ARG EXTRA_CMAKE_ARGS

WORKDIR /viam-cpp-sdk

RUN mkdir build && \
cd build && \
cmake .. -G Ninja \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DBUILD_SHARED_LIBS=${BUILD_SHARED} \
-DVIAMCPPSDK_OFFLINE_PROTO_GENERATION=ON \
-DVIAMCPPSDK_BUILD_TESTS=${BUILD_TESTS} \
-DVIAMCPPSDK_BUILD_EXAMPLES=${BUILD_EXAMPLES} \
${EXTRA_CMAKE_ARGS}

RUN cmake --build build --target install && \
cmake --install build

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 0 additions & 51 deletions etc/docker/tests/Dockerfile.debian.bullseye

This file was deleted.

11 changes: 1 addition & 10 deletions etc/docker/tests/run_test.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
#!/bin/bash
set -e

mkdir build
cd build
cmake .. -G Ninja -DVIAMCPPSDK_USE_DYNAMIC_PROTOS=ON \
-DVIAMCPPSDK_OFFLINE_PROTO_GENERATION=ON \
-DVIAMCPPSDK_SANITIZED_BUILD=$BUILD_SHARED \
-DVIAMCPPSDK_CLANG_TIDY=ON \
-DBUILD_SHARED_LIBS=$BUILD_SHARED

ninja all
ninja install
INSTALL_DIR="$(pwd)/install"
BUILD_SHARED=$(grep 'BUILD_SHARED_LIBS' CMakeCache.txt | cut -d '=' -f 2)

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

0 comments on commit d4a6e52

Please sign in to comment.