Notes

Creating a Docker image for React Native, Android and Fastlane

Edit on GitHub

React Native & Expo
2 minutes

Why? So i could use it inside my CD (Bitbucket Pipelines) and save on build minutes.

 1# Dockerfile
 2FROM ubuntu:20.04
 3
 4LABEL Description="This image provides a base Android development environment for React Native, and may be used to run tests."
 5
 6ENV DEBIAN_FRONTEND=noninteractive
 7
 8# set default build arguments
 9ARG SDK_VERSION=commandlinetools-linux-6609375_latest.zip
10ARG ANDROID_BUILD_VERSION=30
11ARG ANDROID_TOOLS_VERSION=30.0.3
12ARG BUCK_VERSION=2020.10.21.01
13ARG NDK_VERSION=20.1.5948944
14ARG NODE_VERSION=14.x
15ARG WATCHMAN_VERSION=4.9.0
16
17# set default environment variables
18ENV ADB_INSTALL_TIMEOUT=10
19ENV ANDROID_HOME=/opt/android
20ENV ANDROID_SDK_HOME=${ANDROID_HOME}
21ENV ANDROID_NDK=${ANDROID_HOME}/ndk/$NDK_VERSION
22ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
23
24ENV PATH=${ANDROID_NDK}:${ANDROID_HOME}/cmdline-tools/tools/bin:${ANDROID_HOME}/emulator:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:/opt/buck/bin/:${PATH}
25
26# Install system dependencies
27RUN apt update -qq && apt install -qq -y --no-install-recommends \
28        apt-transport-https \
29        curl \
30        file \
31        gcc \
32        git \
33        g++ \
34        gnupg2 \
35        libc++1-10 \
36        libgl1 \
37        libtcmalloc-minimal4 \
38        make \
39        openjdk-8-jdk-headless \
40        openssh-client \
41        python3 \
42        python3-distutils \
43        rsync \
44        ruby \
45        ruby-dev \
46        tzdata \
47        unzip \
48        sudo \
49        ninja-build \
50        zip \
51    && gem install bundler \
52    && rm -rf /var/lib/apt/lists/*;
53
54# Refresh keys to prevent invalid signature
55RUN apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com
56
57# install nodejs and yarn packages from nodesource and yarn apt sources
58RUN curl -sL https://deb.nodesource.com/setup_${NODE_VERSION} | bash - \
59    && echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
60    && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
61    && apt-get update -qq \
62    && apt-get install -qq -y --no-install-recommends nodejs yarn \
63    && rm -rf /var/lib/apt/lists/*
64
65# download and install buck using debian package
66RUN curl -sS -L https://github.com/facebook/buck/releases/download/v${BUCK_VERSION}/buck.${BUCK_VERSION}_all.deb -o /tmp/buck.deb \
67    && dpkg -i /tmp/buck.deb \
68    && rm /tmp/buck.deb
69
70# Full reference at https://dl.google.com/android/repository/repository2-1.xml
71# download and unpack android
72RUN curl -sS https://dl.google.com/android/repository/${SDK_VERSION} -o /tmp/sdk.zip \
73    && mkdir -p ${ANDROID_HOME}/cmdline-tools \
74    && unzip -q -d ${ANDROID_HOME}/cmdline-tools /tmp/sdk.zip \
75    && rm /tmp/sdk.zip \
76    && yes | sdkmanager --licenses \
77    && yes | sdkmanager "platform-tools" \
78        "emulator" \
79        "platforms;android-$ANDROID_BUILD_VERSION" \
80        "build-tools;$ANDROID_TOOLS_VERSION" \
81        "cmake;3.10.2.4988404" \
82        "system-images;android-21;google_apis;armeabi-v7a" \
83        "ndk;$NDK_VERSION" \
84    && rm -rf ${ANDROID_HOME}/.android

Related