8000 Add Dockerfile with host py3 in virtualenv · sinazeyni/python-for-android@0c936d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c936d1

Browse files
committed
Add Dockerfile with host py3 in virtualenv
1 parent abe9962 commit 0c936d1

File tree

3 files changed

+134
-2
lines changed

3 files changed

+134
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ before_script:
3131
- tox
3232

3333
script:
34-
- docker build --tag=p4a .
34+
- docker build --tag=p4a --file Dockerfile.py2 .
3535
- docker run p4a /bin/sh -c "$COMMAND"

Dockerfile renamed to Dockerfile.py2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# - python-for-android dependencies
44
#
55
# Build with:
6-
# docker build --tag=p4a .
6+
# docker build --tag=p4a --file Dockerfile.py2 .
77
#
88
# Run with:
99
# docker run -it --rm p4a /bin/sh -c '. venv/bin/activate && p4a apk --help'

Dockerfile.py3

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Dockerfile with:
2+
# - Android build environment
3+
# - python-for-android dependencies
4+
#
5+
# Build with:
6+
# docker build --tag=p4apy3 .
7+
#
8+
# Run with:
9+
# docker run -it --rm p4apy3 /bin/sh -c '. venv/bin/activate && p4a apk --help'
10+
#
11+
# Or for interactive shell:
12+
# docker run -it --rm p4apy3
13+
#
14+
# Note:
15+
# Use 'docker run' without '--rm' flag for keeping the container and use
16+
# 'docker commit <container hash> <new image>' to extend the original image
17+
18+
FROM ubuntu:18.04
19+
20+
ENV ANDROID_HOME="/opt/android"
21+
22+
RUN apt -y update -qq \
23+
&& apt -y install -qq --no-install-recommends curl unzip \
24+
&& apt -y autoremove \
25+
&& apt -y clean
26+
27+
28+
ENV ANDROID_NDK_HOME="${ANDROID_HOME}/android-ndk"
29+
ENV ANDROID_NDK_VERSION="16b"
30+
ENV ANDROID_NDK_HOME_V="${ANDROID_NDK_HOME}-r${ANDROID_NDK_VERSION}"
31+
32+
# get the latest version from https://developer.android.com/ndk/downloads/index.html
33+
ENV ANDROID_NDK_ARCHIVE="android-ndk-r${ANDROID_NDK_VERSION}-linux-x86_64.zip"
34+
ENV ANDROID_NDK_DL_URL="https://dl.google.com/android/repository/${ANDROID_NDK_ARCHIVE}"
35+
36+
# download and install Android NDK
37+
RUN curl --location --progress-bar --insecure \
38+
"${ANDROID_NDK_DL_URL}" \
39+
--output "${ANDROID_NDK_ARCHIVE}" \
40+
&& mkdir --parents "${ANDROID_NDK_HOME_V}" \
41+
&& unzip -q "${ANDROID_NDK_ARCHIVE}" -d "${ANDROID_HOME}" \
42+
&& ln -sfn "${ANDROID_NDK_HOME_V}" "${ANDROID_NDK_HOME}" \
43+
&& rm -rf "${ANDROID_NDK_ARCHIVE}"
44+
45+
46+
ENV ANDROID_SDK_HOME="${ANDROID_HOME}/android-sdk"
47+
48+
# get the latest version from https://developer.android.com/studio/index.html
49+
ENV ANDROID_SDK_TOOLS_VERSION="3859397"
50+
ENV ANDROID_SDK_TOOLS_ARCHIVE="sdk-tools-linux-${ANDROID_SDK_TOOLS_VERSION}.zip"
51+
ENV ANDROID_SDK_TOOLS_DL_URL="https://dl.google.com/android/repository/${ANDROID_SDK_TOOLS_ARCHIVE}"
52+
53+
# download and install Android SDK
54+
RUN curl --location --progress-bar --insecure \
55+
"${ANDROID_SDK_TOOLS_DL_URL}" \
56+
--output "${ANDROID_SDK_TOOLS_ARCHIVE}" \
57+
&& mkdir --parents "${ANDROID_SDK_HOME}" \
58+
&& unzip -q "${ANDROID_SDK_TOOLS_ARCHIVE}" -d "${ANDROID_SDK_HOME}" \
59+
&& rm -rf "${ANDROID_SDK_TOOLS_ARCHIVE}"
60+
61+
# update Android SDK, install Android API, Build Tools...
62+
RUN mkdir --parents "${ANDROID_SDK_HOME}/.android/" \
63+
&& echo '### User Sources for Android SDK Manager' \
64+
> "${ANDROID_SDK_HOME}/.android/repositories.cfg"
65+
66+
# accept Android licenses (JDK necessary!)
67+
RUN apt -y update -qq \
68+
&& apt -y install -qq --no-install-recommends openjdk-8-jdk \
69+
&& apt -y autoremove \
70+
&& apt -y clean
71+
RUN yes | "${ANDROID_SDK_HOME}/tools/bin/sdkmanager" --licenses > /dev/null
72+
73+
# download platforms, API, build tools
74+
RUN "${ANDROID_SDK_HOME}/tools/bin/sdkmanager" "platforms;android-19" && \
75+
"${ANDROID_SDK_HOME}/tools/bin/sdkmanager" "platforms;android-27" && \
76+
"${ANDROID_SDK_HOME}/tools/bin/sdkmanager" "build-tools;26.0.2" && \
77+
chmod +x "${ANDROID_SDK_HOME}/tools/bin/avdmanager"
78+
79+
80+
ENV USER="user"
81+
ENV HOME_DIR="/home/${USER}"
82+
ENV WORK_DIR="${HOME_DIR}" \
83+
PATH="${HOME_DIR}/.local/bin:${PATH}"
84+
85+
# install system dependencies
86+
RUN apt -y update -qq \
87+
&& apt -y install -qq --no-install-recommends \
88+
python3 virtualenv python3-pip wget lbzip2 patch sudo \
89+
&& apt -y autoremove \
90+
&& apt -y clean
91+
92+
# build dependencies
93+
# https://buildozer.readthedocs.io/en/latest/installation.html#android-on-ubuntu-16-04-64bit
94+
RUN dpkg --add-architecture i386 \
95+
&& apt -y update -qq \
96+
&& apt -y install -qq --no-install-recommends \
97+
build-essential ccache git python3 python3-dev \
98+
libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 \
99+
libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 \
100+
zip zlib1g-dev zlib1g:i386 \
101+
&& apt -y autoremove \
102+
&& apt -y clean
103+
104+
# specific recipes dependencies (e.g. libffi requires autoreconf binary)
105+
RUN apt -y update -qq \
106+
&& apt -y install -qq --no-install-recommends \
107+
autoconf automake cmake gettext libltdl-dev libtool pkg-config \
108+
&& apt -y autoremove \
109+
&& apt -y clean
110+
111+
112+
# prepare non root env
113+
RUN useradd --create-home --shell /bin/bash ${USER}
114+
115+
# with sudo access and no password
116+
RUN usermod -append --groups sudo ${USER}
117+
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
118+
119+
120+
RUN pip3 install --upgrade cython==0.28.6
121+
122+
WORKDIR ${WORK_DIR}
123+
COPY . ${WORK_DIR}
124+
125+
# user needs ownership/write access to these directories
126+
RUN chown --recursive ${USER} ${WORK_DIR} ${ANDROID_SDK_HOME}
127+
USER ${USER}
128+
129+
# install python-for-android from current branch
130+
RUN virtualenv --python=python3 venv \
131+
&& . venv/bin/activate \
132+
&& pip3 install -e .

0 commit comments

Comments
 (0)
0