The SCM (Souce Control Management) tool, Git, is quickly becoming the preferred replacement technology for SVN (Subversion) and CVS (Concurrent Versions System). It is a very commonly used approach for Rails developers to manage their code between each other and have that code eventually make it to the application server where the RubyOnRails application is hosted.
Formal git documentation.
If you are new to Git or just want to brush up on what it's about, then take this online tutorial.
This tutorial will guide you through how to setup a scenario that uses Git to exchange files with the IBM i server and many clients (i.e. a developers laptop). The Git tooling is included with the PowerRuby install in folder /PowerRuby/oss/bin with symbolic links created in /QOpenSys/usr/bin so they are accessible to everyone without having to export additional entries to your PATH environment variable.
The general concept of this tutorial is to have a central server-side (IBM i) repository that a developer will push and pull from. The application folder will only pull from the Git repository because you won't, in theory, be making changes to the application source in the IFS. This is because the primary approach to RubyOnRails development is done on the developers laptop and then pushed/deployed to the server. Below is a picture of what this scenario looks like. Note that you could also have your development repository also stored on the IFS (more on that later).
Setting Up Your git Profile
Part of using git involves knowing who did what. This means you need to declare who you are on each machine you use git on. To do this you can run the following git config commands (replace email@example.com and Your Name with appropriate information). The push.default simple setting is explained here.
$ git config --global user.email "firstname.lastname@example.org" $ git config --global user.name "Your Name" $ git config --global push.default simple
Setup The Server Repository
The first thing you need to do is setup the primary repository that developers will pull and push from. This could reside on any machine but the IBM i makes a great fit because it is most likely already being backed up and is "always on". The practice of setting up a server-side repository is to first initialize it as bare and then subsequently occupy it from the client-side with a git push (as you will see later).
CALL QP2TERM $ mkdir -p /git/rails_app $ cd /git/rails_app $ git init --bare
Check out the free ProGit book if you are wanting more in-depth explanations than what is provided here.
Development Environment Setup
In the RubyOnRails community it is most common to do all application development on your local laptop. This means you need to have source in a central Git repository so it can be retrieved, worked on, and put back into the central repository for other developers to also contribute.
Option 1: Initial Occupy of Server-Side
This step is only necessary if you are the one initially occupying the server-side (central) repo. If you are not doing this then skip to option 2, "Clone Server-Side Repo", below.
The following should be done from your local laptop terminal. On Mac you should use the Terminal application. If you're on Linux then you already know. And if you're on Windows you can go here.
Open up a terminal on your laptop and type the following to push the initial code to the IBM i git repository from your local machine. Note you need to have SSH started on your IBM i for this command to work.
$ cd /path/to/my/rails_app $ git init $ git add . $ git commit -m 'initial commit' $ git remote add origin ssh://email@example.com/git/rails_app $ git push origin master
Alternatively you could also do your development on the IBM i.
$ cd /ifs/path/to/my/git_projects/ $ git init $ git add . $ git commit -m 'initial commit' $ git remote add origin /git/rails_app $ git push origin master
Option 2: Clone Server-Side Repo
If the server-side repo is already setup then setting up your development environment is very simple.
$ git clone ssh://firstname.lastname@example.org/git/rails_ap
Making Changes In Development Environment
At this point the development repository is initialized as is the server-side. Next let's go through a change iteration. Go ahead and make a change to the Gemfile by adding a simple comment to it:
source 'https://rubygems.org'/ # This is a new comment line gem 'rails', '4.0.0' . . .
Now it is time to add those changes back to the central repository on the server. To do that first make sure you are in the Git project's directory (i.e. /path/to/my/git_projects/rails_app) and the run the below commands. This will put your changes back up on the server into the central repository at location /git/rails_app
$ git add . $ git commit -m "A message for the commit" $ git push origin master
Alternatively you can run the following command and simplify your push to the server-side to a simple git push.
$ git push --set-upstream origin master
Note the code is only in the central server repository and is not yet in your application's IFS folder. The next step will detail how to manually deploy from the git repo to your web app (most likely in the /www folder).
When you want to bring a fresh set of source from the central git repository then you can do the following sequence of events. This will preserve your current release and put the new one in a timestamped folder and then create a symbolic link named current to point at it.
$ mkdir /www/apache_instance/htdocs/releases/CCYYMMDDHHMMSS $ git clone -l /git/rails_app /www/apache/htdocs/releases/CCYYMMDDHHMMSS $ ln -s /www/apache/htdocs/releases/20140301120645/ /www/apache/htdocs/current
At this point you can cd into the /www/apache/htdocs/current folder and start your Rails server.
$ cd /www/apache/htdocs/current $ rails s -p9999