devroom.io/content/blog/2011-11-18-deploying-a-third-party-rails-application-like-gitlab.md

76 lines
3.1 KiB
Markdown
Raw Normal View History

2017-03-20 15:35:19 +00:00
+++
date = "2011-11-18"
title = "Deploying a third-party Rails application - like Gitlab"
tags = ["Capistrano", "github", "gitlab", "deploy"]
slug = "deploying-a-third-party-rails-application-like-gitlab"
+++
2015-03-26 11:28:08 +00:00
We all know how to deploy our own Rails projects. (If not, [read this guide][1].) But how do you handle deploying a third-party application that may require some customisation on your part?
A good example would be [Gitlab][gitlab]
Gitlab is an open source Github clone, build using Ruby on Rails. It's a nice project that uses Gitosis under the hood to manage your git repositories. There are [several][2] [good][3] installation guides available on the web, but they all assume you want to deploy gitlab verbatim - without any modification or configuration
I have also setup Gitlab, but I want to use capistrano and unicorn. I also want to tweak some configuration. In some rare cases I want to fix an annoying bug and not wait for the Gitlab team to pull it.
Doing a `git pull` on my remote server just won't cut it.
## Fork! Fork!
What I did was clone Gitlab and use the same principles describe in my [_Contributing to open source with Github_][4] to apply my own changes and merge any upstream changes when they are available.
Here's how I set everything up.
First, clone the official Gitlab repository and name it `upstream`.
2017-03-20 15:35:19 +00:00
``` shell
git clone --origin upstream https://github.com/gitlabhq/gitlabhq.git my_git_server
```
2015-03-26 11:28:08 +00:00
Next I made all the changes I want. I updated `config/gitosis.yml` and `unicorn` to `Gemfile` and setup Capistrano.
I then pushed this to my own git server. This is the same server Capistrano will use to pull changes from.
2017-03-20 15:35:19 +00:00
``` shell
git remote add origin git@git.ariejan.net:my_git_server.git
git push origin master
cap deploy
```
2015-03-26 11:28:08 +00:00
That's all there is to deploying Gitlab from my own repository.
## Merging upstream changes
Now, the Gitlab crew is pushing out new features at an amazing rate. So, how do I get those new features (and the occasional bug fix) into my copy of Gitlab for deploying?
2017-03-20 15:35:19 +00:00
``` shell
git fetch upstream
```
2015-03-26 11:28:08 +00:00
Remember how we named the official Gitlab repository `upstream` earlier? With this `fetch` we get all changes from their repository (but we don't apply them to anything yet).
Then, merge the upstream changes with your own branch.
2017-03-20 15:35:19 +00:00
``` shell
git merge upstream/master
```
2015-03-26 11:28:08 +00:00
There may be merge conflicts, just resolve them and commit your merge. Then again to deploy:
2017-03-20 15:35:19 +00:00
``` shell
git push origin master
cap deploy
```
2015-03-26 11:28:08 +00:00
## Why do this?
The reason I use this approach is that it's easy to merge upstream changes and have my own customizations and deployment tools at the same time.
[1]: http://ariejan.net/2011/09/14/lighting-fast-zero-downtime-deployments-with-git-capistrano-nginx-and-unicorn
[gitlab]: http://www.gitlabhq.com
[2]: http://www.ryanwersal.com/blog/2011/10/18/installing-gitlab-on-ubuntu-server/
[3]: http://nepalonrails.tumblr.com/post/12603081685/setup-gitlab-github-clone-using-vagrant-and-chef
[4]: http://ariejan.net/2011/11/09/contributing-to-open-source-with-github
2017-03-20 15:35:19 +00:00