Yocto build container: start as builduser

Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
This commit is contained in:
Thomas Klaehn 2017-11-16 13:26:17 +01:00
parent d64c9e41b1
commit 6691814ab4
2 changed files with 26 additions and 17 deletions

View File

@ -1,6 +1,6 @@
FROM debian:jessie
MAINTAINER Thomas Klaehn <thomas.klaehn@u-blox.com>
LABEL maintainer="thomas.klaehn@u-blox.com"
RUN apt-get update && \
apt-get install -yq sudo build-essential git python python3 man bash diffstat \
@ -19,11 +19,6 @@ RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
ENV LANG en_US.utf8
RUN mkdir -p /var/build
WORKDIR /var/build
ADD init.sh /usr/local/bin/init.sh
ENTRYPOINT ["/usr/local/bin/init.sh"]

36
init.sh
View File

@ -1,31 +1,45 @@
#!/bin/bash
username=builduser
usergroup=buildgroup
builddir=/var/build
now="$(date +%s >&1)"
username=builduser_${now}
usergroup=buildgroup_${now}
builddir=$(pwd)
homedir=/home/${username}
sshdir=${homedir}/.ssh
# figure out the uid/gid we need to use by integrating the path that has
# been bind mounted in. this is then used for the builduser.
# Figure out the uid/gid we need to use by integrating the path that has
# been bind mounted in. This is then used for the builduser.
BUILD_UID=$(stat --printf=%u ${builddir} 2> /dev/null)
BUILD_GID=$(stat --printf=%g ${builddir} 2> /dev/null)
# create a group
# Add docker container group/user.
groupadd --gid ${BUILD_GID} --non-unique ${usergroup}
# add user
useradd -s /bin/bash --home ${homedir} --non-unique --uid ${BUILD_UID} \
--gid ${BUILD_GID} --groups sudo ${username}
# give users in the sudo group sudo access in the container
# Give users in the sudo group sudo access in the container.
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# copy ssh key files
# Copy ssh key files.
mkdir -p ${homedir}
mkdir -p ${sshdir}
cp /var/ssh/* ${sshdir}/
chown -R ${username}:${usergroup} ${homedir}
exec "$@"
# Determine parallel build capabilities.
parallel_build="$(nproc >&1)"
if [ ${parallel_build} -gt 20 ]
then
BB_NUMBER_THREADS=20
PARALLEL_MAKE=20
else
BB_NUMBER_THREADS=${parallel_build}
PARALLEL_MAKE=${parallel_build}
fi
export BB_NUMBER_THREADS
export PARALLEL_MAKE
# Execute CMD
su ${username} -c "$@"