Skip to content

Commit

Permalink
Separate UID and GID and fix ccache
Browse files Browse the repository at this point in the history
  • Loading branch information
griswaldbrooks committed Sep 8, 2023
1 parent 73e7afc commit b5e81fd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
54 changes: 40 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,22 @@ ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -q -y --no-install-recommends \
apt-utils \
ccache \
clang \
clang-format \
clang-tidy \
cmake \
git \
lld \
llvm \
python3-colcon-common-extensions \
python3-colcon-mixin \
python3-pip \
python3-colcon-common-extensions \
python3-colcon-lcov-result \
python3-colcon-coveragepy-result \
python3-colcon-mixin \
python3-pip \
python3-rosdep \
python3-vcstool \
vim \
wget \
ssh-client \
&& rm -rf /var/lib/apt/lists/*

# install some pip packages needed for testing
RUN python3 -m pip install -U \
pre-commit

# copy source to install repo dependencies
WORKDIR /ws
Expand All @@ -51,12 +42,47 @@ RUN rosdep update && apt-get update \

FROM upstream AS development

ARG UIDGID
ARG UID
ARG GID
ARG USER

# fail build if args are missing
RUN if [ -z "$UIDGID" ]; then echo '\nERROR: UIDGID not set. Run \n\n \texport UIDGID=$(id -u):$(id -g) \n\n on host before building Dockerfile.\n'; exit 1; fi
# hadolint ignore=SC2028
RUN if [ -z "$UID" ]; then echo '\nERROR: UID not set. Run \n\n \texport UID=$(id -u) \n\n on host before building Dockerfile.\n'; exit 1; fi
# hadolint ignore=SC2028
RUN if [ -z "$GID" ]; then echo '\nERROR: GID not set. Run \n\n \texport GID=$(id -g) \n\n on host before building Dockerfile.\n'; exit 1; fi
# hadolint ignore=SC2028
RUN if [ -z "$USER" ]; then echo '\nERROR: USER not set. Run \n\n \texport USER=$(whoami) \n\n on host before building Dockerfile.\n'; exit 1; fi

# chown working directory to user
RUN mkdir -p /home/${USER}/ws && chown -R ${UIDGID} /home/${USER}
# install developer tools
RUN --mount=type=cache,target=/var/cache/apt,id=apt \
apt-get update && apt-get upgrade -y \
&& apt-get install -q -y --no-install-recommends \
ccache \
clang-format \
clang-tidy \
git \
openssh-client \
vim \
wget \
&& rm -rf /var/lib/apt/lists/*

RUN python3 -m pip install --no-cache-dir \
pre-commit==3.0.4

# Setup user home directory
# --no-log-init helps with excessively long UIDs
RUN groupadd --gid $GID $USER \
&& useradd --no-log-init --uid $GID --gid $UID -m $USER --groups sudo \
&& echo $USER ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USER \
&& chmod 0440 /etc/sudoers.d/$USER \
&& echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> /home/${USER}/.profile \
&& touch /home/${USER}/.bashrc \
&& chown -R ${GID}:${UID} /home/${USER}

USER $USER
ENV SHELL /bin/bash
ENTRYPOINT []

# Setup mixin
WORKDIR /home/${USER}/ws
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Build a new development image
```
source .env
mkdir -p ~/.${REPO}/ccache
export UIDGID=$(id -u):$(id -g); docker compose -f compose.dev.yml build
export UID=$(id -u) export GID=$(id -g); docker compose -f compose.dev.yml build
```
Start an interactive development container
```
Expand Down
6 changes: 3 additions & 3 deletions compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ services:
development:
build:
args:
UIDGID: ${UIDGID}
UID: ${UID}
GID: ${GID}
USER: ${USER}
REPO: ${REPO}
context: .
Expand All @@ -13,6 +14,7 @@ services:
colcon mixin add default https://raw.githubusercontent.com/colcon/colcon-mixin-repository/master/index.yaml &&
colcon mixin update &&
export PATH="/usr/lib/ccache:$PATH" &&
source /opt/ros/humble/setup.bash &&
bash"
container_name: ${USER}-${REPO}-dev
environment:
Expand All @@ -26,14 +28,12 @@ services:
image: ${REPO}-dev:latest
network_mode: host
privileged: true
user: ${UIDGID}
volumes:
- ~/.ssh:${HOME}/.ssh:ro
- ~/.gitconfig:${HOME}/.gitconfig:ro
- ${PWD}:${HOME}/ws/src/${REPO}
- ~/.${REPO}/ccache:${HOME}/.ccache
- /tmp/.X11-unix:/tmp/.X11-unix:ro
- ${XDG_RUNTIME_DIR}:${XDG_RUNTIME_DIR}:ro
- /etc/group:/etc/group:ro
- /etc/passwd:/etc/passwd:ro
- /etc/shadow:/etc/shadow:ro
Expand Down

0 comments on commit b5e81fd

Please sign in to comment.