Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker utility #187

Merged
merged 2 commits into from
Dec 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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 <[email protected]>

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"
17 changes: 17 additions & 0 deletions tools/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tools/run-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
# First-time usage: docker build . && docker tag <id> libcanard && ./run-docker.sh

dockerimage=libcanard

docker run -it --rm -v $(pwd):/home/user/libcanard:z -e LOCAL_USER_ID=`id -u` $dockerimage "$@"