SlideShare una empresa de Scribd logo
1 de 39
Put Git to work
increase the quality of your Rails project, and let git do the boring
work for you
Rodrigo
Urubatan
▶ rodrigo@urubatan.com.br
▶ http://twitter.com/urubatan
▶ http://github.com/urubatan
▶ http://linkedin.com/in/urubatan
▶ http://sobrecodigo.com
5 ways git can help deploy your rails
application
1 – check every commit follow company standards
2 – identify where each commit come from
3 – make sure at least the changed files tests run before pushing code
4 – start CI build after pushing the code
5 – 2 different approaches to git push your deploy after the ci build succeded
There is a lot of boring manual work to
do before each deploy!
Check code against
standards
Pretty format commit
messages
Run tests for the files
you changed to speed
up development
Start CI builds Start deployments Compile assets
Run migrations when
needed
Install npm modules
Reload application
servers
This is
my goal!
Git can help!
Commit Check
standards
Format
message
Push
code
Run tests
(locally)
Start CI
process
Pull
code
Bundle
install
Yarn
install
Start
deploy
Npm
install
Bundle
install
Db
migrate
Restart
service(s)
Putting it to
work!
Codding
standards
Git pre-commit hook
Formatting
commit
message
Git prepare-commit-msg hook
Running
tests
Git pre-push hook
Firing CI
build
Git post-receive hook
Automatic
deployment
Git post-receive hook
Or Git post-merge hook
I had one (more than one) evil coworker
that didn’t follow any company standards
This Photo by Unknown Author is licensed under CC BY
How to fight the
Evil Coworker
who does not
follow good
practices?
This Photo by Unknown Author is licensed under CC BY-SA
rubocode + .git/hooks/pre-commit
#!/bin/sh
echo "Checking commit"
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# If you want to allow non-ASCII filenames set this variable to true.
rubocop -R `git diff --cached --name-only $against`
if [ "$?" != "0" ]; then
cat <<EOF
pretty Failed!! message!!
EOF
exit 1
fi
I found a commit and did not know
where it came from
This Photo by Unknown Author is licensed under CC BY
Formatting commit messages
#!/bin/bash
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
BRANCH_IN_COMMIT=$(grep -c "[$BRANCH_NAME]" $1)
if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1
fi
Life is too short
to test before
sharing my code!
Run your tests before pushing the code!
#!/usr/bin/env ruby
branch_name=`git symbolic-ref -q HEAD`
branch_name = branch_name.gsub('refs/heads/', '').strip
changed_files = `git diff --name-only
#{ARGV[0]}/#{branch_name}`.split("n").map(&
:strip).select{|n| n =~ /.rb$/}
#run the file specific test
test_files = changed_files.map do |name|
if name =~ /^app/
name.gsub('app/', 'test/').gsub(/.rb$/, '_test.rb')
elsif name =~ /^test/
name
else
nil
end
end.reject(&:nil?).uniq
#abort if there is a test missing
if !test_files.reject{|n| File.exists?(n)}.empty?
puts %Q{
Aborting push because there are missing test files:
#{test_files.reject{|n| File.exists?(n)}}
}
exit 1
end
#if there are config files changes, run all tests
if !changed_files.select{|n| n =~ /^config/}.empty?
test_files = ''
end
system('git stash')
result = system("rails test #{test_files.join(' ')}")
system('git stash apply')
unless result
puts %Q{
Aborting push due to failed tests
}
exit 1
end
Trick’em into
using your
perfect hooks
This Photo by Unknown Author is licensed under CC BY-NC-ND
And the evil trick!
▶ npm i shared-git-hooks --save-dev or yarn add shared-git-hooks
▶ Add your git hooks (with or without extension) to the hooks
directory in your project
Too much automation?
This Photo by Unknown Author is licensed under CC BY-NC-SA
Found out you
need another gem
or npm module
when you decide
to do some work
in the airplane?
This Photo by Unknown Author is licensed under CC BY-NC-SA
.git/hooks/post-merge
#!/bin/bash
bundle install
yarn install
Continuous Integration
This Photo by Unknown Author is licensed under CC BY-SA
Continuous
integration
pooling?
Firing CI
Build
▶.git/hooks/post-receive with a
curl to your CI server
▶Github integrated CI servers
(github version of the above)
Jenkins
curl -X POST http://username:user_api_token@your-
jenkins.com/job/JobName/build?token=build_trigger_api_token
TravisCI
body='{
"request": {
"branch":"master"
}}'
curl -s -X POST 
-H "Content-Type: application/json" 
-H "Accept: application/json" 
-H "Travis-API-Version: 3" 
-H "Authorization: token xxxxxx" 
-d "$body" 
https://api.travis-ci.com/repo/mycompany%2Fmyrepo/requests
TeamCity
curl -X POST -u apiuser:apipassword -d '<build><buildType
id="SpringPetclinic_Build"/></build>'
http://localhost:8111/httpAuth/app/rest/buildQueue --header "Content-Type:
application/xml" -H "Accept: application/json"
Bamboo
export BAMBOO_USER=foo
export BAMBOO_PASS=bar
export PROJECT_NAME=TST
export PLAN_NAME=DMY
export STAGE_NAME=JOB1
curl --user $BAMBOO_USER:$BAMBOO_PASS -X POST -d
"$STAGE_NAME&ExecuteAllStages"
http://mybamboohost:8085/rest/api/latest/queue/$PROJECT_NAME-
$PLAN_NAME
Automatic
Deployment
– Heroku
Recipe
1 server
1 bare repository
1 simple script
1 deployment
repository/path
My goal with this approach is to do this
▶ git remote add production user@server:myapp.git
▶ Git push production master
This Just Deployed my code to production!
Git Bare Repository
▶ mkdir myapp.git
▶ cd myapp.git && git init --bare
▶ vi hooks/post-receive
myapp.git/hooks/post-receive
#!/bin/bash
while read oldrev newrev ref
do
branch_received=`echo $ref | cut -d/ -f3`
echo "Deploying branch $branch_received"
/bin/bash --login -- <<__EOF__
cd /home/urubatan/projects/deployedapp
git fetch
git checkout -f $branch_received
git pull
yarn install
bundle install
rails db:migrate
rails assets:precompile
touch tmp/restart.txt
__EOF__
done
Automatic Deployment – git pull style
(post-merge hook)
#!/bin/bash
bundle install
yarn install
rails db:migrate
rails assets:precompile
touch tmp/restart.txt
Do you feel you need to track all that
deploys?
This Photo by Unknown Author is licensed under CC BY-SA
git-deploy
▶ https://github.com/git-deploy/git-deploy
▶ git deploy start (you can git deploy abort if needed)
▶ Merge all feature branches that need deployment
▶ git deploy sync
▶ Push that to all your servers (maybe using our Heroku strategy?)
▶ git deploy finish
▶ Now you can use the git-deploy script to list all deployments, or go back to
any one of them!
Questions?
Rodrigo Urubatan
▶ I help ruby developers to use the
best tools for each job so they can
solve hard problems, with less bugs
and have more free time.
▶ rodrigo@urubatan.com.br
▶ http://twitter.com/urubatan
▶ http://bit.ly/weekly_rails_tips
▶ http://github.com/urubatan
▶ http://linkedin.com/in/urubatan
▶ http://sobrecodigo.com
Whats next? A git ebook!
http://bit.ly/weekly_rails_tips

Más contenido relacionado

La actualidad más candente

Deploying a Location-Aware Ember Application
Deploying a Location-Aware Ember ApplicationDeploying a Location-Aware Ember Application
Deploying a Location-Aware Ember ApplicationBen Limmer
 
GraphQL IN Golang
GraphQL IN GolangGraphQL IN Golang
GraphQL IN GolangBo-Yi Wu
 
Using Ansible as Makefiles to unite your developers
Using Ansible as Makefiles to unite your developersUsing Ansible as Makefiles to unite your developers
Using Ansible as Makefiles to unite your developersthiagoalessio
 
Ruby Isn't Just About Rails
Ruby Isn't Just About RailsRuby Isn't Just About Rails
Ruby Isn't Just About RailsAdam Wiggins
 
以 Laravel 經驗開發 Hyperf 應用
以 Laravel 經驗開發 Hyperf 應用以 Laravel 經驗開發 Hyperf 應用
以 Laravel 經驗開發 Hyperf 應用Shengyou Fan
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyLaunchAny
 
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnishRunning node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnishthiagoalessio
 
Lights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFeverLights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFeverbridgetkromhout
 
Jedi Mind Tricks for Git
Jedi Mind Tricks for GitJedi Mind Tricks for Git
Jedi Mind Tricks for GitJan Krag
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Vikas Chauhan
 
Repoinit: a mini-language for content repository initialization
Repoinit: a mini-language for content repository initializationRepoinit: a mini-language for content repository initialization
Repoinit: a mini-language for content repository initializationBertrand Delacretaz
 
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...MongoDB
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpmsom_nangia
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à RubyMicrosoft
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversTatsuhiko Miyagawa
 
Distributed Developer Workflows using Git
Distributed Developer Workflows using GitDistributed Developer Workflows using Git
Distributed Developer Workflows using GitSusan Potter
 
Silex, the microframework
Silex, the microframeworkSilex, the microframework
Silex, the microframeworkInviqa
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with DancerDave Cross
 

La actualidad más candente (20)

Deploying a Location-Aware Ember Application
Deploying a Location-Aware Ember ApplicationDeploying a Location-Aware Ember Application
Deploying a Location-Aware Ember Application
 
GraphQL IN Golang
GraphQL IN GolangGraphQL IN Golang
GraphQL IN Golang
 
Mojolicious and REST
Mojolicious and RESTMojolicious and REST
Mojolicious and REST
 
Using Ansible as Makefiles to unite your developers
Using Ansible as Makefiles to unite your developersUsing Ansible as Makefiles to unite your developers
Using Ansible as Makefiles to unite your developers
 
Ruby Isn't Just About Rails
Ruby Isn't Just About RailsRuby Isn't Just About Rails
Ruby Isn't Just About Rails
 
以 Laravel 經驗開發 Hyperf 應用
以 Laravel 經驗開發 Hyperf 應用以 Laravel 經驗開發 Hyperf 應用
以 Laravel 經驗開發 Hyperf 應用
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Running node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnishRunning node.js as a service behind nginx/varnish
Running node.js as a service behind nginx/varnish
 
Lights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFeverLights, Camera, Docker: Streaming Video at DramaFever
Lights, Camera, Docker: Streaming Video at DramaFever
 
Jedi Mind Tricks for Git
Jedi Mind Tricks for GitJedi Mind Tricks for Git
Jedi Mind Tricks for Git
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
Repoinit: a mini-language for content repository initialization
Repoinit: a mini-language for content repository initializationRepoinit: a mini-language for content repository initialization
Repoinit: a mini-language for content repository initialization
 
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à Ruby
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 
Distributed Developer Workflows using Git
Distributed Developer Workflows using GitDistributed Developer Workflows using Git
Distributed Developer Workflows using Git
 
Silex, the microframework
Silex, the microframeworkSilex, the microframework
Silex, the microframework
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 

Similar a 2018 the conf put git to work - increase the quality of your rails project and let git do the boring work for you

Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby TeamArto Artnik
 
Scaling up development of a modular code base
Scaling up development of a modular code baseScaling up development of a modular code base
Scaling up development of a modular code baseRobert Munteanu
 
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기SuJang Yang
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)dantleech
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hopeMarcus Ramberg
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
Optimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for DockerOptimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for DockerGraham Charters
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis OverviewLeo Lorieri
 
Scaling up development of a modular code base
Scaling up development of a modular code baseScaling up development of a modular code base
Scaling up development of a modular code baseRobert Munteanu
 
Scaling up development of a modular code base - R Munteanu
Scaling up development of a modular code base - R MunteanuScaling up development of a modular code base - R Munteanu
Scaling up development of a modular code base - R Munteanumfrancis
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment TacticsIan Barber
 
Instrumentación de entrega continua con Gitlab
Instrumentación de entrega continua con GitlabInstrumentación de entrega continua con Gitlab
Instrumentación de entrega continua con GitlabSoftware Guru
 
Kubernetes walkthrough
Kubernetes walkthroughKubernetes walkthrough
Kubernetes walkthroughSangwon Lee
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)LumoSpark
 
Deploying configurable frontend web application containers
Deploying configurable frontend web application containersDeploying configurable frontend web application containers
Deploying configurable frontend web application containersJosé Moreira
 
Women Who Code - RSpec JSON API Workshop
Women Who Code - RSpec JSON API WorkshopWomen Who Code - RSpec JSON API Workshop
Women Who Code - RSpec JSON API WorkshopEddie Lau
 

Similar a 2018 the conf put git to work - increase the quality of your rails project and let git do the boring work for you (20)

Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Scaling up development of a modular code base
Scaling up development of a modular code baseScaling up development of a modular code base
Scaling up development of a modular code base
 
Capistrano Overview
Capistrano OverviewCapistrano Overview
Capistrano Overview
 
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기
DevFest 2022 - GitHub Actions를 활용한 Flutter 배포 자동화하기
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Optimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for DockerOptimizing Spring Boot apps for Docker
Optimizing Spring Boot apps for Docker
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
Scaling up development of a modular code base
Scaling up development of a modular code baseScaling up development of a modular code base
Scaling up development of a modular code base
 
Scaling up development of a modular code base - R Munteanu
Scaling up development of a modular code base - R MunteanuScaling up development of a modular code base - R Munteanu
Scaling up development of a modular code base - R Munteanu
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment Tactics
 
Instrumentación de entrega continua con Gitlab
Instrumentación de entrega continua con GitlabInstrumentación de entrega continua con Gitlab
Instrumentación de entrega continua con Gitlab
 
Sprockets
SprocketsSprockets
Sprockets
 
Kubernetes walkthrough
Kubernetes walkthroughKubernetes walkthrough
Kubernetes walkthrough
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)Web development automatisation for fun and profit (Artem Daniliants)
Web development automatisation for fun and profit (Artem Daniliants)
 
Deploying configurable frontend web application containers
Deploying configurable frontend web application containersDeploying configurable frontend web application containers
Deploying configurable frontend web application containers
 
Write php deploy everywhere tek11
Write php deploy everywhere   tek11Write php deploy everywhere   tek11
Write php deploy everywhere tek11
 
Women Who Code - RSpec JSON API Workshop
Women Who Code - RSpec JSON API WorkshopWomen Who Code - RSpec JSON API Workshop
Women Who Code - RSpec JSON API Workshop
 

Más de Rodrigo Urubatan

Data science in ruby is it possible? is it fast? should we use it?
Data science in ruby is it possible? is it fast? should we use it?Data science in ruby is it possible? is it fast? should we use it?
Data science in ruby is it possible? is it fast? should we use it?Rodrigo Urubatan
 
Data science in ruby, is it possible? is it fast? should we use it?
Data science in ruby, is it possible? is it fast? should we use it?Data science in ruby, is it possible? is it fast? should we use it?
Data science in ruby, is it possible? is it fast? should we use it?Rodrigo Urubatan
 
TDC2017 - POA - Aprendendo a usar Xamarin para desenvolver aplicações moveis ...
TDC2017 - POA - Aprendendo a usar Xamarin para desenvolver aplicações moveis ...TDC2017 - POA - Aprendendo a usar Xamarin para desenvolver aplicações moveis ...
TDC2017 - POA - Aprendendo a usar Xamarin para desenvolver aplicações moveis ...Rodrigo Urubatan
 
Your first game with unity3d framework
Your first game with unity3d frameworkYour first game with unity3d framework
Your first game with unity3d frameworkRodrigo Urubatan
 
Tdc Floripa 2017 - 8 falácias da programação distribuída
Tdc Floripa 2017 -  8 falácias da programação distribuídaTdc Floripa 2017 -  8 falácias da programação distribuída
Tdc Floripa 2017 - 8 falácias da programação distribuídaRodrigo Urubatan
 
Rubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDDRubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDDRodrigo Urubatan
 
resolvendo problemas de comunicação em equipes distribuídas com bdd
resolvendo problemas de comunicação em equipes distribuídas com bddresolvendo problemas de comunicação em equipes distribuídas com bdd
resolvendo problemas de comunicação em equipes distribuídas com bddRodrigo Urubatan
 
vantagens e desvantagens de trabalhar remoto
vantagens e desvantagens de trabalhar remotovantagens e desvantagens de trabalhar remoto
vantagens e desvantagens de trabalhar remotoRodrigo Urubatan
 
Using BDD to Solve communication problems
Using BDD to Solve communication problemsUsing BDD to Solve communication problems
Using BDD to Solve communication problemsRodrigo Urubatan
 
TDC2015 Porto Alegre - Interfaces ricas com Rails e React.JS
TDC2015  Porto Alegre - Interfaces ricas com Rails e React.JSTDC2015  Porto Alegre - Interfaces ricas com Rails e React.JS
TDC2015 Porto Alegre - Interfaces ricas com Rails e React.JSRodrigo Urubatan
 
Interfaces ricas com Rails e React.JS @ Rubyconf 2015
Interfaces ricas com Rails e React.JS @ Rubyconf 2015Interfaces ricas com Rails e React.JS @ Rubyconf 2015
Interfaces ricas com Rails e React.JS @ Rubyconf 2015Rodrigo Urubatan
 
TDC São Paulo 2015 - Interfaces Ricas com Rails e React.JS
TDC São Paulo 2015  - Interfaces Ricas com Rails e React.JSTDC São Paulo 2015  - Interfaces Ricas com Rails e React.JS
TDC São Paulo 2015 - Interfaces Ricas com Rails e React.JSRodrigo Urubatan
 
Full Text Search com Solr, MySQL Full text e PostgreSQL Full Text
Full Text Search com Solr, MySQL Full text e PostgreSQL Full TextFull Text Search com Solr, MySQL Full text e PostgreSQL Full Text
Full Text Search com Solr, MySQL Full text e PostgreSQL Full TextRodrigo Urubatan
 
Ruby para programadores java
Ruby para programadores javaRuby para programadores java
Ruby para programadores javaRodrigo Urubatan
 
Treinamento html5, css e java script apresentado na HP
Treinamento html5, css e java script apresentado na HPTreinamento html5, css e java script apresentado na HP
Treinamento html5, css e java script apresentado na HPRodrigo Urubatan
 
Ruby on rails impressione a você mesmo, seu chefe e seu cliente
Ruby on rails  impressione a você mesmo, seu chefe e seu clienteRuby on rails  impressione a você mesmo, seu chefe e seu cliente
Ruby on rails impressione a você mesmo, seu chefe e seu clienteRodrigo Urubatan
 
Aplicações Hibridas com Phonegap e HTML5
Aplicações Hibridas com Phonegap e HTML5Aplicações Hibridas com Phonegap e HTML5
Aplicações Hibridas com Phonegap e HTML5Rodrigo Urubatan
 
Git presentation to some coworkers some time ago
Git presentation to some coworkers some time agoGit presentation to some coworkers some time ago
Git presentation to some coworkers some time agoRodrigo Urubatan
 

Más de Rodrigo Urubatan (20)

Ruby code smells
Ruby code smellsRuby code smells
Ruby code smells
 
Data science in ruby is it possible? is it fast? should we use it?
Data science in ruby is it possible? is it fast? should we use it?Data science in ruby is it possible? is it fast? should we use it?
Data science in ruby is it possible? is it fast? should we use it?
 
Data science in ruby, is it possible? is it fast? should we use it?
Data science in ruby, is it possible? is it fast? should we use it?Data science in ruby, is it possible? is it fast? should we use it?
Data science in ruby, is it possible? is it fast? should we use it?
 
TDC2017 - POA - Aprendendo a usar Xamarin para desenvolver aplicações moveis ...
TDC2017 - POA - Aprendendo a usar Xamarin para desenvolver aplicações moveis ...TDC2017 - POA - Aprendendo a usar Xamarin para desenvolver aplicações moveis ...
TDC2017 - POA - Aprendendo a usar Xamarin para desenvolver aplicações moveis ...
 
Your first game with unity3d framework
Your first game with unity3d frameworkYour first game with unity3d framework
Your first game with unity3d framework
 
Tdc Floripa 2017 - 8 falácias da programação distribuída
Tdc Floripa 2017 -  8 falácias da programação distribuídaTdc Floripa 2017 -  8 falácias da programação distribuída
Tdc Floripa 2017 - 8 falácias da programação distribuída
 
Rubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDDRubyconf2016 - Solving communication problems in distributed teams with BDD
Rubyconf2016 - Solving communication problems in distributed teams with BDD
 
resolvendo problemas de comunicação em equipes distribuídas com bdd
resolvendo problemas de comunicação em equipes distribuídas com bddresolvendo problemas de comunicação em equipes distribuídas com bdd
resolvendo problemas de comunicação em equipes distribuídas com bdd
 
vantagens e desvantagens de trabalhar remoto
vantagens e desvantagens de trabalhar remotovantagens e desvantagens de trabalhar remoto
vantagens e desvantagens de trabalhar remoto
 
Using BDD to Solve communication problems
Using BDD to Solve communication problemsUsing BDD to Solve communication problems
Using BDD to Solve communication problems
 
TDC2015 Porto Alegre - Interfaces ricas com Rails e React.JS
TDC2015  Porto Alegre - Interfaces ricas com Rails e React.JSTDC2015  Porto Alegre - Interfaces ricas com Rails e React.JS
TDC2015 Porto Alegre - Interfaces ricas com Rails e React.JS
 
Interfaces ricas com Rails e React.JS @ Rubyconf 2015
Interfaces ricas com Rails e React.JS @ Rubyconf 2015Interfaces ricas com Rails e React.JS @ Rubyconf 2015
Interfaces ricas com Rails e React.JS @ Rubyconf 2015
 
TDC São Paulo 2015 - Interfaces Ricas com Rails e React.JS
TDC São Paulo 2015  - Interfaces Ricas com Rails e React.JSTDC São Paulo 2015  - Interfaces Ricas com Rails e React.JS
TDC São Paulo 2015 - Interfaces Ricas com Rails e React.JS
 
Full Text Search com Solr, MySQL Full text e PostgreSQL Full Text
Full Text Search com Solr, MySQL Full text e PostgreSQL Full TextFull Text Search com Solr, MySQL Full text e PostgreSQL Full Text
Full Text Search com Solr, MySQL Full text e PostgreSQL Full Text
 
Ruby para programadores java
Ruby para programadores javaRuby para programadores java
Ruby para programadores java
 
Treinamento html5, css e java script apresentado na HP
Treinamento html5, css e java script apresentado na HPTreinamento html5, css e java script apresentado na HP
Treinamento html5, css e java script apresentado na HP
 
Ruby on rails impressione a você mesmo, seu chefe e seu cliente
Ruby on rails  impressione a você mesmo, seu chefe e seu clienteRuby on rails  impressione a você mesmo, seu chefe e seu cliente
Ruby on rails impressione a você mesmo, seu chefe e seu cliente
 
Mini curso rails 3
Mini curso rails 3Mini curso rails 3
Mini curso rails 3
 
Aplicações Hibridas com Phonegap e HTML5
Aplicações Hibridas com Phonegap e HTML5Aplicações Hibridas com Phonegap e HTML5
Aplicações Hibridas com Phonegap e HTML5
 
Git presentation to some coworkers some time ago
Git presentation to some coworkers some time agoGit presentation to some coworkers some time ago
Git presentation to some coworkers some time ago
 

Último

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

2018 the conf put git to work - increase the quality of your rails project and let git do the boring work for you

  • 1. Put Git to work increase the quality of your Rails project, and let git do the boring work for you
  • 2.
  • 3. Rodrigo Urubatan ▶ rodrigo@urubatan.com.br ▶ http://twitter.com/urubatan ▶ http://github.com/urubatan ▶ http://linkedin.com/in/urubatan ▶ http://sobrecodigo.com
  • 4. 5 ways git can help deploy your rails application 1 – check every commit follow company standards 2 – identify where each commit come from 3 – make sure at least the changed files tests run before pushing code 4 – start CI build after pushing the code 5 – 2 different approaches to git push your deploy after the ci build succeded
  • 5. There is a lot of boring manual work to do before each deploy! Check code against standards Pretty format commit messages Run tests for the files you changed to speed up development Start CI builds Start deployments Compile assets Run migrations when needed Install npm modules Reload application servers
  • 7. Git can help! Commit Check standards Format message Push code Run tests (locally) Start CI process Pull code Bundle install Yarn install Start deploy Npm install Bundle install Db migrate Restart service(s)
  • 8. Putting it to work! Codding standards Git pre-commit hook Formatting commit message Git prepare-commit-msg hook Running tests Git pre-push hook Firing CI build Git post-receive hook Automatic deployment Git post-receive hook Or Git post-merge hook
  • 9. I had one (more than one) evil coworker that didn’t follow any company standards This Photo by Unknown Author is licensed under CC BY
  • 10. How to fight the Evil Coworker who does not follow good practices? This Photo by Unknown Author is licensed under CC BY-SA
  • 11. rubocode + .git/hooks/pre-commit #!/bin/sh echo "Checking commit" if git rev-parse --verify HEAD >/dev/null 2>&1 then against=HEAD else # Initial commit: diff against an empty tree object against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 fi # If you want to allow non-ASCII filenames set this variable to true. rubocop -R `git diff --cached --name-only $against` if [ "$?" != "0" ]; then cat <<EOF pretty Failed!! message!! EOF exit 1 fi
  • 12. I found a commit and did not know where it came from This Photo by Unknown Author is licensed under CC BY
  • 13. Formatting commit messages #!/bin/bash BRANCH_NAME=$(git symbolic-ref --short HEAD) BRANCH_NAME="${BRANCH_NAME##*/}" BRANCH_IN_COMMIT=$(grep -c "[$BRANCH_NAME]" $1) if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1 fi
  • 14. Life is too short to test before sharing my code!
  • 15. Run your tests before pushing the code! #!/usr/bin/env ruby branch_name=`git symbolic-ref -q HEAD` branch_name = branch_name.gsub('refs/heads/', '').strip changed_files = `git diff --name-only #{ARGV[0]}/#{branch_name}`.split("n").map(& :strip).select{|n| n =~ /.rb$/} #run the file specific test test_files = changed_files.map do |name| if name =~ /^app/ name.gsub('app/', 'test/').gsub(/.rb$/, '_test.rb') elsif name =~ /^test/ name else nil end end.reject(&:nil?).uniq #abort if there is a test missing if !test_files.reject{|n| File.exists?(n)}.empty? puts %Q{ Aborting push because there are missing test files: #{test_files.reject{|n| File.exists?(n)}} } exit 1 end #if there are config files changes, run all tests if !changed_files.select{|n| n =~ /^config/}.empty? test_files = '' end system('git stash') result = system("rails test #{test_files.join(' ')}") system('git stash apply') unless result puts %Q{ Aborting push due to failed tests } exit 1 end
  • 16. Trick’em into using your perfect hooks This Photo by Unknown Author is licensed under CC BY-NC-ND
  • 17. And the evil trick! ▶ npm i shared-git-hooks --save-dev or yarn add shared-git-hooks ▶ Add your git hooks (with or without extension) to the hooks directory in your project
  • 18. Too much automation? This Photo by Unknown Author is licensed under CC BY-NC-SA
  • 19. Found out you need another gem or npm module when you decide to do some work in the airplane? This Photo by Unknown Author is licensed under CC BY-NC-SA
  • 21. Continuous Integration This Photo by Unknown Author is licensed under CC BY-SA
  • 22.
  • 24. Firing CI Build ▶.git/hooks/post-receive with a curl to your CI server ▶Github integrated CI servers (github version of the above)
  • 25. Jenkins curl -X POST http://username:user_api_token@your- jenkins.com/job/JobName/build?token=build_trigger_api_token
  • 26. TravisCI body='{ "request": { "branch":"master" }}' curl -s -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Travis-API-Version: 3" -H "Authorization: token xxxxxx" -d "$body" https://api.travis-ci.com/repo/mycompany%2Fmyrepo/requests
  • 27. TeamCity curl -X POST -u apiuser:apipassword -d '<build><buildType id="SpringPetclinic_Build"/></build>' http://localhost:8111/httpAuth/app/rest/buildQueue --header "Content-Type: application/xml" -H "Accept: application/json"
  • 28. Bamboo export BAMBOO_USER=foo export BAMBOO_PASS=bar export PROJECT_NAME=TST export PLAN_NAME=DMY export STAGE_NAME=JOB1 curl --user $BAMBOO_USER:$BAMBOO_PASS -X POST -d "$STAGE_NAME&ExecuteAllStages" http://mybamboohost:8085/rest/api/latest/queue/$PROJECT_NAME- $PLAN_NAME
  • 29.
  • 30. Automatic Deployment – Heroku Recipe 1 server 1 bare repository 1 simple script 1 deployment repository/path
  • 31. My goal with this approach is to do this ▶ git remote add production user@server:myapp.git ▶ Git push production master This Just Deployed my code to production!
  • 32. Git Bare Repository ▶ mkdir myapp.git ▶ cd myapp.git && git init --bare ▶ vi hooks/post-receive
  • 33. myapp.git/hooks/post-receive #!/bin/bash while read oldrev newrev ref do branch_received=`echo $ref | cut -d/ -f3` echo "Deploying branch $branch_received" /bin/bash --login -- <<__EOF__ cd /home/urubatan/projects/deployedapp git fetch git checkout -f $branch_received git pull yarn install bundle install rails db:migrate rails assets:precompile touch tmp/restart.txt __EOF__ done
  • 34. Automatic Deployment – git pull style (post-merge hook) #!/bin/bash bundle install yarn install rails db:migrate rails assets:precompile touch tmp/restart.txt
  • 35. Do you feel you need to track all that deploys? This Photo by Unknown Author is licensed under CC BY-SA
  • 36. git-deploy ▶ https://github.com/git-deploy/git-deploy ▶ git deploy start (you can git deploy abort if needed) ▶ Merge all feature branches that need deployment ▶ git deploy sync ▶ Push that to all your servers (maybe using our Heroku strategy?) ▶ git deploy finish ▶ Now you can use the git-deploy script to list all deployments, or go back to any one of them!
  • 38. Rodrigo Urubatan ▶ I help ruby developers to use the best tools for each job so they can solve hard problems, with less bugs and have more free time. ▶ rodrigo@urubatan.com.br ▶ http://twitter.com/urubatan ▶ http://bit.ly/weekly_rails_tips ▶ http://github.com/urubatan ▶ http://linkedin.com/in/urubatan ▶ http://sobrecodigo.com
  • 39. Whats next? A git ebook! http://bit.ly/weekly_rails_tips