Skip to content

Commit a38bf20

Browse files
robbyoconnorDocker AOSP
authored and
Docker AOSP
committed
add gosu and refactor things
1 parent de429a4 commit a38bf20

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

Dockerfile

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
#
44
FROM ubuntu:16.04
55

6-
MAINTAINER Kyle Manna <[email protected]>
6+
LABEL maintainer "Kyle Manna <[email protected]>"
7+
8+
ENV GOSU_VERSION=1.10
9+
ENV DEBIAN_FRONTEND noninteractive
710

811
# /bin/sh points to Dash by default, reconfigure to use bash until Android
912
# build becomes POSIX compliant
@@ -12,24 +15,30 @@ RUN echo "dash dash/sh boolean false" | debconf-set-selections && \
1215

1316
# Keep the dependency list as short as reasonable
1417
RUN apt-get update && \
15-
apt-get install -y bc bison bsdmainutils build-essential curl \
18+
apt-get install -y ca-certificates bc bison bsdmainutils build-essential curl \
1619
flex g++-multilib gcc-multilib git gnupg gperf lib32ncurses5-dev \
1720
lib32z1-dev libesd0-dev libncurses5-dev \
18-
libsdl1.2-dev libwxgtk3.0-dev libxml2-utils lzop sudo \
19-
openjdk-8-jdk \
20-
pngcrush schedtool xsltproc zip zlib1g-dev graphviz && \
21+
libsdl1.2-dev libwxgtk3.0-dev libxml2-utils lzop \
22+
openjdk-8-jdk pngcrush schedtool xsltproc zip zlib1g-dev graphviz && \
23+
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
24+
curl -Ls "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" -o /usr/local/bin/gosu; \
25+
curl -Ls "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc" -o /usr/local/bin/gosu.asc \
26+
# verify the signature
27+
export GNUPGHOME="$(mktemp -d)"; \
28+
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
29+
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
30+
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
31+
chmod +x /usr/local/bin/gosu; \
32+
# verify it works
33+
gosu nobody true; \
2134
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
2235

2336
ADD https://commondatastorage.googleapis.com/git-repo-downloads/repo /usr/local/bin/
2437
RUN chmod 755 /usr/local/bin/*
2538

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-
3039
# All builds will be done by user aosp
31-
COPY gitconfig /root/.gitconfig
32-
COPY ssh_config /root/.ssh/config
40+
COPY gitconfig /home/aosp/.gitconfig
41+
COPY ssh_config /home/aosp/.ssh/config
3342

3443
# The persistent data will be in these two directories, everything else is
3544
# considered to be ephemeral
@@ -38,5 +47,5 @@ VOLUME ["/tmp/ccache", "/aosp"]
3847
# Work in the build directory, repo is expected to be init'd here
3948
WORKDIR /aosp
4049

41-
COPY utils/docker_entrypoint.sh /root/docker_entrypoint.sh
42-
ENTRYPOINT ["/root/docker_entrypoint.sh"]
50+
COPY utils/docker_entrypoint.sh /docker_entrypoint.sh
51+
ENTRYPOINT ["/docker_entrypoint.sh"]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ services:
8686
volumes:
8787
- /tmp/ccache:/ccache
8888
- ~/aosp:/aosp
89+
- ~/.gitconfig:/home/aosp/.gitconfig
90+
- ~/.ssh/:/home/aosp/.ssh/
8991
```
9092
Example run: `docker-compose run --rm aosp repo sync -j4` -- your android build directory will be in `~/aosp`.
9193

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ services:
66
volumes:
77
- ~/aosp/ccache:/tmp/ccache
88
- ~/aosp:/aosp
9-
- ~/.gitconfig:/root/.gitconfig
9+
- ~/.gitconfig:/home/aosp/.gitconfig
10+
# uncomment if you want this
11+
#- ~/.ssh/:/home/.ssh/

utils/docker_entrypoint.sh

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,32 @@ 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 ""
4134

35+
msg="docker_entrypoint: Changing ownership of gitconfig and .ssh/config..." && echo $msg
36+
chown -R aosp:aosp /home/aosp/.gitconfig /home/aosp/.ssh/
37+
echo "$msg - done"
4238
echo ""
4339

4440
# Default to 'bash' if no arguments are provided
4541
args="$@"
46-
if [ -z "$args" ]; then
47-
args="bash"
48-
fi
4942

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

0 commit comments

Comments
 (0)