-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
175 lines (160 loc) · 5.27 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
FROM ubuntu:jammy
LABEL maintainer="Adam Duskett <[email protected]>" \
description="Everything needed to build Buildroot mender configs in a reproducable manner."
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=US/Pacific
# Setup tzdata first as to avoid a dialog requesting tzdata setup.
RUN set -e; \
mkdir -p /data/; \
apt --allow-unauthenticated update; \
apt --allow-unauthenticated upgrade -y; \
apt-get install -y apt-utils gpgv2 locales tzdata; \
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8; \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime; \
echo $TZ > /etc/timezone;
# Install dependencies
RUN set -e; \
apt-get update; \
apt-get upgrade -y; \
apt-get install -y \
bash \
bash-completion \
bc \
bison \
bridge-utils \
bzip2 \
cmake \
cpio \
curl \
dialog \
expect \
file \
flex \
g++ \
gcc \
git \
help2man \
iproute2 \
lib32z1 \
make \
mc \
mercurial \
nano \
ncurses-dev \
net-tools \
patch \
psmisc \
python3-dev \
python3-pip \
python3-aiohttp \
python3-cvelib \
python3-ijson \
python3-nose2 \
python3-pexpect \
python3-requests \
qemu-kvm \
qemu-system-x86 \
rsync \
subversion \
sudo \
tar \
unzip \
wget \
gcc-multilib \
g++-multilib \
libc6-i386;
RUN set -e; \
pip3 install -U pip; \
pip3 install \
spdx_lookup==0.3.3;
# Set these arguments in the docker-compose.yml file and the docker/env file
# if you wish to change the default values.
# Default values:
# BUILDROOT_USER: br-user
# BUILDROOT_DIR: buildroot
# BUILDROOT_VERSION: If set to git, clone from the repo
# The buildroot source code is extracted to /home/${BUILDROOT_USER}/{BUILDROOT_DIR}
ARG BUILDROOT_USER
ARG BUILDROOT_DIR
ARG BUILDROOT_PATCH_DIR
ARG BUILDROOT_VERSION=2023.11.1
ARG BUILDROOT_BRANCH=master
ARG UID
ARG GID
# Add the ${BUILDROOT_USER} user, as buildroot should never be built as root.
RUN /bin/bash; \
set -e; \
groupadd -r -g ${GID} ${BUILDROOT_USER}; \
useradd -ms /bin/bash -u ${UID} -g ${GID} ${BUILDROOT_USER}; \
echo "alias ls='ls --color=auto'" >> /home/${BUILDROOT_USER}/.bashrc; \
echo "PS1='\u@\H [\w]$ '" >> /home/${BUILDROOT_USER}/.bashrc; \
chown -R ${BUILDROOT_USER}:${BUILDROOT_USER} /home/${BUILDROOT_USER}; \
if [ $BUILDROOT_VERSION = "git" ]; then \
echo "Cloning Buildroot on branch ${BUILDROOT_BRANCH}"; \
git clone git://git.buildroot.net/buildroot /home/${BUILDROOT_USER}/buildroot -b ${BUILDROOT_BRANCH}; \
if [ -n $BUILDROOT_COMMIT ]; then \
cd /home/${BUILDROOT_USER}/buildroot; \
git checkout ${BUILDROOT_COMMIT}; \
cd -; \
fi; \
else \
wget https://buildroot.org/downloads/buildroot-${BUILDROOT_VERSION}.tar.xz -O /home/${BUILDROOT_USER}/buildroot.tar.xz; \
mkdir -p /home/${BUILDROOT_USER}/${BUILDROOT_DIR}; \
tar -Jxf /home/${BUILDROOT_USER}/buildroot.tar.xz --strip-components=1 -C /home/${BUILDROOT_USER}/${BUILDROOT_DIR}; \
rm -rf /home/${BUILDROOT_USER}/buildroot.tar.xz; \
fi; \
chown -R ${BUILDROOT_USER}:${BUILDROOT_USER} /home/${BUILDROOT_USER}/${BUILDROOT_DIR};
# Copy brmake to /usr/bin for non-verbose builds.
WORKDIR /home/${BUILDROOT_USER}/${BUILDROOT_DIR}
RUN set -e; \
cp utils/brmake /usr/bin/brmake; \
chmod +x /usr/bin/brmake;
# Perform the following:
# - Pre-emtpively create the ccache diretory for permission purposes.
# - Link external_tree/{board,configs,dl} to the base buildroot directory.
ARG EXTERNAL_TREES
RUN set -e; \
mkdir -p /home/ccache; \
chown -R ${BUILDROOT_USER}:${BUILDROOT_USER} /home/ccache; \
mkdir -p /tmp/patches; \
for EXTERNAL_TREE in ${EXTERNAL_TREES}; do \
ln -s /mnt/${EXTERNAL_TREE} ${EXTERNAL_TREE}; \
done;
# Ensure that any patches held in ${external_trees}/patches/buildroot are applied.
# This ensures that relevant upstream patches cherry-picked from
# https://patchwork.ozlabs.org/project/buildroot/list/ are applied during the
# docker build process.
COPY ${BUILDROOT_PATCH_DIR}* /tmp/patches/
RUN set -e; \
cd /home/${BUILDROOT_USER}/${BUILDROOT_DIR}; \
if [ -n "${BUILDROOT_PATCH_DIR}" ]; then \
for i in $(find /tmp/patches/ -name "*.patch" -exec readlink -f {} \; | sort ); do \
echo "Applying patch: $(basename ${i})"; \
patch -p1 < "${i}"; done; \
fi; \
rm -rf ${BUILDROOT_PATCH_DIR}; \
chown -R ${BUILDROOT_USER}:${BUILDROOT_USER} /home/${BUILDROOT_USER}/${BUILDROOT_DIR};
# Link selinux-modules to their respective packages in the Buildroot directory
# We are external linking, but need a list of modules to link against, hence
# the copy.
ARG SELINUX_MODULES_DIR
COPY ${SELINUX_MODULES_DIR} /tmp/selinux-modules
RUN set -ex; \
ls /tmp/selinux-modules;
RUN set -e; \
for selinux_dir in $(find /tmp/selinux-modules -name selinux -type d); do \
pkg_name=$(dirname "${selinux_dir}" |cut -d'/' -f4); \
pkg_dest=/home/${BUILDROOT_USER}/"${BUILDROOT_DIR}"/package/"${pkg_name}"; \
if [ ! -d "${pkg_dest}" ]; then \
echo "${pkg_dest}: No such package"; \
exit 1; \
fi; \
cd "${pkg_dest}"; \
ln -sf /mnt/"${SELINUX_MODULES_DIR}"/"${pkg_name}"/selinux ./; \
done;
COPY --chown=${BUILDROOT_USER}:${BUILDROOT_USER} docker/init /init
USER ${BUILDROOT_USER}
ENV HOME /home/${BUILDROOT_USER}
WORKDIR /home/${BUILDROOT_USER}/${BUILDROOT_DIR}
ENTRYPOINT ["/init"]
CMD ["/bin/bash"]