Skip to content

Rodrigo Urubatan – About Code

Helping ruby developers to use the best tools for each job so they can solve hard problems, with less bugs and have more free time.

Menu
  • Home
  • My last presentations
  • About
  • Privacy Policy
Menu

Git deploy – how to implement git deploy in a project

Posted on 2018-02-25 by Rodrigo Urubatan

Lately I’m becoming a lazy developer, and this reflects in my work.

I tend to choose the easiest solution that will work for any project, and sometimes a simple project, is still in it’s early stages and it does not pay to configure a capistrano deploy or anything fancy, so I’m just using git to do the deployment, and it almost feels like heroku for me.

And the setup is pretty simple, might help you your projects too.

To setup that, we’ll use git hooks, and a bare git repository.

I’ll use a simplified version of my scripts in this post, to create a simple step by step.

In the server, create a directory for the bare git repo and initialize the  repository:

mkdir myproj.git
cd myproj.git
git init --bare
cd ..
git clone myproj.git

After that, we’ll setup the post-receive hook in the bare repository, to do that, create a file called post-receive in the myproj.git/hooks directory with this content:

#!/bin/bash
/bin/bash --login <<_EOF_
export GIT_DIR=/home/urubatan/myproj/.git
rvm use 2.4.0
cd /home/urubatan/myproj
git pull
npm install
bundle install
RAILS_ENV=production bundle exec rake db:migrate
bundle exec rake assets:precompile
touch tmp/restart.txt
_EOF_

Since we want this hook to execute every time we push something to that repository, do not forget o make the script executable:

chmod 755 myproj.git/hooks/post-receive

now back to your machine, just create your rails project as usual:

rails new myproj_client

add the bare repository as “deploy” remote

git remote add deploy user@server:~/myproj.git

and when you are done, push your changes to the server:

git add .
git commit -m "sample commit for the blog"
git push deploy master

Of course, you still need to configure the server, using for example, nginx + passenger, or puma, or any other thing, but that is subject to another post.

Please add any question to the comments of this post, I’ll answer everything as soon as possible.

Related

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent posts

  • Why Embrace Nesting in Ruby Modules?
  • An easy way to have a local “Github Copilot” for free
  • SPA without touching Javascript – The magic of Ruby on rails and Hotwire
  • I see Dead Jobs everywhere (sidekiq DeadSet)
  • Quick tips that help: rails notes

Arquives

  • May 2024
  • April 2024
  • February 2023
  • January 2023
  • December 2022
  • June 2021
  • March 2020
  • January 2020
  • July 2019
  • June 2019
  • May 2019
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • February 2018
  • January 2018
  • November 2017
  • August 2015
  • August 2014
  • July 2014
  • August 2007

Categories

  • AI
  • articles
  • cfp
  • firebase
  • gems
  • git
  • opinion
  • presentations
  • projects
  • rails6
  • ruby
  • Sem categoria
  • server-api
  • tutorials
  • Uncategorized
© 2025 Rodrigo Urubatan – About Code | Powered by Minimalist Blog WordPress Theme