SlideShare uma empresa Scribd logo
1 de 29
Deploy Drupal with
   Capistrano
      a year later
“A life without philosophy
Capistrano is not worth living”
            --Socrates
“A life without philosophy
Capistrano is not worth living”
            --Socrates


 “Drupal is worth the PHPain”
     --Anonymous from Bari
The Actors
Our friend
Our friend

 Kick Ass CMS
Our friend

     Kick Ass CMS




Isn’t very deploy friendly
Our friend

     Kick Ass CMS




Isn’t very deploy friendly
 and needs some help...
His friend

 Kick Ass CMS
His friend

 Kick Ass CMS




 The logo sucks
His friend

         Kick Ass CMS




           The logo sucks
but it will help your deployments!
The Target
$ cap intinig production deploy
capistrano


   $ cap intinig production deploy
capistrano


   $ cap intinig production deploy
             developer
capistrano               stage


   $ cap intinig production deploy
             developer
capistrano               stage


   $ cap intinig production deploy
             developer           command
The Code
Capfile
                   where the fun starts
load 'deploy' if respond_to?(:namespace) # cap2 differentiator

load   'includes/recipes/stages'
load   'includes/recipes/mikamai'
load   'includes/recipes/drupal'
load   'includes/recipes/overrides'
load   'includes/recipes/devs'

# SCM Stuff configure to taste, just remember the repository
set :repository, "git@github.com:mikamai/app.git"
set :scm, :git
set :branch, "master"
set :repository_cache, "git_master"
set :deploy_via, :remote_cache
set :scm_verbose, true
set :keep_releases, 3
includes/recipes
where we put the “Good Stuff”™
devs.rb
           let’s tell capistrano about ourselves

task :intinig do
 set :local_mysqldump, "/usr/local/mysql/bin/mysqldump"
 set :local_db_user, "root"
 set :local_db_password, "youwishItoldyou"
 set :local_db_name, "app_db"
end

task :paolo do
 set :local_mysqldump, "/Applications/MAMP/Library/bin/mysqldump"
 set :local_db_user, "root"
 set :local_db_password, "paolo"
 set :local_db_name, "stefano"
end
drupal.rb
change capistrano default behavior
 load File.dirname(__FILE__) + '/drupal/db'
 load File.dirname(__FILE__) + '/drupal/configure'

 after 'deploy:setup', 'drupal:setup'
 after 'deploy:symlink', 'drupal:symlink'
 before 'deploy:start', 'drupal:db:import:production'

 before 'deploy:restart', 'drupal:configure:stage'
 before 'deploy:start', 'drupal:configure:stage'

 namespace :drupal do
  task :setup, :except => { :no_release => true } do
   sudo "mkdir -p #{shared_path}/files"
   sudo "chmod a+w #{shared_path}/files"

   sudo "mkdir -p #{shared_path}/dumps"

   sudo "chown -R #{user}:#{user} #{deploy_to}"
  end

  task :symlink, :except => { :no_release => true } do
   sudo "ln -s #{shared_path}/files #{latest_release}"
  end
 end
drupal/configure.rb
                    a small hack for multiple stages
namespace :drupal do
 namespace :configure do
  task :stage do
    source = "#{latest_release}/sites/default/settings.#{stage_name}.php"
    dest = "#{latest_release}/sites/default/settings.php"
    sudo "cp #{source} #{dest}"
  end
 end
end
drupal/db.rb
                                       mysql grinding
namespace :local do
 desc "Dumps the local database"
 task :default, :roles => :db do
  raise RuntimeError.new("failed dump") unless system "#{local_mysqldump} -u #{local_db_user} --
password=#{local_db_password} #{local_db_name} > dump.local.sql"
 end

 namespace :upload do
  desc "Dumps and uploads the local database"
  task :default do
    drupal::db::dump::local::default
    put(File.read("dump.local.sql"), "#{shared_path}/dumps/dump.local.sql")
    run "mysql -u #{db_user} --password=#{db_password} #{db_name} < #{shared_path}/dumps/
dump.local.sql"
  end
 end
end
drupal/db.rb
                                     mysql grinding / 2
namespace :remote do
 desc "Dumps the remote database"
 task :default, :roles => :db do
  filename = "#{Time.now.to_i.to_s}.dump.sql"
  run "cd #{shared_path}/dumps; #{remote_mysqldump} -u #{db_user} --password=#{db_password}
#{db_name} > #{filename}"
  run "cd #{shared_path}/dumps; bzip2 #{filename}"
 end

 namespace :download do
  desc "Dumps and downloads the remote database"
  task :default do
   drupal::db::dump::remote::default
   latest
  end

  desc "Downloads the latest database dump"
  task :latest, :roles => :db do
    dumps = capture("ls -xt #{shared_path}/dumps").split.reverse
    get("#{shared_path}/dumps/#{dumps.last}", "./#{dumps.last}")
  end
 end
end
mikamai.rb
             fix problems on our servers
before 'deploy:restart', 'mikamai:permissions:fix'
before 'deploy:start', 'mikamai:permissions:fix'

namespace :mikamai do

 namespace :production do
  task :symlink, :except => { :no_release => true } do
   sudo "rm -rf /var/www/#{application}"
   sudo "ln -s #{latest_release} /var/www/#{application}"
  end
 end

 namespace :permissions do
  task :fix, :except => { :no_release => true } do
   sudo "chown -R www-data:www-data #{latest_release}"
  end
 end

end
overrides.rb
                      do as we say not as we do
namespace :deploy do
 task :finalize_update, :except => { :no_release => true } do
  sudo "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
 end

 task :cold do
  update
  start
 end

 task :restart do
 end

 task :start do
 end
end
stages.rb
                    one for everyone
set :application, "cool_app"

desc "deploy to development environment"
task :development do
 set :stage_name, "development"

 role :web, "danton.mikamai.com:8888", :primary => true
 role :db, "danton.mikamai.com:8888", :primary => true
 set :user, "drupal"
 set :password, "secret"
 set :remote_mysqldump, "/usr/bin/mysqldump"
 set :deploy_to, "/var/apps/#{application}"
 set :db_user, "dbuser"
 set :db_password, "supersecret"
 set :db_name, "appname"
end
Questions?
Giovanni Intini <giovanni@mikamai.com>

Mais conteúdo relacionado

Último

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 

Último (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 

Destaque

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Destaque (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

Deploy Drupal With Capistrano A Year Later

  • 1. Deploy Drupal with Capistrano a year later
  • 2. “A life without philosophy Capistrano is not worth living” --Socrates
  • 3. “A life without philosophy Capistrano is not worth living” --Socrates “Drupal is worth the PHPain” --Anonymous from Bari
  • 6. Our friend Kick Ass CMS
  • 7. Our friend Kick Ass CMS Isn’t very deploy friendly
  • 8. Our friend Kick Ass CMS Isn’t very deploy friendly and needs some help...
  • 9. His friend Kick Ass CMS
  • 10. His friend Kick Ass CMS The logo sucks
  • 11. His friend Kick Ass CMS The logo sucks but it will help your deployments!
  • 13. $ cap intinig production deploy
  • 14. capistrano $ cap intinig production deploy
  • 15. capistrano $ cap intinig production deploy developer
  • 16. capistrano stage $ cap intinig production deploy developer
  • 17. capistrano stage $ cap intinig production deploy developer command
  • 19. Capfile where the fun starts load 'deploy' if respond_to?(:namespace) # cap2 differentiator load 'includes/recipes/stages' load 'includes/recipes/mikamai' load 'includes/recipes/drupal' load 'includes/recipes/overrides' load 'includes/recipes/devs' # SCM Stuff configure to taste, just remember the repository set :repository, "git@github.com:mikamai/app.git" set :scm, :git set :branch, "master" set :repository_cache, "git_master" set :deploy_via, :remote_cache set :scm_verbose, true set :keep_releases, 3
  • 20. includes/recipes where we put the “Good Stuff”™
  • 21. devs.rb let’s tell capistrano about ourselves task :intinig do set :local_mysqldump, "/usr/local/mysql/bin/mysqldump" set :local_db_user, "root" set :local_db_password, "youwishItoldyou" set :local_db_name, "app_db" end task :paolo do set :local_mysqldump, "/Applications/MAMP/Library/bin/mysqldump" set :local_db_user, "root" set :local_db_password, "paolo" set :local_db_name, "stefano" end
  • 22. drupal.rb change capistrano default behavior load File.dirname(__FILE__) + '/drupal/db' load File.dirname(__FILE__) + '/drupal/configure' after 'deploy:setup', 'drupal:setup' after 'deploy:symlink', 'drupal:symlink' before 'deploy:start', 'drupal:db:import:production' before 'deploy:restart', 'drupal:configure:stage' before 'deploy:start', 'drupal:configure:stage' namespace :drupal do task :setup, :except => { :no_release => true } do sudo "mkdir -p #{shared_path}/files" sudo "chmod a+w #{shared_path}/files" sudo "mkdir -p #{shared_path}/dumps" sudo "chown -R #{user}:#{user} #{deploy_to}" end task :symlink, :except => { :no_release => true } do sudo "ln -s #{shared_path}/files #{latest_release}" end end
  • 23. drupal/configure.rb a small hack for multiple stages namespace :drupal do namespace :configure do task :stage do source = "#{latest_release}/sites/default/settings.#{stage_name}.php" dest = "#{latest_release}/sites/default/settings.php" sudo "cp #{source} #{dest}" end end end
  • 24. drupal/db.rb mysql grinding namespace :local do desc "Dumps the local database" task :default, :roles => :db do raise RuntimeError.new("failed dump") unless system "#{local_mysqldump} -u #{local_db_user} -- password=#{local_db_password} #{local_db_name} > dump.local.sql" end namespace :upload do desc "Dumps and uploads the local database" task :default do drupal::db::dump::local::default put(File.read("dump.local.sql"), "#{shared_path}/dumps/dump.local.sql") run "mysql -u #{db_user} --password=#{db_password} #{db_name} < #{shared_path}/dumps/ dump.local.sql" end end end
  • 25. drupal/db.rb mysql grinding / 2 namespace :remote do desc "Dumps the remote database" task :default, :roles => :db do filename = "#{Time.now.to_i.to_s}.dump.sql" run "cd #{shared_path}/dumps; #{remote_mysqldump} -u #{db_user} --password=#{db_password} #{db_name} > #{filename}" run "cd #{shared_path}/dumps; bzip2 #{filename}" end namespace :download do desc "Dumps and downloads the remote database" task :default do drupal::db::dump::remote::default latest end desc "Downloads the latest database dump" task :latest, :roles => :db do dumps = capture("ls -xt #{shared_path}/dumps").split.reverse get("#{shared_path}/dumps/#{dumps.last}", "./#{dumps.last}") end end end
  • 26. mikamai.rb fix problems on our servers before 'deploy:restart', 'mikamai:permissions:fix' before 'deploy:start', 'mikamai:permissions:fix' namespace :mikamai do namespace :production do task :symlink, :except => { :no_release => true } do sudo "rm -rf /var/www/#{application}" sudo "ln -s #{latest_release} /var/www/#{application}" end end namespace :permissions do task :fix, :except => { :no_release => true } do sudo "chown -R www-data:www-data #{latest_release}" end end end
  • 27. overrides.rb do as we say not as we do namespace :deploy do task :finalize_update, :except => { :no_release => true } do sudo "chmod -R g+w #{latest_release}" if fetch(:group_writable, true) end task :cold do update start end task :restart do end task :start do end end
  • 28. stages.rb one for everyone set :application, "cool_app" desc "deploy to development environment" task :development do set :stage_name, "development" role :web, "danton.mikamai.com:8888", :primary => true role :db, "danton.mikamai.com:8888", :primary => true set :user, "drupal" set :password, "secret" set :remote_mysqldump, "/usr/bin/mysqldump" set :deploy_to, "/var/apps/#{application}" set :db_user, "dbuser" set :db_password, "supersecret" set :db_name, "appname" end