Support build as user (#405)

* Support build as user

* Update enter.sh

* Update Dockerfile

* Update enter.sh

* Update entry.sh
This commit is contained in:
Pascal Vizeli 2019-05-14 01:16:40 +02:00 committed by GitHub
parent 5f1fadad29
commit e8d14bdc60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -18,7 +18,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# Build Tools
RUN apt-get update && apt-get install -y --no-install-recommends \
wget patch vim cpio python unzip rsync bc bzip2 ncurses-dev \
wget patch vim cpio python unzip rsync bc bzip2 ncurses-dev sudo \
git make g++ file perl bash binutils locales qemu-utils bison flex \
&& rm -rf /var/lib/apt/lists/*

View File

@ -2,4 +2,7 @@
modprobe overlayfs
docker build -t hassbuildroot .
docker run -it --rm --privileged -v "$(pwd):/build" -v "${CACHE_DIR:=$HOME/hassos-cache}:/cache" hassbuildroot bash
docker run -it --rm --privileged \
-v "$(pwd):/build" -v "${CACHE_DIR:=$HOME/hassos-cache}:/cache" \
-e BUILDER_UID="$(id -u)" -e BUILDER_GID="$(id -g)" \
hassbuildroot bash

View File

@ -1,12 +1,21 @@
#!/bin/bash
set -e
USER="root"
# Run dockerd
dockerd -s vfs &> /dev/null &
# Setup local user
if [ "${BUILDER_UID:0}" -ne 0 ] && [ "${BUILDER_GID:0}" -ne 0 ]; then
groupadd -g "${BUILDER_GID}" builder
useradd -m -u "${BUILDER_UID}" -g "${BUILDER_GID}" -G docker builder
USER="builder"
fi
if CMD="$(command -v "$1")"; then
shift
exec "$CMD" "$@"
sudo -H -u ${USER} "$CMD" "$@"
else
echo "Command not found: $1"
exit 1