Skip to content

Commit

Permalink
[6.0-marshmallow] Add gosu and refactor things
Browse files Browse the repository at this point in the history
  • Loading branch information
robbyoconnor committed Jul 19, 2017
1 parent 224c2e0 commit 1460c4b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 48 deletions.
47 changes: 19 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#
FROM ubuntu:14.04

MAINTAINER Kyle Manna <[email protected]>
LABEL maintainer "Kyle Manna <[email protected]>"

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

ADD https://commondatastorage.googleapis.com/git-repo-downloads/repo /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
COPY gitconfig /root/.gitconfig
COPY ssh_config /root/.ssh/config
COPY gitconfig /home/aosp/.gitconfig
COPY ssh_config /home/aosp/.ssh/config

# The persistent data will be in these two directories, everything else is
# considered to be ephemeral
VOLUME ["/tmp/ccache", "/aosp"]

# Work in the build directory, repo is expected to be init'd here
WORKDIR /aosp

COPY utils/docker_entrypoint.sh /root/docker_entrypoint.sh
ENTRYPOINT ["/root/docker_entrypoint.sh"]
COPY utils/docker_entrypoint.sh /docker_entrypoint.sh
ENTRYPOINT ["/docker_entrypoint.sh"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ services:
volumes:
- /tmp/ccache:/ccache
- ~/aosp:/aosp
- ~/.gitconfig:/home/aosp/.gitconfig
- ~/.ssh/:/home/aosp/.ssh/
```
Example run: `docker-compose run --rm aosp repo sync -j4` -- your android build directory will be in `~/aosp`.

Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ services:
volumes:
- ~/aosp/ccache:/tmp/ccache
- ~/aosp:/aosp
- ~/.gitconfig:/root/.gitconfig
- ~/.gitconfig:/home/aosp/.gitconfig
# uncomment if you want this
#- ~/.ssh/:/home/.ssh/
29 changes: 10 additions & 19 deletions utils/docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,30 @@ set -e
#

# 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
USER_ID=${USER_ID:-1000}
GROUP_ID=${GROUP_ID:-1000}

# ccache
export CCACHE_DIR=/tmp/ccache
export USE_CCACHE=1

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
groupadd -g $GROUP_ID -r aosp ; useradd -u $USER_ID -r -g aosp aosp
echo "$msg - done"
echo ""

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 &&
msg="docker_entrypoint: Changing ownership of /tmp/ccache and /aosp..." && echo $msg
chown -R aosp:aosp /tmp/ccache /aosp
echo "$msg - done"
echo ""

msg="docker_entrypoint: Creating /tmp/ccache and /aosp directory" && echo $msg
mkdir -p /tmp/ccache /aosp
chown aosp:aosp /tmp/ccache /aosp
msg="docker_entrypoint: Changing ownership of gitconfig and .ssh/config..." && echo $msg
chown -R aosp:aosp /home/aosp/.gitconfig /home/aosp/.ssh/
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
exec gosu aosp ${args:-"bash"}

0 comments on commit 1460c4b

Please sign in to comment.