Skip to content

Instantly share code, notes, and snippets.

@marylly
Last active May 17, 2018 01:50
Show Gist options
  • Save marylly/b41aae223fc39f687882c7b8e39cd20a to your computer and use it in GitHub Desktop.
Save marylly/b41aae223fc39f687882c7b8e39cd20a to your computer and use it in GitHub Desktop.
Build Android with Ionic Framework
FROM node:10-alpine
RUN apk update && apk add --no-cache wget nginx musl git bash unzip libstdc++ make g++ gcc libgcc python2 curl ca-certificates tar gzip
RUN npm i ionic cordova -g
ENV ANDROID_HOME /opt/android-sdk-linux
ENV SDK_TOOLS_VERSION 25.2.5
ENV API_LEVELS android-23
ENV BUILD_TOOLS_VERSIONS build-tools_r27.0.0
ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools
ENV GRADLE_VERSION 2.13
ENV PKG_URL "https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64"
ENV JAVA_VERSION_MAJOR 8
ENV JAVA_VERSION_MINOR 171
ENV JAVA_VERSION_BUILD 11
ENV JAVA_BASE /usr/local/java
ENV JAVA_HOME ${JAVA_BASE}/jdk
ENV JAVA_PKG jdk
ENV PATH ${PATH}:${JAVA_HOME}/bin
ENV LANG C.UTF-8
RUN echo http://download.oracle.com/otn-pub/java/jdk/${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-b${JAVA_VERSION_BUILD}/512cd62ec5174c3487ac17c61aaa89e8/${JAVA_PKG}-${JAVA_VERSION_MAJOR}u${JAVA_VERSION_MINOR}-linux-x64.tar.gz?AuthParam=1526518885_a68084d725e0aa561a728a8e8fe1f1e9
# Use workarounds from https://github.com/gliderlabs/docker-alpine/issues/11:
# 1. Install glibc
# 2. hotfix /etc/nsswitch.conf, which is apperently required by glibc and is not used in Alpine Linux
RUN apk --no-cache add \
bash \
ca-certificates \
curl &&\
# Install Java
mkdir -p ${JAVA_BASE} &&\
curl -sSL --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/jdk-8u171-linux-x64.tar.gz?AuthParam=1526520255_7c558437e000904c709f28baa518316b | tar zxf - -C $JAVA_BASE &&\
ln -s $JAVA_BASE/jdk1.8.0_171 ${JAVA_HOME} &&\
echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf &&\
# Cleanup
rm -rf /tmp/* \
${JAVA_HOME}/*src.zip \
${JAVA_HOME}/lib/missioncontrol \
${JAVA_HOME}/lib/visualvm \
${JAVA_HOME}/lib/*javafx* \
${JAVA_HOME}/jre/lib/plugin.jar \
${JAVA_HOME}/jre/lib/ext/jfxrt.jar \
${JAVA_HOME}/jre/bin/javaws \
${JAVA_HOME}/jre/lib/javaws.jar \
${JAVA_HOME}/jre/lib/desktop \
${JAVA_HOME}/jre/plugin \
${JAVA_HOME}/jre/lib/deploy* \
${JAVA_HOME}/jre/lib/*javafx* \
${JAVA_HOME}/jre/lib/*jfx* \
${JAVA_HOME}/jre/lib/amd64/libdecora_sse.so \
${JAVA_HOME}/jre/lib/amd64/libprism_*.so \
${JAVA_HOME}/jre/lib/amd64/libfxplugins.so \
${JAVA_HOME}/jre/lib/amd64/libglass.so \
${JAVA_HOME}/jre/lib/amd64/libgstreamer-lite.so \
${JAVA_HOME}/jre/lib/amd64/libjavafx*.so \
${JAVA_HOME}/jre/lib/amd64/libjfx*.so
RUN mkdir -p /opt/android-sdk-linux && cd /opt \
&& wget -q http://dl.google.com/android/repository/tools_r${SDK_TOOLS_VERSION}-linux.zip -O android-sdk-tools.zip \
&& unzip -q android-sdk-tools.zip -d ${ANDROID_HOME} \
&& rm -f android-sdk-tools.zip \
&& echo y | android update sdk --no-ui -a --filter \
tools,platform-tools,${API_LEVELS},${BUILD_TOOLS_VERSIONS} --no-https
# install libsass
RUN git clone https://github.com/sass/sassc && cd sassc && \
git clone https://github.com/sass/libsass && \
SASS_LIBSASS_PATH=/sassc/libsass make && \
mv bin/sassc /usr/bin/sassc && \
cd ../ && rm -rf /sassc
# created node-sass binary
ENV SASS_BINARY_PATH=/usr/lib/node_modules/node-sass/build/Release/binding.node
RUN git clone --recursive https://github.com/sass/node-sass.git && \
cd node-sass && \
git submodule update --init --recursive && \
npm install && \
node scripts/build -f && \
cd ../ && rm -rf node-sass
# add binary path of node-sass to .npmrc
RUN touch $HOME/.npmrc && echo "sass_binary_cache=${SASS_BINARY_PATH}" >> $HOME/.npmrc
ENV JAVA_HOME=/usr/lib/jvm/default-jvm
RUN apk add --no-cache openjdk7 && \
ln -sf "${JAVA_HOME}/bin/"* "/usr/bin/"
# Install Gradle
RUN wget https://services.gradle.org/distributions/gradle-"$GRADLE_VERSION"-bin.zip && \
mkdir /opt/gradle && \
unzip -d gradle gradle-"$GRADLE_VERSION"-bin.zip && \
mv gradle/gradle-"$GRADLE_VERSION" . && \
mv gradle-"$GRADLE_VERSION" /opt/gradle && \
ls -la /opt/gradle && \
export PATH=$PATH:/opt/gradle/bin && \
gradle -v \
rm -rf gradle-"$GRADLE_VERSION"-bin.zip
RUN mkdir app-mobile
WORKDIR app-mobile
COPY . .
WORKDIR AppExample
RUN npm install
RUN ionic cordova platform add android
RUN ionic cordova build android
COPY /tmp/app-mobile/AppExample/platforms/android/app/build/outputs/apk/debug/app-debug.apk /usr/share/nginx/html
RUN rm -rf /etc/nginx/conf.d/* && rm -rf /etc/nginx/sites-available/*
COPY nginx-custom.conf /etc/nginx/conf.d/
CMD ["nginx", "-g", "daemon off;"]
EXPOSE 5000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment