SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
Deploy Node.js app with
Capistrano
Gergely Nemeth
Capistrano
Gergely Nemeth
● utility and framework for executing commands in
parallel on multiple remote machines
● via SSH
● definable tasks, which can be applied to machines in
certain roles
● automate deploys
● open source: https://github.com/capistrano/capistrano
Get Capistrano
Gergely Nemeth
1. install Ruby and RubyGems
2. install Capistrano
gem install capistrano
3. install Capistrano extensions
gem install capistrano-ext
All set, let’s prepare our
project!
Gergely Nemeth
Prepare our project
Gergely Nemeth
Navigate to your project’s root, then
capify .
This will create a Capfile and a config folder with a
deploy.rb in it.
● deploy.rb: contains our deploy script
● Capfile: contains our recipes (so it can hold
multiple deploy scripts)
Prepare our server(s)
Gergely Nemeth
1. Make sure, you can login via SSH to your destination
servers
2. We will use forever, make sure, it is installed on your
system
npm install forever -g
Create our recipe
Gergely Nemeth
The default deploy.rb should look like something like
this:
set :application, "set your application name here"
set :repository, "set your repository location here"
# set :scm, :git # You can set :scm explicitly or Capistrano will make
an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`,
`perforce`, `subversion` or `none`
role :web, "your web-server here" # Your HTTP
server, Apache/etc
role :app, "your app-server here" # This may
be the same as your `Web` server
role :db, "your primary db-server here", :primary => true # This is
where Rails migrations will run
role :db, "your slave db-server here"
Create our recipe #2
Gergely Nemeth
Set up server access:
set :user, "ec2-user"
set :use_sudo, false
role :app, "IP_ADDRESS" #multiple address can be added here
#make sure the same SSH key is used on
#every server
In this example, we will use our ssh keys (and forward it
to the server) to access our git repository, to do this, add
the following line to your deploy.rb file:
set :ssh_options, { :forward_agent => true }
Set up your git access:
set :repository, "LINK_TO_YOUR_REPO"
set :branch, "master"
Create our recipe #3
Gergely Nemeth
Add deploy hooks:
namespace :deploy do
desc "Stop Forever"
task :stop do
run "/home/ec2-user/.nvm/v0.10.15/bin/forever stopall; true"
end
desc "Start Forever"
task :start, :on_error => :continue do
run "cd #{current_path} && /home/ec2-user/.nvm/v0.10.15/bin/forever
start app.js"
end
desc "Restart Forever"
task :restart do
stop
sleep 5
start
end
desc "Check required packages and install if packages are not installed"
task :install_packages do
run "cd #{release_path} && bower install"
run "cd #{release_path} && /home/ec2-user/.nvm/v0.10.15/bin/npm
install --production --loglevel warn"
end
end
Create our recipe #4
Gergely Nemeth
Set deploy destination:
set :deploy_to, "/home/ec2-user/myawesomeproject"
Set server environment
set :default_environment, {
'NODE_ENV' => 'production'
}
Validate our recipe from the command line:
cap deploy:setup
This command will SSH into our server and create the
deploy structure in the folder we specified in: :deploy_to.
Do not proceed until it is not successful.
Go live!
Gergely Nemeth
1. Make sure, everything is set
cap deploy:check
2. Deploy
cap deploy
3. If something fails, Capistrano will automatically do a
rollback
4. You can do a rollback to specific version with:
cap deploy:VERSION_NUMBER
Or to the latest with
cap deploy:rollback
The full recipe
Gergely Nemeth
The full recipe can be downloaded from:
https://gist.github.com/anonymous/6249142
Have fun trying it out! :)

Contenu connexe

Tendances

Eventful Email in Ruby
Eventful Email in RubyEventful Email in Ruby
Eventful Email in Ruby
hassox
 
How did puppet change our system's life?
How did puppet change our system's life?How did puppet change our system's life?
How did puppet change our system's life?
Hung Phung Dac
 

Tendances (20)

Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year later
 
Getting Started with Capistrano
Getting Started with CapistranoGetting Started with Capistrano
Getting Started with Capistrano
 
Git, gitHub, Azure and Visual Studio
Git, gitHub, Azure and Visual StudioGit, gitHub, Azure and Visual Studio
Git, gitHub, Azure and Visual Studio
 
earthquake.gem
earthquake.gemearthquake.gem
earthquake.gem
 
Chef training Day4
Chef training Day4Chef training Day4
Chef training Day4
 
Depende, ¿de qué depende? - Plain Concepts Dev Day
Depende, ¿de qué depende? - Plain Concepts Dev Day Depende, ¿de qué depende? - Plain Concepts Dev Day
Depende, ¿de qué depende? - Plain Concepts Dev Day
 
Deployment with capistrano
Deployment with capistranoDeployment with capistrano
Deployment with capistrano
 
Test Kitchen and Infrastructure as Code
Test Kitchen and Infrastructure as CodeTest Kitchen and Infrastructure as Code
Test Kitchen and Infrastructure as Code
 
Eventful Email in Ruby
Eventful Email in RubyEventful Email in Ruby
Eventful Email in Ruby
 
Chef training - Day2
Chef training - Day2Chef training - Day2
Chef training - Day2
 
Sprockets
SprocketsSprockets
Sprockets
 
Swagman - Converting Postman Collection to Swagger Build
Swagman - Converting Postman Collection to Swagger BuildSwagman - Converting Postman Collection to Swagger Build
Swagman - Converting Postman Collection to Swagger Build
 
Learned lessons in a real world project
Learned lessons in a real world projectLearned lessons in a real world project
Learned lessons in a real world project
 
Puppet Data Mining
Puppet Data MiningPuppet Data Mining
Puppet Data Mining
 
Rails 勉強会#3
Rails 勉強会#3Rails 勉強会#3
Rails 勉強会#3
 
No Hugging, No Learning
No Hugging, No LearningNo Hugging, No Learning
No Hugging, No Learning
 
install s3cmd in Linux
install s3cmd in Linuxinstall s3cmd in Linux
install s3cmd in Linux
 
Newgenlib Installation on Ubuntu 12.04
Newgenlib Installation on Ubuntu 12.04Newgenlib Installation on Ubuntu 12.04
Newgenlib Installation on Ubuntu 12.04
 
Hacking our way to geembo
Hacking our way to geemboHacking our way to geembo
Hacking our way to geembo
 
How did puppet change our system's life?
How did puppet change our system's life?How did puppet change our system's life?
How did puppet change our system's life?
 

Similaire à Deploy node.js app with capistrano

Similaire à Deploy node.js app with capistrano (20)

Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
 
The Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session IThe Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session I
 
Capistrano
CapistranoCapistrano
Capistrano
 
Magento 2 Development
Magento 2 DevelopmentMagento 2 Development
Magento 2 Development
 
Setting Up a Cloud Server - Part 3 - Transcript.pdf
Setting Up a Cloud Server - Part 3 - Transcript.pdfSetting Up a Cloud Server - Part 3 - Transcript.pdf
Setting Up a Cloud Server - Part 3 - Transcript.pdf
 
Capistrano Overview
Capistrano OverviewCapistrano Overview
Capistrano Overview
 
Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2Configuring Your First Hadoop Cluster On EC2
Configuring Your First Hadoop Cluster On EC2
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
Deploying your rails application to a clean ubuntu 10
Deploying your rails application to a clean ubuntu 10Deploying your rails application to a clean ubuntu 10
Deploying your rails application to a clean ubuntu 10
 
Aucklug slides - desktop tips and tricks
Aucklug slides - desktop tips and tricksAucklug slides - desktop tips and tricks
Aucklug slides - desktop tips and tricks
 
Alta disponibilidad en GNU/Linux
Alta disponibilidad en GNU/LinuxAlta disponibilidad en GNU/Linux
Alta disponibilidad en GNU/Linux
 
DevOpsDays Amsterdam Cosmic workshop
DevOpsDays Amsterdam Cosmic workshopDevOpsDays Amsterdam Cosmic workshop
DevOpsDays Amsterdam Cosmic workshop
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11
 
Kubernetes laravel and kubernetes
Kubernetes   laravel and kubernetesKubernetes   laravel and kubernetes
Kubernetes laravel and kubernetes
 
How To Install GitLab As Your Private GitHub Clone
How To Install GitLab As Your Private GitHub CloneHow To Install GitLab As Your Private GitHub Clone
How To Install GitLab As Your Private GitHub Clone
 
Nodejs in Production
Nodejs in ProductionNodejs in Production
Nodejs in Production
 
Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with Capistrano
 
Docker
DockerDocker
Docker
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshop
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Dernier (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
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...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
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
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Deploy node.js app with capistrano

  • 1. Deploy Node.js app with Capistrano Gergely Nemeth
  • 2. Capistrano Gergely Nemeth ● utility and framework for executing commands in parallel on multiple remote machines ● via SSH ● definable tasks, which can be applied to machines in certain roles ● automate deploys ● open source: https://github.com/capistrano/capistrano
  • 3. Get Capistrano Gergely Nemeth 1. install Ruby and RubyGems 2. install Capistrano gem install capistrano 3. install Capistrano extensions gem install capistrano-ext
  • 4. All set, let’s prepare our project! Gergely Nemeth
  • 5. Prepare our project Gergely Nemeth Navigate to your project’s root, then capify . This will create a Capfile and a config folder with a deploy.rb in it. ● deploy.rb: contains our deploy script ● Capfile: contains our recipes (so it can hold multiple deploy scripts)
  • 6. Prepare our server(s) Gergely Nemeth 1. Make sure, you can login via SSH to your destination servers 2. We will use forever, make sure, it is installed on your system npm install forever -g
  • 7. Create our recipe Gergely Nemeth The default deploy.rb should look like something like this: set :application, "set your application name here" set :repository, "set your repository location here" # set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names # Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none` role :web, "your web-server here" # Your HTTP server, Apache/etc role :app, "your app-server here" # This may be the same as your `Web` server role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run role :db, "your slave db-server here"
  • 8. Create our recipe #2 Gergely Nemeth Set up server access: set :user, "ec2-user" set :use_sudo, false role :app, "IP_ADDRESS" #multiple address can be added here #make sure the same SSH key is used on #every server In this example, we will use our ssh keys (and forward it to the server) to access our git repository, to do this, add the following line to your deploy.rb file: set :ssh_options, { :forward_agent => true } Set up your git access: set :repository, "LINK_TO_YOUR_REPO" set :branch, "master"
  • 9. Create our recipe #3 Gergely Nemeth Add deploy hooks: namespace :deploy do desc "Stop Forever" task :stop do run "/home/ec2-user/.nvm/v0.10.15/bin/forever stopall; true" end desc "Start Forever" task :start, :on_error => :continue do run "cd #{current_path} && /home/ec2-user/.nvm/v0.10.15/bin/forever start app.js" end desc "Restart Forever" task :restart do stop sleep 5 start end desc "Check required packages and install if packages are not installed" task :install_packages do run "cd #{release_path} && bower install" run "cd #{release_path} && /home/ec2-user/.nvm/v0.10.15/bin/npm install --production --loglevel warn" end end
  • 10. Create our recipe #4 Gergely Nemeth Set deploy destination: set :deploy_to, "/home/ec2-user/myawesomeproject" Set server environment set :default_environment, { 'NODE_ENV' => 'production' } Validate our recipe from the command line: cap deploy:setup This command will SSH into our server and create the deploy structure in the folder we specified in: :deploy_to. Do not proceed until it is not successful.
  • 11. Go live! Gergely Nemeth 1. Make sure, everything is set cap deploy:check 2. Deploy cap deploy 3. If something fails, Capistrano will automatically do a rollback 4. You can do a rollback to specific version with: cap deploy:VERSION_NUMBER Or to the latest with cap deploy:rollback
  • 12. The full recipe Gergely Nemeth The full recipe can be downloaded from: https://gist.github.com/anonymous/6249142 Have fun trying it out! :)