Skip to content

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

License

Notifications You must be signed in to change notification settings

orbismobile/docker-nginx-jenkins-android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JENKINS BEHIND NGINX REVERSE PROXY WITH DOCKER

POWERED BY ORBIS MOBILE TEAM

icon

SUMMARY

This Docker Project uses the latest versions of nginx and jenkins docker official images. You will be able to use nginx as a reverse proxy server to access jenkins automation server. This project is well-recommended for development purpose but if you want to work in production environment we tightly recommend you to work with the best lightweight alpine images, please review the alpine branch

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    nginxproject_nginxservice    ...  0.0.0.0:80->80/tcp    nginxproject_nginxservice_1
4dd4d4c68b65    nginxproject_jenkinsservice  ...  8080/tcp, 50000/tcp   nginxproject_jenkinsservice_1
  1. Access to the running nginx container:
docker exec -i -t nginxproject_nginxservice_1 bash
  1. Inside the nginx docker container, we must create your own user basic auth
htpasswd /etc/apache2/.htpasswd 'YOUR_USER_NAME'
  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 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 [email protected]: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 ~./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.
  3. Once your bitbucket repository already has your public key, try to clone your repository with ssh again:
git clone [email protected]:orbisunt/YOU_REPO.git
  1. This time you will be able to clone your repository.
  2. Happy coding!!!!