- Use my existing GitHub repo with OpenShift
- 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:
- Create a DiY OpenShift app
- Strip that app down to just it’s control structure.
- Commit and push to the OpenShift git
- Add the OpenShift git repo as a remote origin to my local clone of my GitHub repo
- Pull from the OpenShift origin
- Resolve any merge issues (both had a README.md), commit
- Add a new single remote alias for combining GitHub and OpenShift
- Push to combined remote
- 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.
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