diff --git a/riotdocker-base/Dockerfile b/riotdocker-base/Dockerfile index 75401897..bd6398ba 100644 --- a/riotdocker-base/Dockerfile +++ b/riotdocker-base/Dockerfile @@ -3,36 +3,11 @@ FROM ubuntu:jammy LABEL maintainer="Kaspar Schleiser " 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 "riot@example.com" && \ - 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 diff --git a/riotdocker-base/build.sh b/riotdocker-base/build.sh new file mode 100755 index 00000000..6c519b36 --- /dev/null +++ b/riotdocker-base/build.sh @@ -0,0 +1,112 @@ +#!/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 "::group::%s" "$1" + printf "${BLUE}${BOLD}==>${NORMAL}${BOLD} Step %d:${NORMAL} %s\n" "$COUNTER_STEP" "$1" +} + +endstep() { + echo "::endgroup::" +} + +substep() { + COUNTER_SUBSTEP=$(("$COUNTER_SUBSTEP" + 1)) + printf "::group::%s" "$1" + printf "${BLUE}${BOLD} -->${NORMAL}${BOLD} Step %d.%d:${NORMAL} %s\n" \ + "$COUNTER_STEP" "$COUNTER_SUBSTEP" "$1" +} + +endsubstep() { + echo "::endgroup::" +} + +step_install_dev_tools() { + step "Installing development tools" + + substep "Updating package index" + apt-get update + endsubstep + + substep "Installing GCC" + apt-get -y --no-install-recommends install gcc + endsubstep + + substep "Installing git" + apt-get -y --no-install-recommends install git + endsubstep + + substep "Installing Python" + apt-get -y --no-install-recommends install \ + python3 \ + python3-dev \ + python3-pip + endsubstep + + substep "Clean up installation files" + apt-get clean + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + endsubstep + + endstep +} + +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 + endsubstep + + 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 + endsubstep + + endstep +} + +step_setup_dirs() { + step "Setting up folders and files" + + substep "Creating /data/riotbuild" + mkdir -m 777 -p /data/riotbuild + endsubstep + + substep "Creating /run.sh" + cp run.sh /run.sh + endsubstep + + endstep +} + +step_setup_git() { + step "Setting up git" + + substep "Configuring user and email" + git config --system user.name "riot" + git config --system user.email "riot@example.com" + endsubstep + + substep "Setting up safe directories" + git config --system --add safe.directory /data/riotbuild + endsubstep + + endstep +} + +step_install_dev_tools +step_provide_create_user_cmd +step_setup_dirs +step_setup_git +exit 0