Skip to content

orbismobile/docker-nginx-jenkins-android

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JENKINS BEHIND NGINX REVERSE PROXY WITH DOCKER

POWERED BY ORBIS MOBILE TEAM

icon

SUMMARY

This Docker Project uses nginx and jenkins docker official images. You will be able to use nginx as a reverse proxy server to access jenkins automation server.

Note: All server configurations in nginx are made to work on a local environment.

THE FINAL CONTINUOUS INTEGRATION FLOW

If you want to implement the complete Continuous Integration Flow for your development process, so take a look at our Medium Post.

icon

PREREQUISITIES

  1. Install Docker and Docker Compose.
  2. At top level project run docker-compose up command from terminal.
  3. Go to terminal and run:
docker ps

You will see two running containers as follows:

CONTAINER ID    IMAGE                          ...        PORTS                 NAMES
621282adb463    jenkinsandroid_nginxservice    ...  0.0.0.0:80->80/tcp    ...jenkinsandroid_nginxservice_1
4dd4d4c68b65    jenkinsandroid_jenkinsservice  ...  8080/tcp, 50000/tcp   ..jenkinsandroid_jenkinsservice_1
  1. Access to the running nginx container:
docker exec -i -t dockernginxjenkinsandroid_nginxservice_1 sh
  1. Inside the nginx docker container, we must create your own user basic auth
htpasswd -b -C 5 /etc/apache2/.htpasswd YOUR_USER_NAME YOUR_PASSWORD
  1. You will be prompted to write a password.
  2. That's all, you have a nginx basic auth now.

LET'S GET STARTED

Go to http://localhost/jenkins and you will be prompted to write you user authentication, write your YOUR_USER_NAME and YOUR_PASSWORD as we explain above and could access to the jenkins server.

icon

After enter your right credentials, you will be redirect to the jenkins server.

CLONING A BITBUCKET REPOSITORY WITH JENKINS

Keep in mind that jenkins container already has the jenkins user. So you can clone any repository through this user. For that purpose, we are going to create our SSH keys inside the container:

  1. Enter to the jenkins repository:
docker exec -i -t nginxproject_jenkinsservice_1 bash
  1. Into the container, place into the JENKINS_HOME path (/var/jenkins_home) and try to clone your own repository with SSH, for instance:
git clone git@bitbucket.org:orbisunt/YOU_REPO.git
  1. You will be prompted like this:
The authenticity of host 'bitbucket.org (...)' can't be established.
RSA key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no)? 
  1. Write yes and tap enter, the .ssh folder will be created automatically and the bitbucket server host will be added into the known_hosts file (/var/jenkins_home/.ssh/known_hosts)

  2. Until this point, we can't clone our repository with SSH because we haven't created our SSH KEYS(private and public) yet. For that purpose, we need to run:

ssh-keygen
  1. Press enter and we'll have our private and public keys, something like this:
cd /var/jenkins_home/.ssh ; ls
id_rsa	id_rsa.pub  known_hosts

ADDIND PUBLIC KEY TO BITBUCKET REPOSITORY

  1. Go to Bitbucket -> bitbucket settings -> SSH Keys.
  2. Copy the content of your id_rsa.pub and add it.
cat /var/jenkins_home/.ssh/id_rsa.pub
  1. Once your bitbucket repository already has your public key, try to clone your repository with ssh again:
git clone git@bitbucket.org:orbisunt/YOU_REPO.git
  1. This time you will be able to clone your repository.
  2. Happy coding!!!!

RUNNING ANDROID UI TESTS

When it comes to Android UI Tests, the best way is to run tests in a separate host machine. For that purpose, to take advantage of the speed of emulators in your host machine(MacOSX, Linux, Windows). We are going to create a Jenkins Slave Node.

  1. Go to Manage Jenkins > Manage Nodes.
  2. Enter Node Name. For example "android".
  3. Select Permanent Agent and press OK.
  4. Number of executors. For example 1.
  5. Set a Remote FS Root. For example "/Users/carlitosdroid/slave"
  6. Launch Method > Launch slave agents via Java Web Start
  7. That's all. Press Save and Go back to Nodes.
  8. Connect slave to jenkins from terminal run the following:
java -jar agent.jar -jnlpUrl http://localhost/jenkins/computer/android/slave-agent.jnlp -secret 636e4c1230031230536a46a3fc8f782fa123ea56477fb3f3226c06fcdcf09dd6 -workDir "/Users/carlitosdroid/slave" -auth YOUR_USER_NAME:YOUR_PASSWORD

All the steps above are here: Step by step guide to set up master and slave machines on Windows

INSTALLING ADDITIONAL ANDROID SDK LIBRARIES

If you wish, you can download these additional libraries for building your app:

cd $ANDROID_HOME/tools/bin/ && ./sdkmanager "extras;google;m2repository" "platforms;android-27" \
"extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2" \
"extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2" \
"cmake;3.6.4111459" "ndk-bundle"

COMMON ERRORS WITH FASTLANE

ERROR: Git repository is dirty! Please ensure the repo is in a clean state by committing/stashing/discarding all changes first. SOLUTION: Add fastlane/report.xml code line to your .gitignore file

COMMON ERRORS WITH CRASHLYTICS

ERROR: WARN - Crashlytics had a problem uploading the distribution. Project is inactive SOLUTION: Imeplementing crashlytic correctly in your project and generate a crash to active the app in crashlytics darshboard.

COMMON ERRORS WHEN WORKING WITH GOOGLE CLOUD

Make the server port is available, usually the default available por is 80

About

Little recipe with basic configuration for a jenkin server with nginx, all in docker

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published