Last active
April 30, 2020 16:10
-
-
Save har5hit/6fcf2f0870fa97bcae130064457b6ea2 to your computer and use it in GitHub Desktop.
DockerFile with Jenkins, Android, Flutter, Gradle, Docker, Docker Compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------Dockerfile----------------- | |
# Setting the base image of which docker image is being created | |
FROM jenkins/jenkins:lts | |
# Switching to root user to install dependencies and flutter | |
USER root | |
#Flutter | |
#Installing the different dependencies required for Flutter, installing flutter from beta channel from github and giving permissions to jenkins user to the folder | |
RUN apt-get update && apt-get install -y --force-yes git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback lib32stdc++6 python3 \ | |
&& apt-get clean \ | |
&& git clone -b beta https://github.com/flutter/flutter.git /usr/local/flutter \ | |
&& chown -R jenkins:jenkins /usr/local/flutter | |
ENV ANDROID_SDK_ZIP commandlinetools-linux-6200805_latest.zip | |
ENV ANDROID_SDK_ZIP_URL https://dl.google.com/android/repository/$ANDROID_SDK_ZIP | |
ENV ANDROID_HOME /opt/android-sdk-linux | |
ENV GRADLE_ZIP gradle-5.6.4-bin.zip | |
ENV GRADLE_ZIP_URL https://services.gradle.org/distributions/$GRADLE_ZIP | |
ENV PATH $PATH:$ANDROID_HOME/tools/bin | |
ENV PATH $PATH:$ANDROID_HOME/platform-tools | |
ENV PATH $PATH:/opt/gradle-5.6.4/bin | |
## Install Docker requirements | |
RUN dpkg --add-architecture i386 | |
RUN rm -rf /var/lib/apt/list/* && apt-get update && apt-get install ca-certificates curl gnupg2 software-properties-common git unzip file apt-utils lxc apt-transport-https -y | |
## Install Android SDK into Image | |
ADD $GRADLE_ZIP_URL /opt/ | |
RUN unzip /opt/$GRADLE_ZIP -d /opt/ && rm /opt/$GRADLE_ZIP | |
ADD $ANDROID_SDK_ZIP_URL /opt/ | |
RUN unzip -q /opt/$ANDROID_SDK_ZIP -d $ANDROID_HOME && rm /opt/$ANDROID_SDK_ZIP | |
RUN echo y | sdkmanager --sdk_root=${ANDROID_HOME} "build-tools;29.0.2" | |
RUN echo y | sdkmanager --sdk_root=${ANDROID_HOME} "platforms;android-29" | |
RUN echo y |sdkmanager --sdk_root=${ANDROID_HOME} "extras;android;m2repository" | |
RUN chown -R jenkins $ANDROID_HOME | |
RUN apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 zlib1g:i386 -y --no-install-recommends | |
RUN apt-get clean | |
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | |
## Install Docker-ce into Image | |
RUN curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; | |
RUN apt-key add /tmp/dkey | |
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable" | |
RUN apt-get update && apt-get install docker-ce -y --no-install-recommends | |
RUN usermod -aG docker jenkins | |
#Test | |
RUN docker -v | |
#Docker Compose | |
RUN curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
RUN chmod +x /usr/local/bin/docker-compose | |
#Test | |
RUN docker-compose -v | |
## Install Jenkins plugin | |
USER jenkins | |
RUN /usr/local/bin/install-plugins.sh git gradle ws-cleanup locale | |
# Running flutter doctor to check if flutter was installed correctly | |
RUN /usr/local/flutter/bin/flutter doctor -v \ | |
&& rm -rfv /flutter/bin/cache/artifacts/gradle_wrapper | |
# Setting flutter and dart-sdk to PATH so they are accessible from terminal | |
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}" | |
------------docker-compose.yml----------------- | |
version: '3.0' # specify docker-compose version | |
services: | |
jenkins: # name of the service | |
build: . # directory of the Dockerfile | |
ports: | |
- "8080:8080" | |
- "127.0.0.1:50000:50000" | |
restart: always | |
volumes: | |
- ../jenkins_local_home:/var/jenkins_home | |
- /var/run/docker.sock:/var/run/docker.sock | |
-------------------------- | |
If issues with flutter build apk, | |
- Go to docker container | |
- RUN flutter doctor | |
If issues in licenses, | |
- RUN sdkmanager --sdk_root=${ANDROID_HOME} "tools" | |
- flutter doctor --android-licenses | |
- flutter doctor | |
---- Gradle No Daemon----- | |
- Go to jenkins_home/.gradle/ | |
- echo "org.gradle.daemon=false" >> gradle.properties | |
---- If docker not accessible in container---- | |
In host machine, | |
RUN newgrp docker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment