Your Existing Github to OpenShift With Travis-CI

I’ve a pre-existing app written in Java (Shields App). I’ve worked out how to deploy similar apps into OpenShift (OpenShift, JDK 8, Gradle). Now to finish things up I needed to:

  1. Use my existing GitHub repo with OpenShift
  2. Get Travis-CI to deploy to OpenShift

Info on both of these is out there, so it was largely just pulling it together and applying it to my case.

Using An Existing GitHub Repo With OpenShift

If you really know git, you’ll know that this is “straight forward”. While I use git on a daily basis, this was not intuitive to me so it’s worth a some explanation I think. The common pattern of git use is you clone a remote repository locally, work in it and push changes back to the remote origin. But git is by no means limited to that. Apropos the my goals here you can have multiple remote origins for a repo. To learn the mechanics of this I referred to the article Pushing to two git remote origins from one repository. Understanding the mechanics I decided how best to apply them here. I came up with:

  1. Create a DiY OpenShift app
  2. Strip that app down to just it’s control structure.
  3. Commit and push to the OpenShift git
  4. Add the OpenShift git repo as a remote origin to my local clone of my GitHub repo
  5. Pull from the OpenShift origin
  6. Resolve any merge issues (both had a, commit
  7. Add a new single remote alias for combining GitHub and OpenShift
  8. Push to combined remote
  9. Verify GitHub and OpenShift gits both looked right

After all this, what you have is a local repo with two origins, GitHub and OpenShift, that are now synchronized. If you wanted, at this point, you could simply work in that local repo, and always push to the combined remote and everything would work as desired.

Get Travis-CI to Deploy to OpenShift

While I had the git repos in order now, I wanted a continuous deployment pipeline, where builds were tested and if tests passed, then they were deployed. For that I used Travis-CI. My existing repo was already building on Travis-CI, so the only addition was to followed their guide for deploying to OpenShift.

The Results

Plugging these all together you end up with:

  • A single local repo to work in
  • A single place to push to – GitHub
  • Continuous integration – Travis-CI builds every GitHub push
  • Continuous deployment – Travis-CI pushes every passing build to OpenShift git for deployment