Skip to content

Commit 124b817

Browse files
committed
add gosu and refactor things
1 parent de429a4 commit 124b817

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

Dockerfile

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

6-
MAINTAINER Kyle Manna <kyle@kylemanna.com>
6+
LABEL maintainer "Kyle Manna <kyle@kylemanna.com>"
77

88
# /bin/sh points to Dash by default, reconfigure to use bash until Android
99
# build becomes POSIX compliant
1010
RUN echo "dash dash/sh boolean false" | debconf-set-selections && \
1111
dpkg-reconfigure -p critical dash
1212

1313
# Keep the dependency list as short as reasonable
14+
ENV GOSU_VERSION=1.10
15+
ENV DEBIAN_FRONTEND noninteractive
1416
RUN apt-get update && \
15-
apt-get install -y bc bison bsdmainutils build-essential curl \
17+
apt-get install -y ca-certificates bc bison bsdmainutils build-essential curl \
1618
flex g++-multilib gcc-multilib git gnupg gperf lib32ncurses5-dev \
1719
lib32z1-dev libesd0-dev libncurses5-dev \
1820
libsdl1.2-dev libwxgtk3.0-dev libxml2-utils lzop sudo \
1921
openjdk-8-jdk \
2022
pngcrush schedtool xsltproc zip zlib1g-dev graphviz && \
21-
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
23+
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
24+
curl -Ls "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" | tee /usr/local/bin/gosu; \
25+
curl -Ls "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"| tee /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 -r "$GNUPGHOME" /usr/local/bin/gosu.asc; \
31+
chmod +x /usr/local/bin/gosu; \
32+
# verify it works
33+
gosu nobody true; \
34+
apt-get purge -y --auto-remove ca-certificates ; 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/*
@@ -28,8 +41,8 @@ RUN chmod 755 /usr/local/bin/*
2841
WORKDIR /tmp
2942

3043
# All builds will be done by user aosp
31-
COPY gitconfig /root/.gitconfig
32-
COPY ssh_config /root/.ssh/config
44+
COPY gitconfig /home/aosp/.gitconfig
45+
COPY ssh_config /home/aosp/config
3346

3447
# The persistent data will be in these two directories, everything else is
3548
# considered to be ephemeral
@@ -38,5 +51,5 @@ VOLUME ["/tmp/ccache", "/aosp"]
3851
# Work in the build directory, repo is expected to be init'd here
3952
WORKDIR /aosp
4053

41-
COPY utils/docker_entrypoint.sh /root/docker_entrypoint.sh
42-
ENTRYPOINT ["/root/docker_entrypoint.sh"]
54+
COPY utils/docker_entrypoint.sh /docker_entrypoint.sh
55+
ENTRYPOINT ["/docker_entrypoint.sh"]

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: 11 additions & 18 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
25+
groupadd -g $GROUP_ID -r aosp ; useradd -u $USER_ID -r -g aosp aosp
2726
echo "$msg - done"
27+
echo ""
2828

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

37-
msg="docker_entrypoint: Creating /tmp/ccache and /aosp directory" && echo $msg
38-
mkdir -p /tmp/ccache /aosp
39-
chown aosp:aosp /tmp/ccache /aosp
34+
msg="docker_entrypoint: Changing ownership of gitconfig and .ssh/config..." && echo $msg
35+
chown -R aosp:aosp /home/aosp/.gitconfig /home/aosp/.ssh/
4036
echo "$msg - done"
41-
4237
echo ""
4338

4439
# Default to 'bash' if no arguments are provided
4540
args="$@"
46-
if [ -z "$args" ]; then
47-
args="bash"
48-
fi
41+
[ -z "$args" ] || args="bash"
4942

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

0 commit comments

Comments
 (0)