-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
riotdocker-base: Split out build logic
This splits out all the build logic into the bash script build.sh. This has two advantages: - Only a single layer is added for this Dockerfile - This reduces overhead, especially with the VFS storage driver - Still takes full advantage of de-duplication of the layers concept: No image is based on intermediate steps anyway - Improves maintainability - Strict split of meta data (--> Dockerfile) and build commands (--> build.sh) - No need for long `cmd_a && cmd_b && cmd_c && cmd_d` stuff anymore
- Loading branch information
Showing
2 changed files
with
87 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 \ | ||
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 |