SlideShare ist ein Scribd-Unternehmen logo
1 von 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>

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Kürzlich hochgeladen (20)

Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Empfohlen

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
 

Empfohlen (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