SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
Capistrano
Deploy Magento Project
& others...
By Sylvain Rayé

Zürich Mage Hackathon - 10.03.2013
EGO PAGE ;-)
Sylvain Rayé
● CTO & Senior Web Developer for rissip GmbH
● Computer Engineer Information Systems
● Certified Magento Developer

http://www.sylvainraye.com
http://www.diglin.com
@sylvainraye
@diglin_com
The basics
Capistrano
● Deployment framework for web applications
○ Ruby On Rails applications
○ PHP applications (need to overwrite few core tasks)

● Purpose
○
○
○
○
○

Quick code deployment (full or partial)
Recurring process/tasks
Multi Stages
Multi Servers
Execute command on server (local or remote)

● NOT
○ Completely ready to use
Definitions 1/2
● Task
○ Execute a set of command(s) on server e.g. cap deploy
desc "Dummy task"
task :dummy do
puts 'I am a dummy task!!!'
end

● Role
○ Multi Servers role: DB1, DB2, Web Server, LDAP, ...
○ Roles are applied to a task (default is all roles)
roles :web, "192.168.0.1", "www.domain.com"'
roles :db, "192.168.0.2", :primary => true
desc "I run a db command on the db server"
task :dummy, :roles => :db do
run "mysql -u dummy -pdummy -e 'SHOW DATABASES;' "
end
Definitions 2/2
● Namespace
○ Basic: "deploy:" - Custom: e.g. "tools:", "config:"
namespace :tools do
desc "Backup task"
task :backup do
puts 'I should do a backup but I am a lazy boy!!!'
end
end

● Hook
○ before "anytask" - after "anytask"
before "deploy", "tools:backup"
after "deploy" do
puts "Bravo! You deployed your code!!!"
end

● Recipe
○ Bundle of tasks gathered in a file. e.g. deploy.rb
DISPATCH Behavior
deploy:setup

1rst deployment prepare setup on the server(s)

deploy:default

Deploys your project

deploy:update

Deploys your project and create symlink

deploy:update_code
Strategy.deploy!

Copies your project to the remote server
deploy_via (local: copy, remote: checkout, export,
remote_cache)

deploy:finalize_update

[internal] Touches up the released code

deploy:create_symlink

Updates the symlink to the most recent release

deploy:restart

Do nothing - To overwrite if needed

Source: https://github.com/capistrano/capistrano/wiki/2.x-Default-Deployment-Behaviour
REMOTE DEPLOYMENT STRUCTURE
[deploy_to] (e.g. /www-data/hosts/www.domain.com/capiroot/apps/magento)
[deploy_to]/releases
[deploy_to]/releases/20130310001122
[deploy_to]/releases/20130105000010
[deploy_to]/releases/...
[deploy_to]/shared
[deploy_to]/shared/media
[deploy_to]/shared/var
[deploy_to]/shared/...
[deploy_to]/current -> [deploy_to]/releases/20130310001122
Installation & Use
Installation
● Requirements:
○ Version Source Control (git, svn, ...) - Local: Ruby, Gem
Server: executed bin, same user/pass on all server, SSH

● Installation
○ gem install capistrano
○ Binaries: capify and cap

● Init a project
○ cd myproject && capify .
○ 2 files created
■ Capfile: bootstrap
■ config/deploy.rb: recipe, config, hooks, ...
Structure of LOCAL project
|_MyProject
|__Capfile
# Capistrano bootstrap
|__config
| |__deploy.rb
# Recipe, global config
|__app
|__cron.php
|__index.php
|__media (set it as shared on remote server)
|__RELEASE_NOTES.txt
|__shell
|__skin
|__js
|__var (set it as shared on remote server)
|__...
-
DEFAULT Capile / deploy.rb files
● Capfile
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
# load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks

● config/deploy.rb
require 'capistrano/ext/multistage'
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"
Default Tasks
> cd myproject
> cap -vT
cap deploy
# Deploys your project.
cap deploy:check
# Test deployment dependencies.
cap deploy:cleanup
# Clean up old releases.
cap deploy:cold
# Deploys and starts a `cold' application.
cap deploy:create_symlink # Updates the symlink to the most recently deployed version.
cap deploy:finalize_update # [internal] Touches up the released code.
cap deploy:pending
# Displays the commits since your last deploy.
cap deploy:pending:diff
# Displays the `diff' since your last deploy.
cap deploy:restart
# Blank task exists as a hook into which to install your own environment
cap deploy:rollback
# Rolls back to a previous version and restarts.
cap deploy:rollback:cleanup # [internal] Removes the most recently deployed release.
cap deploy:rollback:code
# Rolls back to the previously deployed version.
cap deploy:rollback:revision # [internal] Points the current symlink at the previous revision.
cap deploy:setup
# Prepares one or more servers for deployment.
cap deploy:start
# Blank task exists as a hook into which to install your own environment
cap deploy:stop
# Blank task exists as a hook into which to install your own environment
cap deploy:update
# Copies your project and updates the symlink.
cap deploy:update_code
# Copies your project to the remote servers.
cap deploy:upload
# Copy files to the currently deployed version.
cap invoke
# Invoke a single command on the remote servers.
cap shell
# Begin an interactive Capistrano session.
Tasks to overwrite for non rails
● deploy:start, deploy:stop, deploy:restart
○ Set them to an empty task (Capistrano v 1.x)

● deploy:migrate, deploy:migrations
○ Set them to an empty task

● deploy:default, deploy:cold
○ Not mandatory: do a redirect to task deploy:update

● deploy:finalize_update
○ e.g. files and folder fix permissions

● Sample code at http://bit.ly/13yukoP
Configure &
Create your own task(s)
COnfigure
● SSH Authentication with keys
○ Otherwise, after each 'cap', password will be asked !
> ssh-keygen -t rsa
> cat ~/.ssh/id_dsa.pub | ssh sylvain@staging.magehackathon.local "cat - >>.ssh/authorized_keys"

● Deploy.rb
set :http_domain, 'staging.magehackathon.local' # local variable
set :location, http_domain
set :user, "sylvain" # SSH user
# set :scm_username, “foo”
# set :use_sudo, false
# set :ssh_options, { :forward_agent => true, :port: 22 }
default_run_options[:pty] = true
set :application, "capistranosimple"
set :keep_releases, 5
set :repository, "adress of my repo" # Git remote repo for example
set :scm, :git # other version control system are also available: e.g. svn
set :branch, "master"
set :deploy_via, :remote_cache # possible values: copy, checkout, remote_cache, export
set :deploy_to, "/www-data/hosts/#{http_domain}/capiroot/apps/#{application}"
role :web, location
# Your web server domain or IP. e.g. Apache or nginx
role :db, location, :primary => true
Create your own code
● VERY Basic knowledge in Ruby
○ To Ruby from PHP: http://bit.ly/Z7y3mn

● Define variable
set :application, "capistranomagento"
set :keep_releases, 5
set :app_shared_dirs, ["/app/etc", "/media", "/var"]

● Create methods, tasks
def remote_file_exists(full_path)
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
end
namespace :tools do
desc "Import sample data with specific information to database. Executed after deploy:setup"
task :import_sample_data, :roles => [:db], :only => { :primary => true } do
....
abort "#{localsamplesqlfile} doesnt exist locally" unless File.exists?( localsamplesqlfile)
if !remote_file_exists("#{shared_path}/shell/#{samplesqlfile}") then
run "mkdir -p #{shared_path}/shell"
upload localsamplesqlfile, "#{shared_path}/shell/#{samplesqlfile}"
end
end
end
Basic CAPISTRANO Action
● run: execute commands on one or more servers
● parallel: execute multiple commands on multiple servers in parallel
● put: store the contents of a file on multiple servers
● get: transfers a file from a single remote server to the local host
● upload: transfers a file or directory from the local host to multiple remote
hosts, in parallel.
● download: transfers a file or directory from multiple remote hosts to the
local host, in parallel.
● capture: executes a command on a single host and returns ("captures") the
output as a string
● stream: very similar to run, but optimized for displaying live streams of
text (like tailed log files) from multiple hosts
Simple Demo
One stage
see code at http://bit.ly/ZS0iYl
Multi Stages
Multi Stages - 1/2
● Without Capistrano Extension
○ A task per stage in config/deploy.rb
task :production do
role :web, "www.capify.org"
set :deploy_to, "/u/apps/#{application}-production/"
set :deploy_via, :remote_cache
after('deploy:create_symlink', 'cache:clear')
end
task :staging do
role :web, "localhost"
set :deploy_to, "/Users/capistrano/Sites/#{application}-staging/"
set :deploy_via, :copy
after('deploy:create_symlink', 'cache:clear', 'mage:enable_profiler')
end

> cap <stagename> <taskname> <optional_parameter>
> cap staging deploy
Multi Stages - 2/2
● With Capistrano Extension (Preferred)
○ A ruby file per stage
■ config/deploy/local.rb - http://bit.ly/161gZ82
■ config/deploy/staging.rb - http://bit.ly/ZdSnDR
■ config/deploy/production.rb - http://bit.ly/ZS8rft
○ Settings in config/deploy.rb
require 'capistrano/ext/multistage'
set :stages, %w(local production staging)
set :default_stage, "staging"
...
> cap <stagename> <taskname> <optional_parameter>
> cap staging deploy:upload FILES=index.php,app/code/local
Structure of LOCAL project
|_MyProject
|__Capfile
# Capistrano bootstrap
|__config
| |__deploy.rb
# Recipes, global config
| |__deploy
# In case of multi stages
|
|__local.rb
# Config, Hook specific to local
|
|__staging.rb
# Config, Hook specific to staging
|
|__production.rb # Config, Hook specific to production
|__index.php
|__skin
|__media (shared)
|__app
|__cron.php
|__js
|__var (shared)
|__RELEASE_NOTES.txt
|__shell
|__...
Simple Demo
Two stages
see code at http://bit.ly/ZS0iYl
Magentify
Magentify a Project
● Install Magentify
○ gem install magentify

● Init a project
○ Same as with Capify
○ > cd myproject && magentify .

● Advantage
○ Some predefined behaviors and tasks
cap mage:cc
# Clear the Magento Cache
cap mage:clean_log
# Clean the Magento logs
cap mage:compiler
# Run the Magento compiler
cap mage:disable
# Disable the Magento install by creating the maintenance.flag in the web root.
cap mage:disable_compiler # Disable the Magento compiler
cap mage:enable
# Enable the Magento stores by removing the maintenance.flag in the web root.
cap mage:enable_compiler # Enable the Magento compiler
cap mage:finalize_update
# Touches up the released code.
cap mage:indexer
# Run the Magento indexer
cap mage:setup
# Prepares one or more servers for deployment of Magento.
Magento Demo
Two stages
see code at http://bit.ly/ZS0iYl
Links
Links
● This presentation and its code
○ http://bit.ly/ZS0iYl

● Capistrano
○ http://capistranorb.com

● Magentify
○ http://bit.ly/ZZSyYa

● PHP deployment with Capistrano
○ http://bit.ly/Z7y3mn
○ http://bit.ly/MzqH9o

● Capistrano GUI
○ https://github.com/joelmoss/strano
THANKS !!!

Weitere ähnliche Inhalte

Was ist angesagt?

Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
It Works On My Machine: Vagrant for Software Development
It Works On My Machine: Vagrant for Software DevelopmentIt Works On My Machine: Vagrant for Software Development
It Works On My Machine: Vagrant for Software DevelopmentCarlos Perez
 
Salt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native ClientSalt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native ClientMayflower GmbH
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Projectxsist10
 
Managing your Drupal project with Composer
Managing your Drupal project with ComposerManaging your Drupal project with Composer
Managing your Drupal project with ComposerMatt Glaman
 
Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePiotr Pelczar
 
"13 ways to run web applications on the Internet" Andrii Shumada
"13 ways to run web applications on the Internet" Andrii Shumada"13 ways to run web applications on the Internet" Andrii Shumada
"13 ways to run web applications on the Internet" Andrii ShumadaFwdays
 
Continuous Integration and Deployment Patterns for Magento
Continuous Integration and Deployment Patterns for MagentoContinuous Integration and Deployment Patterns for Magento
Continuous Integration and Deployment Patterns for MagentoAOE
 
PuppetConf 2016: Deploying Multi-Tier Windows Applications with Application O...
PuppetConf 2016: Deploying Multi-Tier Windows Applications with Application O...PuppetConf 2016: Deploying Multi-Tier Windows Applications with Application O...
PuppetConf 2016: Deploying Multi-Tier Windows Applications with Application O...Puppet
 
Symfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim RomanovskySymfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim Romanovskyphp-user-group-minsk
 
Vagrant move over, here is Docker
Vagrant move over, here is DockerVagrant move over, here is Docker
Vagrant move over, here is DockerNick Belhomme
 
Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Dana Luther
 
Deploying a Pylons app to Google App Engine
Deploying a Pylons app to Google App EngineDeploying a Pylons app to Google App Engine
Deploying a Pylons app to Google App EngineJazkarta, Inc.
 
Converting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaConverting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaDana Luther
 
Meetup C++ Floripa - Conan.io
Meetup C++ Floripa - Conan.ioMeetup C++ Floripa - Conan.io
Meetup C++ Floripa - Conan.ioUilian Ries
 
Terminus, the Pantheon command-line interface
Terminus, the Pantheon command-line interfaceTerminus, the Pantheon command-line interface
Terminus, the Pantheon command-line interfaceJon Peck
 
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
 

Was ist angesagt? (20)

Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
It Works On My Machine: Vagrant for Software Development
It Works On My Machine: Vagrant for Software DevelopmentIt Works On My Machine: Vagrant for Software Development
It Works On My Machine: Vagrant for Software Development
 
Salt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native ClientSalt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native Client
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
Managing your Drupal project with Composer
Managing your Drupal project with ComposerManaging your Drupal project with Composer
Managing your Drupal project with Composer
 
Statyczna analiza kodu PHP
Statyczna analiza kodu PHPStatyczna analiza kodu PHP
Statyczna analiza kodu PHP
 
Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecture
 
"13 ways to run web applications on the Internet" Andrii Shumada
"13 ways to run web applications on the Internet" Andrii Shumada"13 ways to run web applications on the Internet" Andrii Shumada
"13 ways to run web applications on the Internet" Andrii Shumada
 
Drupal Development Tips
Drupal Development TipsDrupal Development Tips
Drupal Development Tips
 
Continuous Integration and Deployment Patterns for Magento
Continuous Integration and Deployment Patterns for MagentoContinuous Integration and Deployment Patterns for Magento
Continuous Integration and Deployment Patterns for Magento
 
PuppetConf 2016: Deploying Multi-Tier Windows Applications with Application O...
PuppetConf 2016: Deploying Multi-Tier Windows Applications with Application O...PuppetConf 2016: Deploying Multi-Tier Windows Applications with Application O...
PuppetConf 2016: Deploying Multi-Tier Windows Applications with Application O...
 
Symfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim RomanovskySymfony Under Control by Maxim Romanovsky
Symfony Under Control by Maxim Romanovsky
 
Taming AEM deployments
Taming AEM deploymentsTaming AEM deployments
Taming AEM deployments
 
Vagrant move over, here is Docker
Vagrant move over, here is DockerVagrant move over, here is Docker
Vagrant move over, here is Docker
 
Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]
 
Deploying a Pylons app to Google App Engine
Deploying a Pylons app to Google App EngineDeploying a Pylons app to Google App Engine
Deploying a Pylons app to Google App Engine
 
Converting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - CascadiaConverting Your Dev Environment to a Docker Stack - Cascadia
Converting Your Dev Environment to a Docker Stack - Cascadia
 
Meetup C++ Floripa - Conan.io
Meetup C++ Floripa - Conan.ioMeetup C++ Floripa - Conan.io
Meetup C++ Floripa - Conan.io
 
Terminus, the Pantheon command-line interface
Terminus, the Pantheon command-line interfaceTerminus, the Pantheon command-line interface
Terminus, the Pantheon command-line interface
 
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
 

Andere mochten auch

Deploy Magento Shops with Capistrano v3
Deploy Magento Shops with Capistrano  v3Deploy Magento Shops with Capistrano  v3
Deploy Magento Shops with Capistrano v3Roman Hutterer
 
Magento: I varnish you
Magento: I varnish youMagento: I varnish you
Magento: I varnish youSylvain Rayé
 
Gastronomía Mexicana
Gastronomía MexicanaGastronomía Mexicana
Gastronomía Mexicanaadisadylu
 
20151012 tourmeaway參與感想
20151012 tourmeaway參與感想20151012 tourmeaway參與感想
20151012 tourmeaway參與感想Jessie Wang
 
Project Portfolio - Raven Dorr
Project Portfolio - Raven DorrProject Portfolio - Raven Dorr
Project Portfolio - Raven DorrRaven Dorr
 
Custom t-shirt, towels and textile
Custom t-shirt, towels and textile Custom t-shirt, towels and textile
Custom t-shirt, towels and textile Lucky Liu
 
Google plus pp
Google plus  ppGoogle plus  pp
Google plus ppmalimido
 
Profile and CV Martin C. Michel
Profile and CV Martin C. MichelProfile and CV Martin C. Michel
Profile and CV Martin C. MichelMartin C. Michel
 
MN Business May 2015
MN Business May 2015MN Business May 2015
MN Business May 2015Doug Killion
 
CALIFORNIA: TOP 10 Fertility Clinics 2016
CALIFORNIA: TOP 10 Fertility Clinics 2016CALIFORNIA: TOP 10 Fertility Clinics 2016
CALIFORNIA: TOP 10 Fertility Clinics 2016M Fe?ikov
 
立委咖電喂簡報(18g0v簡報)
立委咖電喂簡報(18g0v簡報)立委咖電喂簡報(18g0v簡報)
立委咖電喂簡報(18g0v簡報)Jessie Wang
 
Richard G Logan Resume
Richard G Logan ResumeRichard G Logan Resume
Richard G Logan ResumeRichard Logan
 

Andere mochten auch (19)

Deploy Magento Shops with Capistrano v3
Deploy Magento Shops with Capistrano  v3Deploy Magento Shops with Capistrano  v3
Deploy Magento Shops with Capistrano v3
 
Magento: I varnish you
Magento: I varnish youMagento: I varnish you
Magento: I varnish you
 
Gastronomía Mexicana
Gastronomía MexicanaGastronomía Mexicana
Gastronomía Mexicana
 
Ramirez
RamirezRamirez
Ramirez
 
20151012 tourmeaway參與感想
20151012 tourmeaway參與感想20151012 tourmeaway參與感想
20151012 tourmeaway參與感想
 
Project Portfolio - Raven Dorr
Project Portfolio - Raven DorrProject Portfolio - Raven Dorr
Project Portfolio - Raven Dorr
 
Custom t-shirt, towels and textile
Custom t-shirt, towels and textile Custom t-shirt, towels and textile
Custom t-shirt, towels and textile
 
Dalton
DaltonDalton
Dalton
 
Diktat autocad
Diktat autocadDiktat autocad
Diktat autocad
 
MEMS 200704
MEMS 200704MEMS 200704
MEMS 200704
 
Google plus pp
Google plus  ppGoogle plus  pp
Google plus pp
 
6aslidedesign
6aslidedesign6aslidedesign
6aslidedesign
 
Profile and CV Martin C. Michel
Profile and CV Martin C. MichelProfile and CV Martin C. Michel
Profile and CV Martin C. Michel
 
MN Business May 2015
MN Business May 2015MN Business May 2015
MN Business May 2015
 
CALIFORNIA: TOP 10 Fertility Clinics 2016
CALIFORNIA: TOP 10 Fertility Clinics 2016CALIFORNIA: TOP 10 Fertility Clinics 2016
CALIFORNIA: TOP 10 Fertility Clinics 2016
 
立委咖電喂簡報(18g0v簡報)
立委咖電喂簡報(18g0v簡報)立委咖電喂簡報(18g0v簡報)
立委咖電喂簡報(18g0v簡報)
 
Trabajo
TrabajoTrabajo
Trabajo
 
13Afinalportfolio
13Afinalportfolio13Afinalportfolio
13Afinalportfolio
 
Richard G Logan Resume
Richard G Logan ResumeRichard G Logan Resume
Richard G Logan Resume
 

Ähnlich wie Capistrano deploy Magento project in an efficient way

Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with CapistranoRamazan K
 
[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
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby TeamArto Artnik
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Deepak Garg
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOpsОмские ИТ-субботники
 
Deploy made easy (even on Friday)
Deploy made easy (even on Friday)Deploy made easy (even on Friday)
Deploy made easy (even on Friday)Riccardo Bini
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy Systemadrian_nye
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with PuppetKris Buytaert
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleStein Inge Morisbak
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleStein Inge Morisbak
 
Eclipse HandsOn Workshop
Eclipse HandsOn WorkshopEclipse HandsOn Workshop
Eclipse HandsOn WorkshopBastian Feder
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'acorehard_by
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment TacticsIan Barber
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environmentSumedt Jitpukdebodin
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year laterChristian Ortner
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppSmartLogic
 

Ähnlich wie Capistrano deploy Magento project in an efficient way (20)

Control your deployments with Capistrano
Control your deployments with CapistranoControl your deployments with Capistrano
Control your deployments with Capistrano
 
[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
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
 
Deploy made easy (even on Friday)
Deploy made easy (even on Friday)Deploy made easy (even on Friday)
Deploy made easy (even on Friday)
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Zero Downtime Deployment with Ansible
Zero Downtime Deployment with AnsibleZero Downtime Deployment with Ansible
Zero Downtime Deployment with Ansible
 
Eclipse HandsOn Workshop
Eclipse HandsOn WorkshopEclipse HandsOn Workshop
Eclipse HandsOn Workshop
 
Capistrano Overview
Capistrano OverviewCapistrano Overview
Capistrano Overview
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment Tactics
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environment
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year later
 
Practical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails AppPractical Chef and Capistrano for Your Rails App
Practical Chef and Capistrano for Your Rails App
 

Kürzlich hochgeladen

PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServiceRenan Moreira de Oliveira
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxYounusS2
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.francesco barbera
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum ComputingGDSC PJATK
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Spring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdfSpring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdfAnna Loughnan Colquhoun
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIUdaiappa Ramachandran
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdfJamie (Taka) Wang
 

Kürzlich hochgeladen (20)

PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer ServicePicPay - GenAI Finance Assistant - ChatGPT for Customer Service
PicPay - GenAI Finance Assistant - ChatGPT for Customer Service
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.Digital magic. A small project for controlling smart light bulbs.
Digital magic. A small project for controlling smart light bulbs.
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum Computing
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Spring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdfSpring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdf
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AI
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
 

Capistrano deploy Magento project in an efficient way

  • 1. Capistrano Deploy Magento Project & others... By Sylvain Rayé Zürich Mage Hackathon - 10.03.2013
  • 2. EGO PAGE ;-) Sylvain Rayé ● CTO & Senior Web Developer for rissip GmbH ● Computer Engineer Information Systems ● Certified Magento Developer http://www.sylvainraye.com http://www.diglin.com @sylvainraye @diglin_com
  • 4. Capistrano ● Deployment framework for web applications ○ Ruby On Rails applications ○ PHP applications (need to overwrite few core tasks) ● Purpose ○ ○ ○ ○ ○ Quick code deployment (full or partial) Recurring process/tasks Multi Stages Multi Servers Execute command on server (local or remote) ● NOT ○ Completely ready to use
  • 5. Definitions 1/2 ● Task ○ Execute a set of command(s) on server e.g. cap deploy desc "Dummy task" task :dummy do puts 'I am a dummy task!!!' end ● Role ○ Multi Servers role: DB1, DB2, Web Server, LDAP, ... ○ Roles are applied to a task (default is all roles) roles :web, "192.168.0.1", "www.domain.com"' roles :db, "192.168.0.2", :primary => true desc "I run a db command on the db server" task :dummy, :roles => :db do run "mysql -u dummy -pdummy -e 'SHOW DATABASES;' " end
  • 6. Definitions 2/2 ● Namespace ○ Basic: "deploy:" - Custom: e.g. "tools:", "config:" namespace :tools do desc "Backup task" task :backup do puts 'I should do a backup but I am a lazy boy!!!' end end ● Hook ○ before "anytask" - after "anytask" before "deploy", "tools:backup" after "deploy" do puts "Bravo! You deployed your code!!!" end ● Recipe ○ Bundle of tasks gathered in a file. e.g. deploy.rb
  • 7. DISPATCH Behavior deploy:setup 1rst deployment prepare setup on the server(s) deploy:default Deploys your project deploy:update Deploys your project and create symlink deploy:update_code Strategy.deploy! Copies your project to the remote server deploy_via (local: copy, remote: checkout, export, remote_cache) deploy:finalize_update [internal] Touches up the released code deploy:create_symlink Updates the symlink to the most recent release deploy:restart Do nothing - To overwrite if needed Source: https://github.com/capistrano/capistrano/wiki/2.x-Default-Deployment-Behaviour
  • 8. REMOTE DEPLOYMENT STRUCTURE [deploy_to] (e.g. /www-data/hosts/www.domain.com/capiroot/apps/magento) [deploy_to]/releases [deploy_to]/releases/20130310001122 [deploy_to]/releases/20130105000010 [deploy_to]/releases/... [deploy_to]/shared [deploy_to]/shared/media [deploy_to]/shared/var [deploy_to]/shared/... [deploy_to]/current -> [deploy_to]/releases/20130310001122
  • 10. Installation ● Requirements: ○ Version Source Control (git, svn, ...) - Local: Ruby, Gem Server: executed bin, same user/pass on all server, SSH ● Installation ○ gem install capistrano ○ Binaries: capify and cap ● Init a project ○ cd myproject && capify . ○ 2 files created ■ Capfile: bootstrap ■ config/deploy.rb: recipe, config, hooks, ...
  • 11. Structure of LOCAL project |_MyProject |__Capfile # Capistrano bootstrap |__config | |__deploy.rb # Recipe, global config |__app |__cron.php |__index.php |__media (set it as shared on remote server) |__RELEASE_NOTES.txt |__shell |__skin |__js |__var (set it as shared on remote server) |__... -
  • 12. DEFAULT Capile / deploy.rb files ● Capfile load 'deploy' # Uncomment if you are using Rails' asset pipeline # load 'deploy/assets' load 'config/deploy' # remove this line to skip loading any of the default tasks ● config/deploy.rb require 'capistrano/ext/multistage' 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"
  • 13. Default Tasks > cd myproject > cap -vT cap deploy # Deploys your project. cap deploy:check # Test deployment dependencies. cap deploy:cleanup # Clean up old releases. cap deploy:cold # Deploys and starts a `cold' application. cap deploy:create_symlink # Updates the symlink to the most recently deployed version. cap deploy:finalize_update # [internal] Touches up the released code. cap deploy:pending # Displays the commits since your last deploy. cap deploy:pending:diff # Displays the `diff' since your last deploy. cap deploy:restart # Blank task exists as a hook into which to install your own environment cap deploy:rollback # Rolls back to a previous version and restarts. cap deploy:rollback:cleanup # [internal] Removes the most recently deployed release. cap deploy:rollback:code # Rolls back to the previously deployed version. cap deploy:rollback:revision # [internal] Points the current symlink at the previous revision. cap deploy:setup # Prepares one or more servers for deployment. cap deploy:start # Blank task exists as a hook into which to install your own environment cap deploy:stop # Blank task exists as a hook into which to install your own environment cap deploy:update # Copies your project and updates the symlink. cap deploy:update_code # Copies your project to the remote servers. cap deploy:upload # Copy files to the currently deployed version. cap invoke # Invoke a single command on the remote servers. cap shell # Begin an interactive Capistrano session.
  • 14. Tasks to overwrite for non rails ● deploy:start, deploy:stop, deploy:restart ○ Set them to an empty task (Capistrano v 1.x) ● deploy:migrate, deploy:migrations ○ Set them to an empty task ● deploy:default, deploy:cold ○ Not mandatory: do a redirect to task deploy:update ● deploy:finalize_update ○ e.g. files and folder fix permissions ● Sample code at http://bit.ly/13yukoP
  • 15. Configure & Create your own task(s)
  • 16. COnfigure ● SSH Authentication with keys ○ Otherwise, after each 'cap', password will be asked ! > ssh-keygen -t rsa > cat ~/.ssh/id_dsa.pub | ssh sylvain@staging.magehackathon.local "cat - >>.ssh/authorized_keys" ● Deploy.rb set :http_domain, 'staging.magehackathon.local' # local variable set :location, http_domain set :user, "sylvain" # SSH user # set :scm_username, “foo” # set :use_sudo, false # set :ssh_options, { :forward_agent => true, :port: 22 } default_run_options[:pty] = true set :application, "capistranosimple" set :keep_releases, 5 set :repository, "adress of my repo" # Git remote repo for example set :scm, :git # other version control system are also available: e.g. svn set :branch, "master" set :deploy_via, :remote_cache # possible values: copy, checkout, remote_cache, export set :deploy_to, "/www-data/hosts/#{http_domain}/capiroot/apps/#{application}" role :web, location # Your web server domain or IP. e.g. Apache or nginx role :db, location, :primary => true
  • 17. Create your own code ● VERY Basic knowledge in Ruby ○ To Ruby from PHP: http://bit.ly/Z7y3mn ● Define variable set :application, "capistranomagento" set :keep_releases, 5 set :app_shared_dirs, ["/app/etc", "/media", "/var"] ● Create methods, tasks def remote_file_exists(full_path) 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip end namespace :tools do desc "Import sample data with specific information to database. Executed after deploy:setup" task :import_sample_data, :roles => [:db], :only => { :primary => true } do .... abort "#{localsamplesqlfile} doesnt exist locally" unless File.exists?( localsamplesqlfile) if !remote_file_exists("#{shared_path}/shell/#{samplesqlfile}") then run "mkdir -p #{shared_path}/shell" upload localsamplesqlfile, "#{shared_path}/shell/#{samplesqlfile}" end end end
  • 18. Basic CAPISTRANO Action ● run: execute commands on one or more servers ● parallel: execute multiple commands on multiple servers in parallel ● put: store the contents of a file on multiple servers ● get: transfers a file from a single remote server to the local host ● upload: transfers a file or directory from the local host to multiple remote hosts, in parallel. ● download: transfers a file or directory from multiple remote hosts to the local host, in parallel. ● capture: executes a command on a single host and returns ("captures") the output as a string ● stream: very similar to run, but optimized for displaying live streams of text (like tailed log files) from multiple hosts
  • 19. Simple Demo One stage see code at http://bit.ly/ZS0iYl
  • 21. Multi Stages - 1/2 ● Without Capistrano Extension ○ A task per stage in config/deploy.rb task :production do role :web, "www.capify.org" set :deploy_to, "/u/apps/#{application}-production/" set :deploy_via, :remote_cache after('deploy:create_symlink', 'cache:clear') end task :staging do role :web, "localhost" set :deploy_to, "/Users/capistrano/Sites/#{application}-staging/" set :deploy_via, :copy after('deploy:create_symlink', 'cache:clear', 'mage:enable_profiler') end > cap <stagename> <taskname> <optional_parameter> > cap staging deploy
  • 22. Multi Stages - 2/2 ● With Capistrano Extension (Preferred) ○ A ruby file per stage ■ config/deploy/local.rb - http://bit.ly/161gZ82 ■ config/deploy/staging.rb - http://bit.ly/ZdSnDR ■ config/deploy/production.rb - http://bit.ly/ZS8rft ○ Settings in config/deploy.rb require 'capistrano/ext/multistage' set :stages, %w(local production staging) set :default_stage, "staging" ... > cap <stagename> <taskname> <optional_parameter> > cap staging deploy:upload FILES=index.php,app/code/local
  • 23. Structure of LOCAL project |_MyProject |__Capfile # Capistrano bootstrap |__config | |__deploy.rb # Recipes, global config | |__deploy # In case of multi stages | |__local.rb # Config, Hook specific to local | |__staging.rb # Config, Hook specific to staging | |__production.rb # Config, Hook specific to production |__index.php |__skin |__media (shared) |__app |__cron.php |__js |__var (shared) |__RELEASE_NOTES.txt |__shell |__...
  • 24. Simple Demo Two stages see code at http://bit.ly/ZS0iYl
  • 26. Magentify a Project ● Install Magentify ○ gem install magentify ● Init a project ○ Same as with Capify ○ > cd myproject && magentify . ● Advantage ○ Some predefined behaviors and tasks cap mage:cc # Clear the Magento Cache cap mage:clean_log # Clean the Magento logs cap mage:compiler # Run the Magento compiler cap mage:disable # Disable the Magento install by creating the maintenance.flag in the web root. cap mage:disable_compiler # Disable the Magento compiler cap mage:enable # Enable the Magento stores by removing the maintenance.flag in the web root. cap mage:enable_compiler # Enable the Magento compiler cap mage:finalize_update # Touches up the released code. cap mage:indexer # Run the Magento indexer cap mage:setup # Prepares one or more servers for deployment of Magento.
  • 27. Magento Demo Two stages see code at http://bit.ly/ZS0iYl
  • 28. Links
  • 29. Links ● This presentation and its code ○ http://bit.ly/ZS0iYl ● Capistrano ○ http://capistranorb.com ● Magentify ○ http://bit.ly/ZZSyYa ● PHP deployment with Capistrano ○ http://bit.ly/Z7y3mn ○ http://bit.ly/MzqH9o ● Capistrano GUI ○ https://github.com/joelmoss/strano