Skip to content

Commit 22dabbe

Browse files
Sam Mikes (He/him/his)danderson
Sam Mikes (He/him/his)
authored andcommitted
docker: refactor and update docker image build
Fixes tailscale/tailscale#15674 update docker image datestamp make docker-shell target use the build image with an explicit /bin/bash command retain the docker-remove-shell-image target in case something depends on it, but clarify that it is now a no-op hoist all ENV declarations hoist all mkdir commands combine mkdir commands use env vars in mkdir combine apt-get commands into single RUN make argument order consistent in apt-get commands collect packages into fewer apt-get commands add clean up of temporary files after apt-get expand apt-get commands to one package per line sort packages in apt-get commands combine go installation commands into single RUN update golang version to 1.24.1 also copy build.gradle file ensure gradlew is executable before running remove trailing newline per review comment, extract multiline apt-get command into shell script, copy and run that shell script within image during docker build Signed-off-by: Sam Mikes (He/him/his) <[email protected]>
1 parent a684f89 commit 22dabbe

File tree

4 files changed

+62
-71
lines changed

4 files changed

+62
-71
lines changed

Makefile

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# with this name, it will be used.
1111
#
1212
# The convention here is tailscale-android-build-amd64-<date>
13-
DOCKER_IMAGE := tailscale-android-build-amd64-031325-1
13+
DOCKER_IMAGE := tailscale-android-build-amd64-041425-1
1414
export TS_USE_TOOLCHAIN=1
1515

1616
# Auto-select an NDK from ANDROID_HOME (choose highest version available)
@@ -355,13 +355,12 @@ docker-remove-build-image: ## Removes the current docker build image
355355
docker-all: docker-build-image docker-run-build $(DOCKER_IMAGE)
356356

357357
.PHONY: docker-shell
358-
docker-shell: ## Builds a docker image with the android build env and opens a shell
359-
docker build -f docker/DockerFile.amd64-shell -t tailscale-android-shell-amd64 .
360-
docker run --rm -v $(CURDIR):/build/tailscale-android -it tailscale-android-shell-amd64
358+
docker-shell: docker-build-image ## Builds a docker image with the android build env and opens a shell
359+
docker run --rm -v $(CURDIR):/build/tailscale-android -it $(DOCKER_IMAGE) /bin/bash
361360

362361
.PHONY: docker-remove-shell-image
363362
docker-remove-shell-image: ## Removes all docker shell image
364-
docker rmi --force tailscale-android-shell-amd64
363+
@echo "docker-remove-shell-image retained for backward compatibility, but is a no-op; docker-shell now uses build image"
365364

366365
.PHONY: clean
367366
clean: ## Remove build artifacts. Does not purge docker build envs. Use dockerRemoveEnv for that.

docker/DockerFile.amd64-build

+19-19
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,30 @@
33

44
FROM --platform=linux/amd64 eclipse-temurin:21
55

6-
# To enable running android tools such as aapt
7-
RUN apt-get update && apt-get -y upgrade
8-
RUN apt-get install -y libz1 libstdc++6 unzip zip
9-
# For Go:
10-
RUN apt-get -y --no-install-recommends install curl gcc
11-
RUN apt-get -y --no-install-recommends install ca-certificates libc6-dev git
12-
13-
RUN apt-get -y install make
14-
15-
RUN mkdir -p build
166
ENV HOME /build
17-
18-
# Make android sdk location, the later make step will populate it.
19-
RUN mkdir android-sdk
207
ENV ANDROID_HOME $HOME/android-sdk
218
ENV ANDROID_SDK_ROOT $ANDROID_HOME
229
ENV PATH $PATH:$HOME/bin:$ANDROID_HOME/platform-tools
2310

11+
RUN mkdir -p \
12+
${HOME} \
13+
/android-sdk \
14+
${ANDROID_HOME} \
15+
$HOME/tailscale-android
16+
17+
# To enable running android tools such as aapt
18+
COPY scripts/docker-build-apt-get.sh /tmp
19+
RUN chmod 755 /tmp/docker-build-apt-get.sh && \
20+
/tmp/docker-build-apt-get.sh && \
21+
rm -f /tmp/docker-build-apt-get.sh
22+
2423
# We need some version of Go new enough to support the "embed" package
2524
# to run "go run tailscale.com/cmd/printdep" to figure out which Tailscale Go
2625
# version we need later, but otherwise this toolchain isn't used:
27-
RUN curl -L https://go.dev/dl/go1.23.0.linux-amd64.tar.gz | tar -C /usr/local -zxv
28-
RUN ln -s /usr/local/go/bin/go /usr/bin
26+
RUN \
27+
curl -L https://go.dev/dl/go1.24.1.linux-amd64.tar.gz | tar -C /usr/local -zxv && \
28+
ln -s /usr/local/go/bin/go /usr/bin
2929

30-
RUN mkdir -p $HOME/tailscale-android
3130
RUN git config --global --add safe.directory $HOME/tailscale-android
3231
WORKDIR $HOME/tailscale-android
3332

@@ -37,10 +36,11 @@ COPY Makefile Makefile
3736
RUN make androidsdk
3837

3938
# Preload Gradle
40-
COPY android/gradlew android/gradlew
39+
COPY android/gradlew android/build.gradle android
4140
COPY android/gradle android/gradle
42-
RUN ./android/gradlew
41+
42+
RUN chmod 755 android/gradlew && \
43+
./android/gradlew
4344

4445
# Build the android app, bump the playstore version code, and make the tv release
4546
CMD make clean && make release && make bump_version_code && make release-tv
46-

docker/DockerFile.amd64-shell

-47
This file was deleted.

scripts/docker-build-apt-get.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) Tailscale Inc & AUTHORS
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
#
6+
# docker-build-apt-get.sh runs 'apt'-related commands inside
7+
# the environment that /builds the docker image/
8+
set -x
9+
set -e
10+
11+
apt-get update
12+
apt-get -y upgrade
13+
14+
apt-get -y install \
15+
\
16+
libstdc++6 \
17+
libz1 \
18+
make \
19+
unzip \
20+
zip \
21+
\
22+
# end of sort region
23+
24+
apt-get -y --no-install-recommends install \
25+
\
26+
ca-certificates \
27+
curl \
28+
gcc \
29+
git \
30+
libc6-dev \
31+
\
32+
# end of sort region
33+
34+
apt-get -y clean
35+
36+
rm -rf \
37+
/var/cache/debconf \
38+
/var/lib/apt/lists \
39+
/var/lib/apt/dpkg

0 commit comments

Comments
 (0)