1
0
mirror of https://github.com/kylemanna/docker-aosp synced 2025-06-07 07:56:25 +00:00
docker-aosp/utils/docker_entrypoint.sh
Jean-Christophe Fillion-Robin 91ae4a8cdc utils/aosp: Update script and Dockerfile to work with any host user uid/gid
This commit introduces the "docker_entrypoint" script that will create
a user with uid/gid matching given `USER_ID` and `GROUP_ID` (or default to
`1000` if not provided).

Fixes #9

This approach works around missing docker feature discussed in
docker/docker#7198 and allow to have executable in the docker container
manipulating files in the shared volume owned by the `USER_ID:GROUP_ID`

The utility script `aosp` has also been updated to automatically
set `USER_ID` and `GROUP_ID` to the value matching the current user
by invoking "docker run" with

```
-e USER_ID=$(id -u) -e GROUP_ID=$(id -g)
```

Finally, the output has also been updated to be more verbose. For example:

```
$ AOSP_VOL=/home/jcfr/Projects/aosp-root/ aosp id
aosp: Checking if /home/jcfr/Projects/aosp-root/aosp exists
aosp: Checking if /home/jcfr/Projects/aosp-root/aosp exists - ok
aosp: Checking if /home/jcfr/Projects/aosp-root/ccache exists
aosp: Checking if /home/jcfr/Projects/aosp-root/ccache exists - ok

docker_entrypoint: Creating user UID/GID [1000/1000]
docker_entrypoint: Creating user UID/GID [1000/1000] - done
docker_entrypoint: Copying .gitconfig and .ssh/config to new user home
docker_entrypoint: Copying .gitconfig and .ssh/config to new user home - done
docker_entrypoint: Creating /tmp/ccache and /asop directory
docker_entrypoint: Creating /tmp/ccache and /asop directory - done

uid=1000(aosp) gid=1000(aosp) groups=1000(aosp)
```
2016-04-20 13:08:40 -04:00

44 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
set -e
# This script designed to be used a docker ENTRYPOINT "workaround" missing docker
# feature discussed in docker/docker#7198, allow to have executable in the docker
# container manipulating files in the shared volume owned by the USER_ID:GROUP_ID.
#
# It creates a user named `aosp` with selected USER_ID and GROUP_ID (or
# 1000 if not specified).
# Example:
#
# docker run -ti -e USER_ID=$(id -u) -e GROUP_ID=$(id -g) imagename bash
#
# Reasonable defaults if no USER_ID/GROUP_ID environment variables are set.
if [ -z ${USER_ID+x} ]; then USER_ID=1000; fi
if [ -z ${GROUP_ID+x} ]; then GROUP_ID=1000; fi
msg="docker_entrypoint: Creating user UID/GID [$USER_ID/$GROUP_ID]" && echo $msg
groupadd -g $GROUP_ID -r aosp && \
useradd -u $USER_ID --create-home -r -g aosp aosp
echo "$msg - done"
msg="docker_entrypoint: Copying .gitconfig and .ssh/config to new user home" && echo $msg
cp /root/.gitconfig /home/aosp/.gitconfig && \
chown aosp:aosp /home/aosp/.gitconfig && \
mkdir -p /home/aosp/.ssh && \
cp /root/.ssh/config /home/aosp/.ssh/config && \
chown aosp:aosp -R /home/aosp/.ssh &&
echo "$msg - done"
msg="docker_entrypoint: Creating /tmp/ccache and /asop directory" && echo $msg
mkdir -p /tmp/ccache /aosp
chown aosp:aosp /tmp/ccache /aosp
echo "$msg - done"
echo ""
# Execute command as `aosp` user
export HOME=/home/aosp
exec sudo -u aosp "$@"