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 README.md), 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
Advertisements

8 thoughts on “Your Existing Github to OpenShift With Travis-CI

  1. Thanks for the great post.

    Appreciate if you could the details of how you did the last step:
    Continuous deployment – Travis-CI pushes every passing build to OpenShift git for deployment

    For Java web app, are you pushing the war file to deployments directory of the OpenShift?

    • I’m not pushing a war. OpenShift will build and deploy your code when you push to its git repo. What I am doing is using Travis-io to sync my github repo to OpenShifts git whenever I have a successful build. OpenShift does the rest.

      • Thanks for quick response.

        How do Travis CI perform the sync? Travis CI need to be authenticated to push to the changes to OpenShift git repo, right? It will be great if you could share more on the authentication side.

        Many thanks.

  2. Pingback: So you want to write a RESTful server in Java… | My name is Ozymandias
  3. To enable the`rhc` command to work in the pre-existing git repo after setting up the openshift remote and merging as you have documented, also set the following git config variables in your source/github repo: `rhc.app-id`, `rhc.app-name`, and `rhc.domain-name`. The proper values can be found in the git repo the rhc command initializes with `git config –local -l` or `cat .git/config`.

    I couldn’t find this documented anywhere, here’s the rhc source: https://github.com/openshift/rhc/blob/master/lib/rhc/context_helper.rb#L137

    • Thanks for the pointer. I’ll admit `rhc` is my least favorite part of openshift. Being ruby based is is very sensitive to my OS version (i.e. hates some of my older machines) and seems to break semi regularly as bits and pieces of the ruby ecosystem change.

  4. Pingback: Java Application Reloader | My name is Ozymandias

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s