mirror of
https://github.com/kylemanna/docker-aosp
synced 2025-06-07 16:06:17 +00:00
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) ```
52 lines
1.3 KiB
Bash
Executable File
52 lines
1.3 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Simple AOSP wrapper to run commands in an AOSP docker container
|
|
#
|
|
# Author: Kyle Manna <kyle@kylemanna.com>
|
|
#
|
|
|
|
set -e
|
|
|
|
# Override from environment
|
|
|
|
AOSP_IMAGE=${AOSP_IMAGE:-kylemanna/aosp}
|
|
AOSP_ARGS=${AOSP_ARGS:---rm -it}
|
|
|
|
AOSP_VOL=${AOSP_VOL:-/vol0}
|
|
AOSP_VOL=${AOSP_VOL%/} # Trim trailing slash if needed
|
|
AOSP_VOL_AOSP=${AOSP_VOL_AOSP:-$AOSP_VOL/aosp}
|
|
AOSP_VOL_AOSP=${AOSP_VOL_AOSP%/} # Trim trailing slash if needed
|
|
AOSP_VOL_CCACHE=${AOSP_VOL_CCACHE:-$AOSP_VOL/ccache}
|
|
AOSP_VOL_CCACHE=${AOSP_VOL_CCACHE%/} # Trim trailing slash if needed
|
|
|
|
# Convenience function
|
|
function aosp_create_dir_if_needed {
|
|
directory=$1
|
|
msg="aosp: Checking if $directory exists"
|
|
echo "$msg"
|
|
if [ ! -d "$directory" ]; then
|
|
echo "$msg - unexistent"
|
|
msg="Creating $directory"
|
|
echo "$msg"
|
|
mkdir -p $directory
|
|
fi
|
|
echo "$msg - ok"
|
|
}
|
|
|
|
# Create AOSP_VOL_AOSP
|
|
aosp_create_dir_if_needed $AOSP_VOL_AOSP
|
|
aosp_create_dir_if_needed $AOSP_VOL_CCACHE
|
|
|
|
# Set uid and gid to match host current user
|
|
AOSP_HOST_ID_ARGS="-e USER_ID=$(id -u) -e GROUP_ID=$(id -g)"
|
|
|
|
if [ -n "$SSH_AUTH_SOCK" ]; then
|
|
SSH_AUTH_ARGS="-v $SSH_AUTH_SOCK:/tmp/ssh_auth -e SSH_AUTH_SOCK=/tmp/ssh_auth"
|
|
fi
|
|
|
|
echo ""
|
|
|
|
docker run $AOSP_ARGS $AOSP_HOST_ID_ARGS $SSH_AUTH_ARGS $AOSP_EXTRA_ARGS \
|
|
-v "$AOSP_VOL_AOSP:/aosp" -v "$AOSP_VOL_CCACHE:/tmp/ccache" \
|
|
$AOSP_IMAGE $@
|