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

Separate UID and GID and fix ccache #20

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
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
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
Loading