Skip to content

Instantly share code, notes, and snippets.

@tanbro
Created March 27, 2025 02:06
Show Gist options
  • Save tanbro/1199c7085d68aa3d091903c3f1deb61c to your computer and use it in GitHub Desktop.
Save tanbro/1199c7085d68aa3d091903c3f1deb61c to your computer and use it in GitHub Desktop.
Dockerfile for chaquopy
# A Dockerfile for building Python(Chaquo) modules
FROM quay.io/pypa/manylinux_2_28_x86_64 AS base
ARG GRADLE_VERSION=8.13
ARG ANDROID_API_LEVEL=29
ARG ANDROID_BUILD_TOOLS_LEVEL=29.0.3
ARG ANDROID_NDK_VERSION=27.2.12479018
# See also:
# * https://medium.com/@simplatex/how-to-build-a-lightweight-docker-container-for-android-build-c52e4e68997e
# * https://github.com/chaquo/chaquopy/blob/master/server/pypi/README.md
# Java
RUN --mount=type=cache,target=/var/cache/dnf \
dnf install -y java-latest-openjdk && \
java -version
# Gradle
ENV GRADLE_HOME=/opt/gradle/gradle-$GRADLE_VERSION
COPY Gradle/gradle-${GRADLE_VERSION} ${GRADLE_HOME}
ENV PATH=$PATH:${GRADLE_HOME}/bin
RUN gradle --version
# Android Command line tools
# See Also: https://developer.android.com/tools#tools-sdk
ENV ANDROID_HOME=/opt/Android/Sdk
ENV ANDROID_NDK_HOME=${ANDROID_HOME}/ndk/${ANDROID_NDK_VERSION}
ENV PATH=$PATH:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/cmdline-tools/latest:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_NDK_HOME}
COPY cmdline-tools/ ${ANDROID_HOME}/cmdline-tools/latest
RUN --mount=type=cache,target=/root/.android/cache \
yes Y | sdkmanager --install \
"platform-tools" \
"build-tools;${ANDROID_BUILD_TOOLS_LEVEL}" \
"platforms;android-${ANDROID_API_LEVEL}" \
"ndk;${ANDROID_NDK_VERSION}"
# A lot of Python Package need Rust
# We install it by rustup, because ChaquoPy need it when compile rust based python package
ARG RUSTUP_UPDATE_ROOT=https://mirrors.aliyun.com/rustup/rustup
ENV RUSTUP_UPDATE_ROOT=$RUSTUP_UPDATE_ROOT
ARG RUSTUP_DIST_SERVER=https://mirrors.aliyun.com/rustup
ENV RUSTUP_DIST_SERVER=$RUSTUP_DIST_SERVER
ENV PATH="${PATH}:/root/.cargo/bin"
# Cargo config on Unix: $HOME/.cargo/config.toml
COPY .cargo/ /root/.cargo
# Download then install rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile minimal -y
RUN echo 'source $HOME/.cargo/env' >> $HOME/.bashrc
# Install rust toolchains
RUN rustup --version && \
rustup target install aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
ENV PATH=/root/.local/bin:${PATH}
# PIP index url
ARG PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple
ENV PIP_INDEX_URL=$PIP_INDEX_URL
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
# Install chaquopy/server/pypi requirements to default python3
COPY chaquopy/server/pypi/requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
python3 -m ensurepip && \
python3 -m pip install --user -r requirements.txt
# Other tools
RUN --mount=type=cache,target=/var/cache/dnf \
dnf install -y wget patch patchelf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment