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

riotdocker-base: Split out build logic #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
33 changes: 4 additions & 29 deletions riotdocker-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,11 @@ FROM ubuntu:jammy
LABEL maintainer="Kaspar Schleiser <[email protected]>"

RUN \
echo 'Update the package index files to latest available versions' >&2 && \
apt-get update && \
echo 'Install GCC' >&2 && \
apt-get -y --no-install-recommends install \
gcc \
git \
python3 \
python3-dev \
python3-pip \
&& \
echo 'Clean up installation files' >&2 && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
--mount=type=bind,source=build.sh,target=/root/build.sh \
--mount=type=bind,source=run.sh,target=/root/run.sh \
--mount=type=bind,source=create_user.c,target=/root/create_user.c \
cd /root && ./build.sh

# compile suid create_user binary
COPY create_user.c /tmp/create_user.c
RUN gcc -DHOMEDIR=\"/data/riotbuild\" -DUSERNAME=\"riotbuild\" /tmp/create_user.c -o /usr/local/bin/create_user \
&& chown root:root /usr/local/bin/create_user \
&& chmod u=rws,g=x,o=- /usr/local/bin/create_user \
&& rm /tmp/create_user.c

# Create working directory for mounting the RIOT sources
RUN mkdir -m 777 -p /data/riotbuild

# Set a global system-wide git user and email address
RUN git config --system user.name "riot" && \
git config --system user.email "[email protected]" && \
git config --system --add safe.directory /data/riotbuild

# Copy our entry point script (signal wrapper)
COPY run.sh /run.sh
ENTRYPOINT ["/bin/bash", "/run.sh"]

# By default, run a shell when no command is specified on the docker command line
Expand Down
83 changes: 83 additions & 0 deletions riotdocker-base/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

# Automatically exit on error
set -e

COUNTER_STEP=0
COUNTER_SUBSTEP=0
BLUE="\e[34m"
BOLD="\e[1m"
NORMAL="\e[0m"

step() {
COUNTER_SUBSTEP=0
COUNTER_STEP=$(("$COUNTER_STEP" + 1))
printf "${BLUE}${BOLD}==>${NORMAL}${BOLD} Step %d:${NORMAL} %s\n" "$COUNTER_STEP" "$1"
}

substep() {
COUNTER_SUBSTEP=$(("$COUNTER_SUBSTEP" + 1))
printf "${BLUE}${BOLD} -->${NORMAL}${BOLD} Step %d.%d:${NORMAL} %s\n" \
"$COUNTER_STEP" "$COUNTER_SUBSTEP" "$1"
}

step_install_dev_tools() {
step "Installing development tools"

substep "Updating package index"
apt-get update

substep "Installing GCC"
apt-get -y --no-install-recommends install gcc

substep "Installing git"
apt-get -y --no-install-recommends install git

substep "Installing Python"
apt-get -y --no-install-recommends install \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing multiple apt-get install in separate steps incurs some run-time cost from hooks being run after each apt-get.

But fine with me -- it's little time spent in CI, and much better readability gained.

python3 \
python3-dev \
python3-pip

substep "Clean up installation files"
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
}

step_provide_create_user_cmd() {
step "Providing create_user binary"

substep "Compiling create_user from source"
gcc -DHOMEDIR=\"/data/riotbuild\" -DUSERNAME=\"riotbuild\" create_user.c -o /usr/local/bin/create_user

substep "Updating file attributes of create_user"
chown root:root /usr/local/bin/create_user
chmod u=rws,g=x,o=- /usr/local/bin/create_user
}

step_setup_dirs() {
step "Setting up folders and files"

substep "Creating /data/riotbuild"
mkdir -m 777 -p /data/riotbuild

substep "Creating /run.sh"
cp run.sh /run.sh
}

step_setup_git() {
step "Setting up git"

substep "Configuring user and email"
git config --system user.name "riot"
git config --system user.email "[email protected]"

substep "Setting up safe directories"
git config --system --add safe.directory /data/riotbuild
}

step_install_dev_tools
step_provide_create_user_cmd
step_setup_dirs
step_setup_git
exit 0