Skip to content

Commit ce7dd92

Browse files
committed
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
1 parent c26aa61 commit ce7dd92

File tree

2 files changed

+87
-29
lines changed

2 files changed

+87
-29
lines changed

riotdocker-base/Dockerfile

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,11 @@ FROM ubuntu:jammy
33
LABEL maintainer="Kaspar Schleiser <[email protected]>"
44

55
RUN \
6-
echo 'Update the package index files to latest available versions' >&2 && \
7-
apt-get update && \
8-
echo 'Install GCC' >&2 && \
9-
apt-get -y --no-install-recommends install \
10-
gcc \
11-
git \
12-
python3 \
13-
python3-dev \
14-
python3-pip \
15-
&& \
16-
echo 'Clean up installation files' >&2 && \
17-
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
6+
--mount=type=bind,source=build.sh,target=/root/build.sh \
7+
--mount=type=bind,source=run.sh,target=/root/run.sh \
8+
--mount=type=bind,source=create_user.c,target=/root/create_user.c \
9+
cd /root && ./build.sh
1810

19-
# compile suid create_user binary
20-
COPY create_user.c /tmp/create_user.c
21-
RUN gcc -DHOMEDIR=\"/data/riotbuild\" -DUSERNAME=\"riotbuild\" /tmp/create_user.c -o /usr/local/bin/create_user \
22-
&& chown root:root /usr/local/bin/create_user \
23-
&& chmod u=rws,g=x,o=- /usr/local/bin/create_user \
24-
&& rm /tmp/create_user.c
25-
26-
# Create working directory for mounting the RIOT sources
27-
RUN mkdir -m 777 -p /data/riotbuild
28-
29-
# Set a global system-wide git user and email address
30-
RUN git config --system user.name "riot" && \
31-
git config --system user.email "[email protected]" && \
32-
git config --system --add safe.directory /data/riotbuild
33-
34-
# Copy our entry point script (signal wrapper)
35-
COPY run.sh /run.sh
3611
ENTRYPOINT ["/bin/bash", "/run.sh"]
3712

3813
# By default, run a shell when no command is specified on the docker command line

riotdocker-base/build.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
# Automatically exit on error
4+
set -e
5+
6+
COUNTER_STEP=0
7+
COUNTER_SUBSTEP=0
8+
BLUE="\e[34m"
9+
BOLD="\e[1m"
10+
NORMAL="\e[0m"
11+
12+
step() {
13+
COUNTER_SUBSTEP=0
14+
COUNTER_STEP=$(("$COUNTER_STEP" + 1))
15+
printf "${BLUE}${BOLD}==>${NORMAL}${BOLD} Step %d:${NORMAL} %s\n" "$COUNTER_STEP" "$1"
16+
}
17+
18+
substep() {
19+
COUNTER_SUBSTEP=$(("$COUNTER_SUBSTEP" + 1))
20+
printf "${BLUE}${BOLD} -->${NORMAL}${BOLD} Step %d.%d:${NORMAL} %s\n" \
21+
"$COUNTER_STEP" "$COUNTER_SUBSTEP" "$1"
22+
}
23+
24+
step_install_dev_tools() {
25+
step "Installing development tools"
26+
27+
substep "Updating package index"
28+
apt-get update
29+
30+
substep "Installing GCC"
31+
apt-get -y --no-install-recommends install gcc
32+
33+
substep "Installing git"
34+
apt-get -y --no-install-recommends install git
35+
36+
substep "Installing Python"
37+
apt-get -y --no-install-recommends install \
38+
python3 \
39+
python3-dev \
40+
python3-pip
41+
42+
substep "Clean up installation files"
43+
apt-get clean
44+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
45+
}
46+
47+
step_provide_create_user_cmd() {
48+
step "Providing create_user binary"
49+
50+
substep "Compiling create_user from source"
51+
gcc -DHOMEDIR=\"/data/riotbuild\" -DUSERNAME=\"riotbuild\" create_user.c -o /usr/local/bin/create_user
52+
53+
substep "Updating file attributes of create_user"
54+
chown root:root /usr/local/bin/create_user
55+
chmod u=rws,g=x,o=- /usr/local/bin/create_user
56+
}
57+
58+
step_setup_dirs() {
59+
step "Setting up folders and files"
60+
61+
substep "Creating /data/riotbuild"
62+
mkdir -m 777 -p /data/riotbuild
63+
64+
substep "Creating /run.sh"
65+
cp run.sh /run.sh
66+
}
67+
68+
step_setup_git() {
69+
step "Setting up git"
70+
71+
substep "Configuring user and email"
72+
git config --system user.name "riot"
73+
git config --system user.email "[email protected]"
74+
75+
substep "Setting up safe directories"
76+
git config --system --add safe.directory /data/riotbuild
77+
}
78+
79+
step_install_dev_tools
80+
step_provide_create_user_cmd
81+
step_setup_dirs
82+
step_setup_git
83+
exit 0

0 commit comments

Comments
 (0)