mirror of
https://github.com/kylemanna/docker-aosp
synced 2025-06-07 16:06:17 +00:00
Merge pull request #11 from jcfr/support-current-user-with-arbitrary-uid-gid
Update `Dockerfile` and `utils/aosp` to work with arbitrary uid gid
This commit is contained in:
commit
4fd3a9d184
29
Dockerfile
29
Dockerfile
@ -23,11 +23,28 @@ RUN apt-get update && \
|
|||||||
ADD https://commondatastorage.googleapis.com/git-repo-downloads/repo /usr/local/bin/
|
ADD https://commondatastorage.googleapis.com/git-repo-downloads/repo /usr/local/bin/
|
||||||
RUN chmod 755 /usr/local/bin/*
|
RUN chmod 755 /usr/local/bin/*
|
||||||
|
|
||||||
|
# Install latest version of JDK
|
||||||
|
# See http://source.android.com/source/initializing.html#setting-up-a-linux-build-environment
|
||||||
|
WORKDIR /tmp
|
||||||
|
RUN curl -O http://mirrors.kernel.org/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jre-headless_8u45-b14-1_amd64.deb && \
|
||||||
|
curl -O http://mirrors.kernel.org/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jre_8u45-b14-1_amd64.deb && \
|
||||||
|
curl -O http://mirrors.kernel.org/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jdk_8u45-b14-1_amd64.deb && \
|
||||||
|
sum=`shasum ./openjdk-8-jre-headless_8u45-b14-1_amd64.deb | awk '{ print $1 }'` && \
|
||||||
|
[ $sum == "e10d79f7fd1b3d011d9a4910bc3e96c3090f3306" ] || \
|
||||||
|
( echo "Hash mismatch. Problem downloading openjdk-8-jre-headless" ; exit 1; ) && \
|
||||||
|
sum=`shasum ./openjdk-8-jre_8u45-b14-1_amd64.deb | awk '{ print $1 }'` && \
|
||||||
|
[ $sum == "1e083bb952fc97ab33cd46f68e82688d2b8acc34" ] || \
|
||||||
|
( echo "Hash mismatch. Problem downloading openjdk-8-jre" ; exit 1; ) && \
|
||||||
|
sum=`shasum ./openjdk-8-jdk_8u45-b14-1_amd64.deb | awk '{ print $1 }'` && \
|
||||||
|
[ $sum == "772e904961a2a5c7d2d129bdbcfd5c16a0fab4bf" ] || \
|
||||||
|
( echo "Hash mismatch. Problem downloading openjdk-8-jdk" ; exit 1; ) && \
|
||||||
|
dpkg -i *.deb && \
|
||||||
|
apt-get -f install && \
|
||||||
|
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
|
||||||
# All builds will be done by user aosp
|
# All builds will be done by user aosp
|
||||||
RUN useradd --create-home aosp
|
COPY gitconfig /root/.gitconfig
|
||||||
ADD gitconfig /home/aosp/.gitconfig
|
COPY ssh_config /root/.ssh/config
|
||||||
ADD ssh_config /home/aosp/.ssh/config
|
|
||||||
RUN chown aosp:aosp /home/aosp/.gitconfig
|
|
||||||
|
|
||||||
# The persistent data will be in these two directories, everything else is
|
# The persistent data will be in these two directories, everything else is
|
||||||
# considered to be ephemeral
|
# considered to be ephemeral
|
||||||
@ -38,5 +55,7 @@ ENV USE_CCACHE 1
|
|||||||
ENV CCACHE_DIR /tmp/ccache
|
ENV CCACHE_DIR /tmp/ccache
|
||||||
|
|
||||||
# Work in the build directory, repo is expected to be init'd here
|
# Work in the build directory, repo is expected to be init'd here
|
||||||
USER aosp
|
|
||||||
WORKDIR /aosp
|
WORKDIR /aosp
|
||||||
|
|
||||||
|
COPY utils/docker_entrypoint.sh /root/docker_entrypoint.sh
|
||||||
|
ENTRYPOINT ["/root/docker_entrypoint.sh"]
|
||||||
|
9
Makefile
Normal file
9
Makefile
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
DOCKER = docker
|
||||||
|
IMAGE = kylemanna/aosp
|
||||||
|
|
||||||
|
aosp: Dockerfile
|
||||||
|
$(DOCKER) build -t $(IMAGE) .
|
||||||
|
|
||||||
|
all: aosp
|
||||||
|
|
||||||
|
.PHONY: all
|
41
utils/aosp
41
utils/aosp
@ -8,21 +8,44 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Override from environment
|
# Override from environment
|
||||||
AOSP_IMAGE=${AOSP_IMAGE:-kylemanna/aosp}
|
|
||||||
AOSP_VOL=${AOSP_VOL:-/vol0}
|
|
||||||
AOSP_ARGS=${AOSP_ARGS:---rm -it}
|
|
||||||
AOSP_VOL_AOSP=${AOSP_VOL_AOSP:-$AOSP_VOL/aosp}
|
|
||||||
AOSP_VOL_CCACHE=${AOSP_VOL_CCACHE:-$AOSP_VOL/ccache}
|
|
||||||
|
|
||||||
if [ ! -d "$AOSP_VOL_AOSP" -o ! -d "$AOSP_VOL_CCACHE" ]; then
|
AOSP_IMAGE=${AOSP_IMAGE:-kylemanna/aosp}
|
||||||
sudo mkdir -p $AOSP_VOL_AOSP $AOSP_VOL_CCACHE
|
AOSP_ARGS=${AOSP_ARGS:---rm -it}
|
||||||
sudo chmod 777 $AOSP_VOL_AOSP $AOSP_VOL_CCACHE
|
|
||||||
|
AOSP_VOL=${AOSP_VOL:-~/aosp-root}
|
||||||
|
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
|
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
|
if [ -n "$SSH_AUTH_SOCK" ]; then
|
||||||
SSH_AUTH_ARGS="-v $SSH_AUTH_SOCK:/tmp/ssh_auth -e SSH_AUTH_SOCK=/tmp/ssh_auth"
|
SSH_AUTH_ARGS="-v $SSH_AUTH_SOCK:/tmp/ssh_auth -e SSH_AUTH_SOCK=/tmp/ssh_auth"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
docker run $AOSP_ARGS $SSH_AUTH_ARGS $AOSP_EXTRA_ARGS \
|
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" \
|
-v "$AOSP_VOL_AOSP:/aosp" -v "$AOSP_VOL_CCACHE:/tmp/ccache" \
|
||||||
$AOSP_IMAGE $@
|
$AOSP_IMAGE $@
|
||||||
|
48
utils/docker_entrypoint.sh
Executable file
48
utils/docker_entrypoint.sh
Executable file
@ -0,0 +1,48 @@
|
|||||||
|
#!/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 ""
|
||||||
|
|
||||||
|
# Default to 'bash' if no arguments are provided
|
||||||
|
args="$@"
|
||||||
|
if [ -z "$args" ]; then
|
||||||
|
args="bash"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Execute command as `aosp` user
|
||||||
|
export HOME=/home/aosp
|
||||||
|
exec sudo -u aosp $args
|
Loading…
x
Reference in New Issue
Block a user