Shrink docker image (#3362)

* Docker rm Android NDK Version 16-19

* Docker remove vulkan and shaderc too

* Docker remove duplicate files

* Separate Docker clean script

* Docker remove templates

* Docker bz2 large notices

* Docker try symlinks

* Docker preserve some SDK Libraries

* Docker rm fonts and resources from platforms

* Docker source properties.sh
This commit is contained in:
Wetitpig 2019-11-10 22:41:19 +08:00 committed by Leonid Pliushch
parent 63733da336
commit 83796081a9
2 changed files with 52 additions and 8 deletions

View File

@ -10,24 +10,19 @@ FROM ubuntu:19.04
ENV LANG C.UTF-8
# Needed for setup:
COPY ./setup-ubuntu.sh ./setup-android-sdk.sh ./properties.sh /tmp/
COPY ./docker-cleanup.sh ./setup-ubuntu.sh ./setup-android-sdk.sh ./properties.sh /tmp/
# Setup needed packages and the Android SDK and NDK:
RUN apt-get update && \
apt-get -yq upgrade && \
apt-get install -yq sudo && \
apt-get install -yq --no-install-recommends sudo fdupes && \
adduser --disabled-password --shell /bin/bash --gecos "" builder && \
echo "builder ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/builder && \
chmod 0440 /etc/sudoers.d/builder && \
su - builder -c /tmp/setup-ubuntu.sh && \
su - builder -c /tmp/setup-android-sdk.sh && \
# Removed unused parts to make a smaller Docker image:
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
cd /home/builder/lib/android-ndk/ && \
rm -Rf sources/cxx-stl/system && \
cd /home/builder/lib/android-sdk/tools && \
rm -Rf emulator* lib* proguard templates
su - builder -c /tmp/docker-cleanup.sh
# Switch User
USER builder:builder

49
scripts/docker-cleanup.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
set -e -u
. $(cd "$(dirname "$0")"; pwd)/properties.sh
echo "Cleaning APT"
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*
echo "Cleaning unneeded NDK modules"
cd /home/builder/lib/android-ndk/sources
rm -Rf cxx-stl/system third_party/shaderc third_party/vulkan
cd /home/builder/lib/android-ndk/platforms
rm -Rf android-16 android-17 android-18 android-19
cd /home/builder/lib/android-ndk
rm -Rf shader-tools
echo "Cleaning unneeded SDK modules"
cd /home/builder/lib/android-sdk/tools
mkdir -p lib2
cp $(grep "CLASSPATH=" bin/sdkmanager | head -n 1 | cut -d '=' -f 2 | tr ':' ' ' | sed 's%\$APP_HOME/%%g') lib2
rm -Rf emulator* lib proguard template support/*.txt
mv lib2 lib
cd /home/builder/lib/android-sdk/platforms/android-21
rm -Rf data templates skins
cd /home/builder/lib/android-sdk/platforms/android-28
rm -Rf data templates skins
echo "Zipping notices"
cd /home/builder/lib/android-ndk
bzip2 NOTICE NOTICE.toolchain sysroot/NOTICE
cd /home/builder/lib/android-sdk
bzip2 tools/NOTICE.txt build-tools/${TERMUX_ANDROID_BUILD_TOOLS_VERSION}/NOTICE.txt platform-tools/NOTICE.txt
cd /home/builder/lib/android-sdk/platforms
echo "Removing duplicate files"
fdupes -r -1 /home/builder/lib/android-ndk /home/builder/lib/android-sdk | \
while read line; do
master=""
for file in ${line[*]}; do
if [ "x${master}" == "x" ]; then
master=$file
else
ln -sf "${master}" "${file}"
fi
done
done
echo "Cleaning done"