Skip to content

Instantly share code, notes, and snippets.

@w3aran
Forked from rcbop/Dockerfile
Created July 26, 2018 02:35
Show Gist options
  • Save w3aran/017892905e6edf5d7f7b555ae3060561 to your computer and use it in GitHub Desktop.
Save w3aran/017892905e6edf5d7f7b555ae3060561 to your computer and use it in GitHub Desktop.
ionic dockerfile and jenkins file for CI
FROM node:8-alpine
LABEL MAINTAINER="[email protected]"
ARG NODEJS_VERSION="8"
ARG IONIC_VERSION="3.20.0"
ARG GRADLE_VERSION="3.2"
ARG ANDROID_SDK_VERSION="4333796"
ARG ANDROID_HOME="/opt/android-sdk"
ARG GRADLE_HOME="/opt/gradle"
ARG ANDROID_BUILD_TOOLS_VERSION="26.0.0"
ENV ANDROID_HOME="${ANDROID_HOME}" GRADLE_HOME="${GRADLE_HOME}"
RUN apk update \
&& apk add --no-cache --virtual .build-deps \
curl \
make \
gcc \
g++ \
python \
&& apk add --virtual .runtime-deps \
openjdk8 \
unzip \
git \
libstdc++ \
bash \
&& npm i npm@latest -g \
&& npm install -g cordova ionic@${IONIC_VERSION} \
&& cd /tmp \
&& echo 'Downloading Gradle' \
&& curl https://downloads.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip -o gradle.zip \
&& unzip gradle.zip \
&& mkdir -p ${GRADLE_HOME} \
&& mv gradle-${GRADLE_VERSION}/* ${GRADLE_HOME} \
&& rm -rf gradle.zip gradle-${GRADLE_VERSION} \
&& echo 'Downloading Android SDK' \
&& curl -fSLk https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_VERSION}.zip -o sdk-tools-linux-${ANDROID_SDK_VERSION}.zip \
&& unzip sdk-tools-linux-${ANDROID_SDK_VERSION}.zip \
&& mkdir -p ${ANDROID_HOME} \
&& mv tools ${ANDROID_HOME} \
&& (while sleep 3; do echo "y"; done) | $ANDROID_HOME/tools/bin/sdkmanager --licenses \
&& $ANDROID_HOME/tools/bin/sdkmanager "platform-tools" \
&& $ANDROID_HOME/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
&& rm -rf /var/cache/apk/* \
&& rm -rf /tmp/sdk-tools-linux-${ANDROID_SDK_VERSION}.zip \
&& apk del .build-deps \
&& mkdir /app
VOLUME [ "/opt/android-sdk" ]
VOLUME [ "/opt/gradle" ]
RUN deluser node && addgroup -g 1000 node && adduser -u 1000 -G node -s /bin/bash -D node
ENV PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$GRADLE_HOME
WORKDIR /app
// ##########################################################################
// # ionic cordova build jenkinsfile
// ##########################################################################
// # Mantainer [email protected]
// ##########################################################################
env.BRANCH="${params.BRANCH}"
env.GIT_CREDENTIALS_ID="my-git-credential-id"
env.GIT_REPO_URL="ssg://myrepository.git"
env.DOCKER_IMAGE_NAME="rcbop-cordova-android-builder"
env.DOCKER_IMAGE_TAG="latest"
env.BUILD_NODE="master"
timestampedNode(env.BUILD_NODE) {
stage('Checkout') {
gitCheckoutBranch("${env.BRANCH}")
// requires last changes plugin
lastChanges()
}
stage('Build base img') {
buildBaseImage()
}
stage('Npm install') {
env.dockerWrapper = prepareDockerWrapper()
installDependencies(env.dockerWrapper)
}
stage ('Cordova prepare'){
cordovaPrepareAndroid(env.dockerWrapper)
}
stage ('Ionic build'){
ionicBuild(env.dockerWrapper)
}
}
def gitCheckoutBranch(branch){
checkout([
$class: 'GitSCM',
branches: [[name: "*/${branch}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[ credentialsId: env.GIT_CREDENTIALS_ID, url: env.GIT_REPO_URL ]]
])
}
def prepareDockerWrapper(){
def gradleCacheDir = "gradle_caches"
echo ">> Creating docker wrapper"
def dockerWrapper = "docker run -v \$(pwd)/${gradleCacheDir}:/root/.gradle/caches -v \$(pwd):/app ${env.DOCKER_NAME}:${env.DOCKER_TAG}"
return dockerWrapper;
}
def installDependencies(dockerWrapper){
echo ">> Install dependencies"
sh "${dockerWrapper} bash -c 'npm i'"
}
def cordovaPrepareAndroid(dockerWrapper){
echo ">> Prepare Android"
sh "${dockerWrapper} bash -c 'cordova prepare android | xargs echo'"
}
def ionicBuild(dockerWrapper){
echo ">> Cordova build android"
sh "${dockerWrapper} bash -c 'ionic cordova build android'"
}
def timestampedNode(String label = "master", Closure body) {
node(label) {
def message = ""
try {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
wrap([$class: 'TimestamperBuildWrapper']) {
body.call();
}
}
} catch (err) {
wrap([$class: 'BuildUser']) {
echo "CURRENT ERROR: ${err}"
currentBuild.result = "FAILED"
}
} finally {
wrap([$class: 'BuildUser']) {
currentBuild.result = currentBuild.result ?: 'SUCCESS'
}
}
}
}
def buildBaseImage(){
sh "bash ./devops/build-dkr-img.sh"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment