From d3a75463c21e654d5f05c076dfc9bebcc0bfad21 Mon Sep 17 00:00:00 2001 From: Kalyan Sriram Date: Fri, 3 Dec 2021 20:18:18 -0800 Subject: [PATCH 1/2] add docker utilities --- docker/Dockerfile | 29 +++++++++++++++++++++++++++++ docker/entrypoint.sh | 17 +++++++++++++++++ tools/run-docker.sh | 5 +++++ 3 files changed, 51 insertions(+) create mode 100644 docker/Dockerfile create mode 100755 docker/entrypoint.sh create mode 100755 tools/run-docker.sh diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..9767e25 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,29 @@ +# +# Development environment for libcanard, based on Ubuntu 20.04 Focal +# +# This software is distributed under the terms of the MIT License. +# Copyright (c) 2021 UAVCAN Consortium. +# Author: Kalyan Sriram + +FROM ubuntu:focal + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update && apt-get -y upgrade +RUN apt-get -y --no-install-recommends install \ + build-essential cmake gcc-multilib g++-multilib \ + clang-tidy-12 clang-format-12 \ + gcc-avr avr-libc \ + sudo curl git ca-certificates + +# borrowed from MAVSDK https://github.com/mavlink/MAVSDK/blob/main/docker/Dockerfile-Ubuntu-20.04 +RUN curl -L https://github.com/ncopa/su-exec/archive/dddd1567b7c76365e1e0aac561287975020a8fad.tar.gz | tar xvz && \ + cd su-exec-* && make && mv su-exec /usr/local/bin && cd .. && rm -rf su-exec-* + +RUN useradd --shell /bin/bash -u 1001 -c "" -m user + +COPY entrypoint.sh /usr/local/bin/entrypoint.sh + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + +WORKDIR "/home/user/libcanard" diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..ab25495 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# Utility to use local user, taken from: +# https://github.com/mavlink/MAVSDK/blob/main/docker/entrypoint.sh + +# Use LOCAL_USER_ID if passed in at runtime. + +if [ -n "${LOCAL_USER_ID}" ]; then + echo "Starting with UID: $LOCAL_USER_ID" + usermod -u $LOCAL_USER_ID user + export HOME=/home/user + chown -R user:user $HOME + + exec su-exec user "$@" +else + exec "$@" +fi diff --git a/tools/run-docker.sh b/tools/run-docker.sh new file mode 100755 index 0000000..837558c --- /dev/null +++ b/tools/run-docker.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +dockerimage=libcanard + +docker run -it --rm -v $(pwd):/home/user/libcanard:z -e LOCAL_USER_ID=`id -u` $dockerimage "$@" From b1da2c84421fc38d75269489d1c5beee9e633211 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sat, 4 Dec 2021 20:16:28 +0200 Subject: [PATCH 2/2] Move docker/ under tools/ and update the docs --- {docker => tools}/Dockerfile | 3 +-- {docker => tools}/entrypoint.sh | 0 tools/run-docker.sh | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) rename {docker => tools}/Dockerfile (99%) rename {docker => tools}/entrypoint.sh (100%) diff --git a/docker/Dockerfile b/tools/Dockerfile similarity index 99% rename from docker/Dockerfile rename to tools/Dockerfile index 9767e25..b7cc4a6 100644 --- a/docker/Dockerfile +++ b/tools/Dockerfile @@ -1,5 +1,4 @@ -# -# Development environment for libcanard, based on Ubuntu 20.04 Focal +# Development environment for libcanard, based on Ubuntu 20.04 Focal. # # This software is distributed under the terms of the MIT License. # Copyright (c) 2021 UAVCAN Consortium. diff --git a/docker/entrypoint.sh b/tools/entrypoint.sh similarity index 100% rename from docker/entrypoint.sh rename to tools/entrypoint.sh diff --git a/tools/run-docker.sh b/tools/run-docker.sh index 837558c..68c33f6 100755 --- a/tools/run-docker.sh +++ b/tools/run-docker.sh @@ -1,4 +1,5 @@ #!/usr/bin/env sh +# First-time usage: docker build . && docker tag libcanard && ./run-docker.sh dockerimage=libcanard