Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure the running user inside the docker container #701

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ ENV LOGS_DIR /srv/logs
ENV USERSCRIPTS_DIR /srv/userscripts

ENV DEBIAN_FRONTEND noninteractive
ENV USER root

# Configurable environment variables
####################################
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
29 changes: 29 additions & 0 deletions src/root_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Docker init script
# Copyright (c) 2017 Julian Xhokaxhiu
# Copyright (C) 2017-2018 Nicola Corna <[email protected]>
#
# 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 <http://www.gnu.org/licenses/>.

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}
Loading