dockcross/imagefiles/entrypoint.sh

49 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
# This is the entrypoint script for the dockerfile. Executed in the
# container at runtime.
if [[ $# == 0 ]]; then
# Presumably the image has been run directly, so help the user get
# started by outputting the dockcross script
if [[ -n $DEFAULT_DOCKCROSS_IMAGE ]]; then
head -n 2 /dockcross/dockcross
echo "DEFAULT_DOCKCROSS_IMAGE=$DEFAULT_DOCKCROSS_IMAGE"
tail -n +4 /dockcross/dockcross
else
cat /dockcross/dockcross
fi
exit 0
fi
# If we are running docker natively, we want to create a user in the container
# with the same UID and GID as the user on the host machine, so that any files
# created are owned by that user. Without this they are all owned by root.
# The dockcross script sets the BUILDER_UID and BUILDER_GID vars.
if [[ -n $BUILDER_UID ]] && [[ -n $BUILDER_GID ]]; then
groupadd -o -g $BUILDER_GID $BUILDER_GROUP 2> /dev/null
useradd -o -m -g $BUILDER_GID -u $BUILDER_UID $BUILDER_USER 2> /dev/null
manylinux: Grant current user password less sudo access. This will allow build script like "build-wheels.sh" to run command like the following (see [1]): sudo yum install -y atlas-devel It will also allow to pip install using sudo and avoid error reported in [3]. That said, instead of running pip using sudo, the recommended approach is to specify the "--user" flag [2] [1] https://github.com/pypa/python-manylinux-demo/blob/893d92517e9e289b9d2ee063f19c3216a39534ab/travis/build-wheels.sh [2] http://stackoverflow.com/questions/7143077/how-can-i-install-packages-in-my-home-folder-with-pip#7143496 [3] Error reported when running pip without "sudo pip install <packagename" or "pip install --user <packagename>" ``` Exception: Traceback (most recent call last): File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run prefix=options.prefix_path, File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/req/req_set.py", line 736, in install requirement.uninstall(auto_confirm=True) File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/req/req_install.py", line 742, in uninstall paths_to_remove.remove(auto_confirm) File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove renames(path, new_path) File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/site-packages/pip/utils/__init__.py", line 267, in renames shutil.move(old, new) File "/opt/_internal/cpython-2.7.11-ucs2/lib/python2.7/shutil.py", line 303, in move os.unlink(src) OSError: [Errno 13] Permission denied: '/opt/_internal/cpython-2.7.11-ucs2/bin/easy_install' ```
2016-09-22 07:11:12 +02:00
echo "$BUILDER_USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
export HOME=/home/${BUILDER_USER}
shopt -s dotglob
cp -r /root/* $HOME/
chown -R $BUILDER_UID:$BUILDER_GID $HOME/*
# Additional updates specific to the image
if [[ -e /dockcross/pre_exec.sh ]]; then
/dockcross/pre_exec.sh
fi
# Execute project specific pre execution hook
if [[ -e /work/.dockcross ]]; then
chpst -u :$BUILDER_UID:$BUILDER_GID /work/.dockcross
fi
# Run the command as the specified user/group.
exec chpst -u :$BUILDER_UID:$BUILDER_GID "$@"
else
# Just run the command as root.
exec "$@"
fi