Wednesday, January 20, 2016

Building a project hosted on Github using an Openshift Jenkins instance

In this blog, we will see how to build a project hosted on Github using an Openshift instance running Jenkins. You can also take it a step further and do continuous deployment. But, let first see how to make work giving that Openshift doesn't grant write permission on several folders on a Jenkins instance such as: .ssh, .m2.

1- Create a Jenkins instance

You can create a Jenkins instance either by logging into web account and using the dashboard, or using the command line by using rhc. Here a blog post to follow if you have not a jenkins instance already Launching a Jenkins instance on Openshift

2- Configuring SSH to connect to Github

In to be able to pull your source code from Github you need to generate an SSH key and deploy to your Github account. Let's assume that your jenkins instance is called buildserver.

First you need to connect to your server using ssh by running the following command

- rhc ssh buildserver

Since Openshift doesn't grant write permission on .ssh folder, we need to write an ssh-wrapper that will use a writable folder to store ssh keys and to be able to update know_hosts. Let's first create a writable folder for ssh.

- mkdir app-root/data/git-ssh

Then, we generate an SSH key that will be deployed on Github

- ssh-keygen -t rsa -b 4096 -C "youremail@yourdomain.com"

when prompted for the location where you want to store your keys, enter the following:

$OPENSHIFT_DATA_DIR/git-ssh/id_rsa ($OPENSHIFT_DATA_DIR is an env variable set automatically by Openshift)

Then, we need deploy id_rsa.pub to Github. This blog entry helps to do so if you are not familiar with that yet. Deploy SSH key to Github

At this time, you would have been able to run successfully this command if .ssh folder was writable.  You will get permission denied.

- ssh -T git@github.com

To overcome this problem, you need to create a script ssh-wrapper.sh that does the following:

#!/bin/bash

ID_RSA="$OPENSHIFT_DATA_DIR/git-ssh/id_rsa"
KNOWN_HOSTS="$OPENSHIFT_DATA_DIR/git-ssh/known_hosts"

ssh -o UserKnownHostsFile=$KNOWN_HOSTS -i $ID_RSA $1 $2

- chmod +x ssh-wrapper.sh (Don't forget to make it executable)

At this point, you should be able to SSH successfully Github

./ssh-wrapper.sh -T git@github.com
Hi Jenkins! You've successfully authenticated, but GitHub does not provide shell access.

Finally, you need to tell Jenkins to use this wrapper to be able to pull your source code from Github. You should go to Manage Jenkins > Configure System > Global Properties and create a new environment variable called GIT_SSH that refers to the location where you created your wrapper.

3- Conclusion

In this tutorial, we have seen how to allow an Openshift Jenkins instance to pull source code from Github. This involved writing an ssh wrapper due a lack of write permission on .ssh folder. As this point, you can start creating Jenkins jobs to build your CI pipeline. I have skipped installing any build tool since it's project specific. Please, don't hesitate to share any thoughts you have about this article or any comment you may have.

Monday, March 14, 2011

Tunisian's jasmine revolution

Tunisian’s Jasmine revolution started in December 2010. At that time, nobody thought that this could be spread across the region and even forced General Ben Ali to leave the country after 23 years of dictatorship. The revolution started in Sidi Bouzid, in the poor interior of Tunisia, when Mohamed Bouazizi, 26 years old, set himself on fire. He is a jobless college graduated, so he started selling fruit and vegetables on the street to support his family. On December 17th 2010, he was arrested and slapped on the face in public by a female officer and his wares were confiscated. In protest against harassment and humiliation, Mohamed Bouazizi set himself alight. His desperate act sparked a large protest movement through the country.  
People protested against poverty, dictatorship and corruption. President Ben Ali and his family controlled the most important sectors like tourism, transportation, real estate, etc. In fact, Wikileaks cables revealed that the US ambassador to Tunisia qualified Ben Ali’s family as “quasi-mafia”.  However, he outlined that the situation was stable and would remain in control for the next 10 years.
The national media, which is controlled by the government, ignored the movement. The Tunisian protesters got organized using social networks such as Facebook and Twitter. They shared videos showing the government’s repression, which encouraged many people to join them. Ben Ali tried several times to convince them to stop protesting. He visited Mohamed Bouazizi in the hospital and promised more investments in Sidi Bouzid.  Then, he gave 3 speeches but people had a strong determination to oust him. He ended up by leaving Tunisia on January 14th 2010.

The success of the Tunisian revolution inspired many other populations like the Egyptian people, who have ousted President Mubarak who was in power for 32 years.