Skip to content

Commit 4c49921

Browse files
committed
[6.0-marshmallow] Add gosu and refactor things
1 parent 224c2e0 commit 4c49921

File tree

4 files changed

+50
-46
lines changed

4 files changed

+50
-46
lines changed

Dockerfile

+17-26
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
#
44
FROM ubuntu:14.04
55

6-
MAINTAINER Kyle Manna <[email protected]>
6+
LABEL maintainer "Kyle Manna <[email protected]>"
77

8+
ENV GOSU_VERSION 1.10
9+
ENV DEBIAN_FRONTEND noninteractive
810
# /bin/sh points to Dash by default, reconfigure to use bash until Android
911
# build becomes POSIX compliant
1012
RUN echo "dash dash/sh boolean false" | debconf-set-selections && \
@@ -16,32 +18,22 @@ RUN apt-get update && \
1618
flex g++-multilib gcc-multilib git gnupg gperf lib32ncurses5-dev \
1719
lib32readline-gplv2-dev lib32z1-dev libesd0-dev libncurses5-dev \
1820
libsdl1.2-dev libwxgtk2.8-dev libxml2-utils lzop \
19-
openjdk-7-jdk \
20-
pngcrush schedtool xsltproc zip zlib1g-dev && \
21+
openjdk-7-jdk pngcrush schedtool xsltproc zip zlib1g-dev && \
22+
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
23+
curl -Ls "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" -o /usr/local/bin/gosu; \
24+
curl -Ls "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc" -o /usr/local/bin/gosu.asc \
25+
# verify the signature
26+
export GNUPGHOME="$(mktemp -d)"; \
27+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
28+
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
29+
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
30+
chmod +x /usr/local/bin/gosu; \
31+
# verify it works
32+
gosu nobody true; \
2133
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
22-
2334
ADD https://commondatastorage.googleapis.com/git-repo-downloads/repo /usr/local/bin/
2435
RUN chmod 755 /usr/local/bin/*
2536

26-
# Install latest version of JDK
27-
# See http://source.android.com/source/initializing.html#setting-up-a-linux-build-environment
28-
WORKDIR /tmp
29-
RUN curl -O http://mirrors.kernel.org/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jre-headless_8u45-b14-1_amd64.deb && \
30-
curl -O http://mirrors.kernel.org/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jre_8u45-b14-1_amd64.deb && \
31-
curl -O http://mirrors.kernel.org/ubuntu/pool/universe/o/openjdk-8/openjdk-8-jdk_8u45-b14-1_amd64.deb && \
32-
sum=`shasum ./openjdk-8-jre-headless_8u45-b14-1_amd64.deb | awk '{ print $1 }'` && \
33-
[ $sum == "e10d79f7fd1b3d011d9a4910bc3e96c3090f3306" ] || \
34-
( echo "Hash mismatch. Problem downloading openjdk-8-jre-headless" ; exit 1; ) && \
35-
sum=`shasum ./openjdk-8-jre_8u45-b14-1_amd64.deb | awk '{ print $1 }'` && \
36-
[ $sum == "1e083bb952fc97ab33cd46f68e82688d2b8acc34" ] || \
37-
( echo "Hash mismatch. Problem downloading openjdk-8-jre" ; exit 1; ) && \
38-
sum=`shasum ./openjdk-8-jdk_8u45-b14-1_amd64.deb | awk '{ print $1 }'` && \
39-
[ $sum == "772e904961a2a5c7d2d129bdbcfd5c16a0fab4bf" ] || \
40-
( echo "Hash mismatch. Problem downloading openjdk-8-jdk" ; exit 1; ) && \
41-
dpkg -i *.deb && \
42-
apt-get -f install && \
43-
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
44-
4537
# All builds will be done by user aosp
4638
COPY gitconfig /root/.gitconfig
4739
COPY ssh_config /root/.ssh/config
@@ -52,6 +44,5 @@ VOLUME ["/tmp/ccache", "/aosp"]
5244

5345
# Work in the build directory, repo is expected to be init'd here
5446
WORKDIR /aosp
55-
56-
COPY utils/docker_entrypoint.sh /root/docker_entrypoint.sh
57-
ENTRYPOINT ["/root/docker_entrypoint.sh"]
47+
COPY utils/docker_entrypoint.sh /docker_entrypoint.sh
48+
ENTRYPOINT ["/docker_entrypoint.sh"]

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ on the main Ubuntu base image.
6060
The `aosp` wrapper is a simple wrapper to simplify invocation of the Docker
6161
image. The wrapper ensures that a volume mount is accessible and has valid
6262
permissions for the `aosp` user in the Docker image (this unfortunately
63-
requires sudo). It also forwards an ssh-agent in to the Docker container
63+
requires sudo, or for you to be in `docker` group.).
64+
It also forwards an ssh-agent in to the Docker container
6465
so that private git repositories can be accessed if needed.
6566

6667
The intention is to use `aosp` to prefix all commands one would run in the
@@ -82,10 +83,17 @@ version: "2"
8283

8384
services:
8485
aosp:
86+
build: . # comment out to use docker hub image -- otherwise an image will be built locally with the same name as the docker hub version
8587
image: kylemanna/aosp:6.0-marshmallow
88+
container_name: aosp
8689
volumes:
87-
- /tmp/ccache:/ccache
90+
- ~/aosp/ccache:/tmp/ccache
8891
- ~/aosp:/aosp
92+
- ~/.gitconfig:/home/aosp/.gitconfig
93+
- ~/.ssh:/home/aosp/.ssh
94+
- $SSH_AUTH_SOCK:/tmp/ssh_auth
95+
environment:
96+
- SSH_AUTH_SOCK=/tmp/ssh_auth
8997
```
9098
Example run: `docker-compose run --rm aosp repo sync -j4` -- your android build directory will be in `~/aosp`.
9199

docker-compose.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ version: "2"
22

33
services:
44
aosp:
5+
build: . # comment out to use docker hub image -- otherwise an image will be built locally with the same name as the docker hub version
56
image: kylemanna/aosp:6.0-marshmallow
67
volumes:
78
- ~/aosp/ccache:/tmp/ccache
89
- ~/aosp:/aosp
9-
- ~/.gitconfig:/root/.gitconfig
10+
- ~/.gitconfig:/home/aosp/.gitconfig
11+
- ~/.ssh:/home/aosp/.ssh
12+
- $SSH_AUTH_SOCK:/tmp/ssh_auth
13+
environment:
14+
- SSH_AUTH_SOCK=/tmp/ssh_auth

utils/docker_entrypoint.sh

+17-17
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@ set -e
1414
#
1515

1616
# Reasonable defaults if no USER_ID/GROUP_ID environment variables are set.
17-
if [ -z ${USER_ID+x} ]; then USER_ID=1000; fi
18-
if [ -z ${GROUP_ID+x} ]; then GROUP_ID=1000; fi
17+
USER_ID=${USER_ID:-1000}
18+
GROUP_ID=${GROUP_ID:-1000}
1919

2020
# ccache
2121
export CCACHE_DIR=/tmp/ccache
2222
export USE_CCACHE=1
2323

2424
msg="docker_entrypoint: Creating user UID/GID [$USER_ID/$GROUP_ID]" && echo $msg
25-
groupadd -g $GROUP_ID -r aosp && \
26-
useradd -u $USER_ID --create-home -r -g aosp aosp
27-
echo "$msg - done"
28-
29-
msg="docker_entrypoint: Copying .gitconfig and .ssh/config to new user home" && echo $msg
30-
cp /root/.gitconfig /home/aosp/.gitconfig && \
31-
chown aosp:aosp /home/aosp/.gitconfig && \
32-
mkdir -p /home/aosp/.ssh && \
33-
cp /root/.ssh/config /home/aosp/.ssh/config && \
34-
chown aosp:aosp -R /home/aosp/.ssh &&
25+
groupadd -g $GROUP_ID -r aosp ; useradd -u $USER_ID -r -g aosp aosp
3526
echo "$msg - done"
27+
echo ""
3628

3729
msg="docker_entrypoint: Creating /tmp/ccache and /aosp directory" && echo $msg
3830
mkdir -p /tmp/ccache /aosp
3931
chown aosp:aosp /tmp/ccache /aosp
4032
echo "$msg - done"
33+
echo ""
34+
35+
msg="docker_entrypoint: Creating ssh and git config (if needed)" && echo $msg
36+
mkdir -p /home/aosp/.ssh
37+
cp -n /root/.gitconfig /home/aosp/ # no clobber (do not copy if file exists)
38+
cp -n /root/.ssh/config /home/aosp/.ssh/ # no clobber (do not copy if file exists)
39+
echo "$msg - done"
4140

41+
msg="docker_entrypoint: Changing ownership of gitconfig and .ssh/config..." && echo $msg
42+
chown -R aosp:aosp /home/aosp/.gitconfig /home/aosp/.ssh/
43+
echo "$msg - done"
4244
echo ""
4345

4446
# Default to 'bash' if no arguments are provided
4547
args="$@"
46-
if [ -z "$args" ]; then
47-
args="bash"
48-
fi
48+
49+
export USER=aosp
4950

5051
# Execute command as `aosp` user
51-
export HOME=/home/aosp
52-
exec sudo -u aosp $args
52+
exec gosu aosp ${args:-"bash"}

0 commit comments

Comments
 (0)