diff --git a/Dockerfile b/Dockerfile index d38676e2..6b2e8fc7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,6 @@ ENV LOGS_DIR /srv/logs ENV USERSCRIPTS_DIR /srv/userscripts ENV DEBIAN_FRONTEND noninteractive -ENV USER root # Configurable environment variables #################################### @@ -129,6 +128,14 @@ ENV REPO_INIT_ARGS "" # Allowed values: positive, non-null integers ENV RETRY_FETCHES= +# You can specify the user name, user id and group id of the linux user inside the docker container executing the build. +# In windows environments docker maps volume folders / files for the current windows user to the root inside the docker container. +# In *nix like environments the uid and gid of the volume folders / files will be identical on the host and inside the container. +# You can use these settings in such environments to match the volume folder / file owners your user on the host. +# If you use 0 as UID it is mandatory to also use the root USER, otherwise the USER name can be arbitrary and does not need to match the host. +ENV USER root +ENV UID 0 +ENV GID 0 # variables to control whether or not tasks are implemented ENV INIT_MIRROR true @@ -204,4 +211,4 @@ RUN ln -sf /proc/1/fd/1 /var/log/docker.log # Set the entry point to init.sh ################################ -ENTRYPOINT /root/init.sh +ENTRYPOINT /root/root_init.sh diff --git a/README.md b/README.md index 196c7624..b812b88c 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,8 @@ Other useful settings are: cores on your machine. Reducing this number can help keeping it responsive for other tasks. * `RETRY_FETCHES`: Set the number of retries for the fetch during `repo sync`. By default, this value is unset (default `repo sync` retry behavior). Positive values greater than 0 are allowed. + * `USER (root)`, `UID (0)`, `GID (0)`: Change this in unix like systems to match the docker volume owner with your host + owner. The full list of settings, including the less interesting ones not mentioned in this guide, can be found in the [Dockerfile][dockerfile]. diff --git a/src/root_init.sh b/src/root_init.sh new file mode 100755 index 00000000..49c46fdc --- /dev/null +++ b/src/root_init.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Docker init script +# Copyright (c) 2017 Julian Xhokaxhiu +# Copyright (C) 2017-2018 Nicola Corna +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +echo "Preparing user: ${USER} with UID: ${UID}, GID: ${GID}" + +if ! id -u "$USER" >/dev/null 2>&1 && [ ! -z "${UID}" ] && [ "${UID}" != "0" ]; then \ + groupadd -g ${GID} -o ${USER} && \ + useradd -m -u ${UID} -g ${GID} -o -s /bin/bash ${USER}; \ +fi + +chown -R ${USER}:${USER} /root + +exec su -c /root/init.sh ${USER} \ No newline at end of file