So I have got my django app running on Openshift. (how to run django app on Openshift) Now I wanted to automate the deployment of the app from a Github repo. The tool people use to do this is called Jenkins. So here’s the rundown of what I have been able to achieve.
First of all I havent been able to automatically build the app for deployment. What I’ve been able to do is setup a jenkins server, create a new job which receives an event from Github notifying a modification, after receiving which it simply pulls the changes from Github and pushes it to the Openshift server running the django app. On receiving the push the django app is rebuilt and deployed. Therefore I don’t have to push the app to both Github and django. But it would be better to have continous integration as the Openshift server stops the django app during rebuild so it becomes unreachable. So next step would be to implement CI.
#Steps to get Jenkins up and running
###1. Create a jenkins app
###2. Login to the jenkins using ssh
###3. Create a file
git-ssh.sh in the data directory
Create a file named
git-ssh.sh in the
$OPENSHIFT_DATA_DIR and put the following code inside it.
###4. Generate ssh keys We need to generate the ssh keys needed for git pull/push to work.
Enter the path to the id_rsa file pointed to by git-ssh.sh ie
Keep the passphrase field blank.
###5. Put the public key on Github and Openshift
Copy the public key just created and add it to the list of SSH keys in Github and Openshift.
The public key is located at
###6. Now open your jenkins dashboard and create a new job Open the jenkins server that you just created on Openshift. Once you get to the dashboard, create a new job with the following properties:
Item name: my-bldryou can give any name you wish
Build a free-style software projectselect this option and click ok
Application UUID: <UUID of the gear you want to push to>
Builder Size: small
Builder Timeout: 300000
Builder Type: redhat-python-2.7
Restrict where this project can be runcheck this option
Label Expression: master
Source code management: Git
- Then enter the details of git repo you want to pull from
- We’ll setup the trigger a little later
- Now add a Build script of type
Execute shelland enter the following code there and save the job:
###7. Add to the list of khown hosts Login in to the jenkins server using ssh and then run the following commands:
###8. Configure jenkins to add required environment variable
Manage Jenkins > Configure System
- Add the following:
###9. Thats it now open my-bldr and click Build Now. If I haven’t missed anything then build should be successful.
Next step would be to add the Github plugin and follow their instructions to add a trigger so that a push to your git repo triggers a build.