For the longest time I self-hosted all my git repositories not so much because I enjoyed doing so but because there were limited options for easily pushing code from git to my servers. Invariably you will end up using an intermediary because GitHub and their peers have no real reason nor inclination to make those things easy for you. After all, if they can keep you in their systems, more money to ’em.
And while that’s perfectly understandable and logical, it’s annoying. And if you’re on a budget and not a Git Expert, it’s extremely frustrating. The deployment API was written in High Level Geek, and I found it a headache to decipher and test.
The Plan The Plan
My plan is simple. I want to push code to a Github Repository and, when it’s a push to master, it would rsync the files over to my server. This will allow multiple people to work on code, among other things.
The Setup The Setup
First make an account with Codeship. You can log in as Github which is useful since you’ll want to connect your Github account with Codeship anyway. When you create a project, you’ll be prompted which SCM you want to use:
I’m using Github, but it’s nice to see GitLab in there as well. Once you pick your SCM, paste in the clone URL.
Finally you can pick Codeship Pro or Basic – I picked Basic because it required the least amount of know-how. Not that it’s easy, but I don’t have to configure the server or anything annoying. In fact, Basic is so basic, than you can just accept the default setup commands and go. Which is what I did.
The Settings The Settings
Once you’ve done all that, you’re on a new screen that tells you to push code. Of course, you can’t do that until you set up a couple more things. Like tell it where to push the code.
Click on “Project Settings” and go to the General tab. You’ll need to get that SSH key and add it to your server’s
~/.ssh/authorized_keys to allow passwordless deployment. I strongly recommend that.
Now you can click Deploy and add a Deployment Pipeline. Pick ‘master’ unless you’re using something else.
Now you have to add a deployment to your pipeline. There are a lot of options here, but for my plan of an rsync, the choice is “Custom Script”. Since I’m pushing code to my DreamPress server, the rsync looks like this:
# DreamPress rsync -aCz -e "ssh" ~/clone/ email@example.com:/home/wp_e414xh/mysite.dream.press/wp-content/themes/my-theme-name/ --delete
You can customize your rsync commands however you want. I like mine to delete files I’ve removed.
Deploy the Ships Deploy the Ships
Everything is set up so go back to your project page and push some code to Github
The code deploys.
On the free version you only get 100 private builds and five private projects. Mine are public (so’s the Github repo for that matter) so it doesn’t matter. The only downside is only getting one push at a time, but since they take less than five minutes, it’s perfectly acceptable for a free solution.