Skip to content

Commit

Permalink
Combine dockerfiles into android-dev for Github codespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
takenagain committed May 31, 2024
1 parent 7cdbc98 commit 1753e65
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 23 deletions.
2 changes: 0 additions & 2 deletions .docker/android-apk-build.dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM komodo/kdf-android:latest as build

ENV FLUTTER_HOME "/home/komodo/.flutter-sdk"

RUN cd /app && \
rustup default nightly-2022-10-29 && \
rustup target add aarch64-linux-android && \
Expand Down
175 changes: 161 additions & 14 deletions .docker/android-dev.dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,173 @@
FROM ghcr.io/cirruslabs/android-sdk:34 as final
FROM docker.io/ubuntu:22.04

LABEL Author "Onur Özkan <onur@komodoplatform.com>"
ARG KDF_BRANCH=main
ENV KDF_DIR=/kdf

ENV FLUTTER_VERSION="2.8.1"
ENV FLUTTER_HOME "/home/komodo/.flutter-sdk"
ENV USER="komodo"
ENV USER_ID=1000
ENV PATH $PATH:$FLUTTER_HOME/bin
ENV AR=/usr/bin/llvm-ar-16
ENV CC=/usr/bin/clang-16
ENV PATH="$HOME/.cargo/bin:$PATH"
ENV PATH=$PATH:/android-ndk/bin
ENV ANDROID_HOME=/opt/android-sdk-linux \
LANG=en_US.UTF-8 \
LC_ALL=en_US.UTF-8 \
LANGUAGE=en_US:en

ENV ANDROID_SDK_ROOT=$ANDROID_HOME \
PATH=${PATH}:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/emulator

# comes from https://developer.android.com/studio/#command-tools
ENV ANDROID_SDK_TOOLS_VERSION 11076708

# https://developer.android.com/studio/releases/build-tools
ENV ANDROID_PLATFORM_VERSION 34
ENV ANDROID_BUILD_TOOLS_VERSION 34.0.0

# https://developer.android.com/ndk/downloads
ENV ANDROID_NDK_VERSION 26.3.11579264
# Libz is distributed in the android ndk, but for some unknown reason it is not
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
ENV CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=x86_64-linux-android-clang \
CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER="qemu-x86_64 -cpu qemu64,+mmx,+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt" \
CC_x86_64_linux_android=x86_64-linux-android-clang \
CXX_x86_64_linux_android=x86_64-linux-android-clang++ \
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi21-clang \
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_RUNNER=qemu-arm \
CC_armv7_linux_androideabi=armv7a-linux-androideabi21-clang \
CXX_armv7_linux_androideabi=armv7a-linux-androideabi21-clang++ \
CC_aarch64_linux_android=aarch64-linux-android21-clang \
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android21-clang \
CC_armv7_linux_androideabi=armv7a-linux-androideabi21-clang \
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi21-clang \
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
OPENSSL_STATIC=1 \
OPENSSL_DIR=/openssl \
OPENSSL_INCLUDE_DIR=/openssl/include \
OPENSSL_LIB_DIR=/openssl/lib \
RUST_TEST_THREADS=1 \
HOME=/tmp/ \
TMPDIR=/tmp/ \
ANDROID_DATA=/ \
ANDROID_DNS_MODE=local \
ANDROID_ROOT=/system

RUN apt update && apt install -y python3 python3-pip python3-venv && \
python3 -m venv /home/komodo/.venv && \
useradd -u 1001 -m $USER && \
usermod -aG sudo $USER && \
echo "$USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
chown -R $USER:$USER /home/$USER && \
chown -R $USER:$USER /opt/android-sdk-linux && \
chmod -R u+rw,g+rw /opt/android-sdk-linux
RUN apt update && apt install -y sudo && \
useradd -u $USER_ID -m $USER && \
usermod -aG sudo $USER && \
echo "$USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

USER $USER

# Download and extract Flutter SDK
RUN mkdir -p /home/komodo/workspace \
&& chown -R $USER:$USER /home/komodo/workspace \
&& git clone https://github.com/flutter/flutter.git ${FLUTTER_HOME} \
&& cd ${FLUTTER_HOME} \
RUN sudo apt-get update -y && \
sudo apt-get install -y --no-install-recommends \
ca-certificates \
build-essential \
libssl-dev \
cmake \
llvm-dev \
libclang-dev \
lld \
gcc \
libc6-dev \
jq \
make \
pkg-config \
git \
automake \
libtool \
m4 \
autoconf \
make \
file \
curl \
wget \
gnupg \
software-properties-common \
lsb-release \
libudev-dev \
zip unzip \
binutils && \
sudo apt-get clean

RUN sudo ln -s /usr/bin/python3 /bin/python &&\
sudo curl --output llvm.sh https://apt.llvm.org/llvm.sh && \
sudo chmod +x llvm.sh && \
sudo ./llvm.sh 16 && \
sudo rm ./llvm.sh && \
sudo ln -s /usr/bin/clang-16 /usr/bin/clang && \
PROTOC_ZIP=protoc-25.3-linux-x86_64.zip && \
sudo curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v25.3/$PROTOC_ZIP && \
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc && \
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*' && \
sudo rm -f $PROTOC_ZIP && \
sudo mkdir $KDF_DIR && \
sudo chown -R $USER:$USER $KDF_DIR

RUN PATH="$HOME/.cargo/bin:$PATH" && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
export PATH="$HOME/.cargo/bin:$PATH" && \
sudo chown -R $USER:$USER $HOME/.cargo && \
rustup toolchain install nightly-2022-10-29 --no-self-update --profile=minimal &&\
rustup default nightly-2022-10-29 && \
rustup target add aarch64-linux-android && \
rustup target add armv7-linux-androideabi && \
sudo apt install -y python3 python3-pip git curl nodejs python3-venv sudo && \
git clone https://github.com/KomodoPlatform/komodo-defi-framework.git $KDF_DIR && \
cd $KDF_DIR && \
git fetch --all && \
git checkout origin/$KDF_BRANCH && \
if [ "$(uname -m)" = "x86_64" ]; then \
bash ./scripts/ci/android-ndk.sh x86 23; \
elif [ "$(uname -m)" = "aarch64" ]; then \
bash ./scripts/ci/android-ndk.sh arm64 23; \
else \
echo "Unsupported architecture"; \
exit 1; \
fi && \
cd $KDF_DIR && \
export PATH="$HOME/.cargo/bin:$PATH" && \
export PATH=$PATH:/android-ndk/bin && \
CC_aarch64_linux_android=aarch64-linux-android21-clang CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android21-clang cargo rustc --target=aarch64-linux-android --lib --release --crate-type=staticlib --package mm2_bin_lib && \
CC_armv7_linux_androideabi=armv7a-linux-androideabi21-clang CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=armv7a-linux-androideabi21-clang cargo rustc --target=armv7-linux-androideabi --lib --release --crate-type=staticlib --package mm2_bin_lib && \
mv target/aarch64-linux-android/release/libmm2lib.a target/aarch64-linux-android/release/libmm2.a &&\
mv target/armv7-linux-androideabi/release/libmm2lib.a target/armv7-linux-androideabi/release/libmm2.a

RUN set -e -o xtrace \
&& cd /opt \
&& sudo chown -R $USER:$USER /opt \
&& sudo apt-get update \
&& sudo apt-get install -y jq \
openjdk-17-jdk \
wget zip unzip git openssh-client curl bc software-properties-common build-essential ruby-full ruby-bundler libstdc++6 libpulse0 libglu1-mesa locales lcov libsqlite3-dev --no-install-recommends \
# for x86 emulators
libxtst6 libnss3-dev libnspr4 libxss1 libatk-bridge2.0-0 libgtk-3-0 libgdk-pixbuf2.0-0 \
&& sudo rm -rf /var/lib/apt/lists/* \
&& sudo sh -c 'echo "en_US.UTF-8 UTF-8" > /etc/locale.gen' \
&& sudo locale-gen \
&& sudo update-locale LANG=en_US.UTF-8 \
&& wget -q https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS_VERSION}_latest.zip -O android-sdk-tools.zip \
&& mkdir -p ${ANDROID_HOME}/cmdline-tools/ \
&& unzip -q android-sdk-tools.zip -d ${ANDROID_HOME}/cmdline-tools/ \
&& mv ${ANDROID_HOME}/cmdline-tools/cmdline-tools ${ANDROID_HOME}/cmdline-tools/latest \
&& sudo chown -R $USER:$USER $ANDROID_HOME \
&& rm android-sdk-tools.zip \
&& yes | sdkmanager --licenses \
&& sdkmanager platform-tools \
&& git config --global user.email "hello@komodoplatform.com" \
&& git config --global user.name "Komodo Platform" \
&& yes | sdkmanager \
"platforms;android-$ANDROID_PLATFORM_VERSION" \
"build-tools;$ANDROID_BUILD_TOOLS_VERSION" \
&& yes | sdkmanager "ndk;$ANDROID_NDK_VERSION"


RUN git clone https://github.com/flutter/flutter.git ${FLUTTER_HOME} \
&& cd ${FLUTTER_HOME} \
&& git fetch \
&& git checkout tags/2.8.1 \
&& flutter config --no-analytics \
Expand Down
1 change: 0 additions & 1 deletion .docker/android-sdk.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ RUN set -o xtrace \
&& yes | sdkmanager --licenses \
&& wget -O /usr/bin/android-wait-for-emulator https://raw.githubusercontent.com/travis-ci/travis-cookbooks/master/community-cookbooks/android-sdk/files/default/android-wait-for-emulator \
&& chmod +x /usr/bin/android-wait-for-emulator \
&& touch /root/.android/repositories.cfg \
&& sdkmanager platform-tools \
&& mkdir -p /root/.android \
&& touch /root/.android/repositories.cfg \
Expand Down
17 changes: 11 additions & 6 deletions .docker/dev-setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
chmod u+rw,g+r /home/komodo/workspace
mkdir -p android/app/src/main/cpp/libs/armeabi-v7a
mkdir -p android/app/src/main/cpp/libs/arm64-v8a
/home/komodo/.venv/bin/pip install -r .docker/requirements.txt
/home/komodo/.venv/bin/python .docker/update_api.py
flutter pub get
sudo chmod -R u+rwx,g+rwx /home/komodo/workspace
sudo chown -R /home/komodo/workspace
flutter pub get

curl -o assets/coins.json https://raw.githubusercontent.com/KomodoPlatform/coins/master/coins
curl -o assets/coins_config.json https://raw.githubusercontent.com/KomodoPlatform/coins/master/utils/coins_config.json
mkdir -p android/app/src/main/cpp/libs/armeabi-v7a
mkdir -p android/app/src/main/cpp/libs/arm64-v8a

cp /kdf/target/aarch64-linux-android/release/libmm2.a android/app/src/main/cpp/libs/arm64-v8a
cp /kdf/target/armv7-linux-androideabi/release/libmm2.a android/app/src/main/cpp/libs/armeabi-v7a

0 comments on commit 1753e65

Please sign in to comment.