SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
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! :)

Weitere ähnliche Inhalte

Was ist angesagt?

Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year laterChristian Ortner
 
Getting Started with Capistrano
Getting Started with CapistranoGetting Started with Capistrano
Getting Started with CapistranoLaunchAny
 
Git, gitHub, Azure and Visual Studio
Git, gitHub, Azure and Visual StudioGit, gitHub, Azure and Visual Studio
Git, gitHub, Azure and Visual StudioSalvatore Sorrentino
 
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 Plain Concepts
 
Deployment with capistrano
Deployment with capistranoDeployment with capistrano
Deployment with capistranosagar junnarkar
 
Test Kitchen and Infrastructure as Code
Test Kitchen and Infrastructure as CodeTest Kitchen and Infrastructure as Code
Test Kitchen and Infrastructure as CodeCybera Inc.
 
Eventful Email in Ruby
Eventful Email in RubyEventful Email in Ruby
Eventful Email in Rubyhassox
 
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 BuildAjinkya Dubey
 
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 projectCodium
 
Rails 勉強会#3
Rails 勉強会#3Rails 勉強会#3
Rails 勉強会#3masami ito
 
No Hugging, No Learning
No Hugging, No LearningNo Hugging, No Learning
No Hugging, No LearningOlaf Alders
 
install s3cmd in Linux
install s3cmd in Linuxinstall s3cmd in Linux
install s3cmd in Linuxlinuxdady
 
Newgenlib Installation on Ubuntu 12.04
Newgenlib Installation on Ubuntu 12.04Newgenlib Installation on Ubuntu 12.04
Newgenlib Installation on Ubuntu 12.04Rajendra Singh
 
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
 

Was ist angesagt? (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?
 

Ähnlich wie Deploy node.js app with capistrano

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 waySylvain Rayé
 
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 IOded Sagir
 
Magento 2 Development
Magento 2 DevelopmentMagento 2 Development
Magento 2 DevelopmentDuke Dao
 
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.pdfShaiAlmog1
 
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 EC2benjaminwootton
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy Systemadrian_nye
 
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 10Maurício Linhares
 
Aucklug slides - desktop tips and tricks
Aucklug slides - desktop tips and tricksAucklug slides - desktop tips and tricks
Aucklug slides - desktop tips and tricksGlen Ogilvie
 
DevOpsDays Amsterdam Cosmic workshop
DevOpsDays Amsterdam Cosmic workshopDevOpsDays Amsterdam Cosmic workshop
DevOpsDays Amsterdam Cosmic workshopRemi Bergsma
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby TeamArto Artnik
 
Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Yury Pliashkou
 
Kubernetes laravel and kubernetes
Kubernetes   laravel and kubernetesKubernetes   laravel and kubernetes
Kubernetes laravel and kubernetesWilliam Stewart
 
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 CloneVEXXHOST Private Cloud
 
Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with CapistranoRamazan K
 
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 workshopleffen
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Kürzlich hochgeladen (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 

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! :)