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

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
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
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
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
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 
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
 

Kürzlich hochgeladen (20)

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
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
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
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
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.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
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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
 
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
 

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