CICD: Update the android Build Docker Image.

Update the android build docker image:
- rebase on ubuntu 22.04;
- add tooling required to sign APKs;
- changes to make the container re-usable;
- change to a multi-stage build to keep the image size smaller;
- generic improvements to the Dockerfile

Also update the example script for how to use the container.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2024-01-05 22:03:43 +13:00 committed by Dirk Hohndel
parent 62ca2d5b85
commit e8dd3389a7
4 changed files with 81 additions and 52 deletions

3
.gitignore vendored
View file

@ -42,3 +42,6 @@ packaging/ios/Info.plist
packaging/ios/Qt packaging/ios/Qt
packaging/ios/asset_catalog_compiler.Info.plist packaging/ios/asset_catalog_compiler.Info.plist
appdata/subsurface.appdata.xml appdata/subsurface.appdata.xml
scripts/docker/android-build-container/android-build-setup.sh
scripts/docker/android-build-container/variables.sh

View file

@ -19,7 +19,7 @@ CONTAINER_ID=$(docker container ls -a -q -f name=${CONTAINER_NAME})
# Create the image if it does not exist # Create the image if it does not exist
if [[ -z "${CONTAINER_ID}" ]]; then if [[ -z "${CONTAINER_ID}" ]]; then
docker create -v ${SUBSURFACE_ROOT}:/android/subsurface -w /android --name=${CONTAINER_NAME} subsurface/android-build-container:5.15.1 sleep infinity docker create -v ${SUBSURFACE_ROOT}:/android/subsurface --name=${CONTAINER_NAME} subsurface/android-build:5.15.1 sleep infinity
fi fi
docker start ${CONTAINER_NAME} docker start ${CONTAINER_NAME}
@ -29,8 +29,6 @@ if [[ -n "${CONTAINER_ID}" ]]; then
BUILD_PARAMETERS="-quick" BUILD_PARAMETERS="-quick"
else else
# Prepare the image for first use # Prepare the image for first use
docker exec -t ${CONTAINER_NAME} rm /android/5.15.1/android/lib/cmake/Qt5Test/Qt5TestConfig.cmake
docker exec -t ${CONTAINER_NAME} apt-get install --reinstall cpp-7 gcc-7-base libgcc-7-dev libcc1-0 gcc-7
# Set the git id # Set the git id
docker exec -t ${CONTAINER_NAME} git config --global user.name "${GIT_NAME}" docker exec -t ${CONTAINER_NAME} git config --global user.name "${GIT_NAME}"
@ -38,10 +36,7 @@ else
fi fi
# Build. Do not rebuild the dependencies if this is not the first build # Build. Do not rebuild the dependencies if this is not the first build
docker exec -t ${CONTAINER_NAME} /bin/bash -x ./subsurface/packaging/android/qmake-build.sh ${BUILD_PARAMETERS} docker exec -e OUTPUT_DIR="/android/subsurface/android-debug" -t ${CONTAINER_NAME} /bin/bash -x ./subsurface/packaging/android/qmake-build.sh ${BUILD_PARAMETERS}
# Copy the output files into the 'android-debug' directory in the source directory
docker cp ${CONTAINER_NAME}:/android/subsurface-mobile-build/android-build/build/outputs/apk/debug/. ${SUBSURFACE_ROOT}/android-debug/
# Stop the container # Stop the container
docker stop ${CONTAINER_NAME} docker stop ${CONTAINER_NAME}

View file

@ -1,43 +1,33 @@
From ubuntu:18.04 FROM subsurface/android-build-container:5.15.1 as base
FROM ubuntu:22.04 as build
RUN apt-get update && \ RUN apt-get update && \
apt-get upgrade -y && \ apt-get upgrade -y && \
apt-get install -y \ apt-get install -y \
autoconf \
automake \
cmake \
git \
libtool-bin \
make \
wget \
unzip \ unzip \
python \ git \
python3-pip \ cmake \
bzip2 \ autoconf \
pkg-config \ libtool-bin \
libx11-xcb1 \
libgl1-mesa-glx \
libglib2.0-0 \
openjdk-8-jdk \ openjdk-8-jdk \
curl \ wget
coreutils \
p7zip-full WORKDIR /android
COPY --from=base /android/5.15.1 5.15.1
# create our working directory and place the local copies of the Qt
# install, NDK and SDK there, plus the three files from the Subsurface # install, NDK and SDK there, plus the three files from the Subsurface
# sources that we need to get the prep routines to run # sources that we need to get the prep routines to run
RUN mkdir -p /android RUN wget https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip && \
ADD commandlinetools-linux-*.zip /android/ unzip commandlinetools-linux-*.zip
RUN cd /android && unzip commandlinetools-linux-*.zip ADD android-build-setup.sh variables.sh .
ADD android-build-setup.sh variables.sh /android/
# run the build setup # run the build setup
RUN ls -l /android RUN bash -x android-build-setup.sh
RUN cd /android && bash -x /android/android-build-setup.sh
# clean up the files that we don't need to keep the container smaller # clean up the files that we don't need to keep the container smaller
RUN cd /android && \ RUN rm -rf \
rm -rf \
5*/android/lib/*x86* \ 5*/android/lib/*x86* \
5*/android/doc \ 5*/android/doc \
5*/android/include/QtHelp \ 5*/android/include/QtHelp \
@ -48,6 +38,7 @@ RUN cd /android && \
5*/android/include/QtTest \ 5*/android/include/QtTest \
5*/android/include/QtXml \ 5*/android/include/QtXml \
5*/android/plugins/geoservices/libqtgeoservices_mapboxgl.so \ 5*/android/plugins/geoservices/libqtgeoservices_mapboxgl.so \
5*/android/lib/cmake/Qt5Test/Qt5TestConfig.cmake \
commandlinetools-linux-*.zip \ commandlinetools-linux-*.zip \
$( find platforms -name arch-mips -o -name arch-x86 ) \ $( find platforms -name arch-mips -o -name arch-x86 ) \
toolchains/x86-* android-ndk*/toolchains/llvm/prebuilt/x86-* \ toolchains/x86-* android-ndk*/toolchains/llvm/prebuilt/x86-* \
@ -69,10 +60,50 @@ RUN cd /android && \
emulator \ emulator \
platform-tools-2 \ platform-tools-2 \
variables.sh \ variables.sh \
android-build-setup.sh android-build-setup.sh \
/usr/lib/gcc && \ /usr/lib/gcc
ls -l && \
du -sh * FROM ubuntu:22.04
RUN apt-get clean
#RUN cd /android/android-ndk-r18b/toolchains && ln -s x86_64-4.9 x86-64-4.9 # Repeat exactly the same step as in the 'build' image above, so it can be reused
RUN touch /android/finished-"`date`" RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y \
unzip \
git \
cmake \
autoconf \
libtool-bin \
openjdk-8-jdk \
wget
RUN apt-get install -y \
autoconf \
automake \
cmake \
git \
make \
wget \
zip \
unzip \
python3 \
python3-pip \
bzip2 \
pkg-config \
libx11-xcb1 \
libgl1-mesa-glx \
libglib2.0-0 \
openjdk-8-jdk \
curl \
coreutils \
p7zip-full && \
apt-get clean
WORKDIR /android
COPY --from=build /android/ .
RUN git config --global --add safe.directory /android/subsurface && \
git config --global --add safe.directory /android/subsurface/libdivecomputer
RUN touch finished-"`date`"

12
scripts/docker/android-build-container/setup-docker.sh Normal file → Executable file
View file

@ -5,16 +5,16 @@
# Google makes it intentionally very hard to download the command line tools # Google makes it intentionally very hard to download the command line tools
# the URL is constantly changing and the website requires you to click through # the URL is constantly changing and the website requires you to click through
# a license. # a license.
#
# Today this URL works: # Today this URL works:
if [ ! -f commandlinetools-linux-6858069_latest.zip ] ; then # https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip
wget https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip #
fi # If this fails, go to https://developer.android.com/studio#cmdline-tools and
# if this fails, go to https://developer.android.com/studio#cmdline-tools and click through # click through for yourself, and then update the URL in the Dockerfile
# for yourself...
# copy the dependency script into this folder # copy the dependency script into this folder
cp ../../../packaging/android/android-build-setup.sh . cp ../../../packaging/android/android-build-setup.sh .
cp ../../../packaging/android/variables.sh . cp ../../../packaging/android/variables.sh .
# create the container (this takes a while) # create the container (this takes a while)
sudo docker build -t android-builder --squash . docker build -t android-build .