DevOps Zone is brought to you in partnership with:

' ! Moshe Kaplan constantly helps successful firms getting to the next level and he is thrilled to uncover some of his secrets. Mr. Kaplan is a seasoned project management and cloud technologies lecturer. He is also known to be a cloud and SCRUM evangelist Moshe is a dSero.com Co-Founder. He was a R&D Director at Essence Security, led RockeTier and served as a board member in the IGT and as a department head at a top IDF IT unit. Moshe holds M.Sc and B.Sc from TAU. Moshe is a DZone MVB and is not an employee of DZone and has posted 59 posts at DZone. You can read more from them at their website. View Full User Profile

Instant Deployment with Git

03.01.2013
| 3730 views |
  • submit to reddit

One of the nicest things in git is that you can actually deploy code to production (or just your test environment) w/o implementing a complicated CI solution.

Off course that using CI such as Jenkins is recommended when compilation is required (JAVA/C/C++/C#) or when TDD/unit tests are use (and you better use them).
Yet, when you just need to deploy, git can be a great service for you.

Note: please note that you must an ssh access from the local machine (not always feasble).

How is done?
Actually it is very simple (and a complete explenation can be found atstackoverflow and toroid):


Step #1: Setup a repository in the development environment and commit a first file
> git init
Step #2: Setup an environment at the web server
> mkdir /path/to/dir/website.git && cd /path/to/dir/website.git
> git init --bare
Step #3: Enable a post receive hook at the web server> mkdir /var/www/www.mydomain.com> cat > hooks/post-receive#!/bin/shGIT_WORK_TREE=/var/www/www.mydomain.com git checkout -f> chmod +x hooks/post-receiveStep #4: Create a trigger at the development environment (and why you need ssh access from the workstation).> git remote add web ssh://www.mydomain.com/path/to/dir/website.git> git push web +master:refs/heads/masterStep #5: Code, Commit and Push to production> echo 'Rocking website!' > index.html
> git add index.html
> git commit -q -m "The index file was commited"
> git push web

Bottom Line
It is a simple task, but tricky if you don't have a direct access to the server (anyone said Jenkins?)

Published at DZone with permission of Moshe Kaplan, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Peter Butkovic replied on Fri, 2013/03/01 - 4:35am

 this seems crazy simple, but to be honest, I like it.

Moshe Kaplan replied on Fri, 2013/03/01 - 12:33pm in response to: Peter Butkovic

10x Peter, Keep Performing, Moshe Kaplan

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.