SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
T H E T H E O R Y   A N D I M P L E M E N T
M A G E N T O 2
C A P I S T R A N O
D e p l o y M a g e n t o 2
C a p i s t r a n o
M a g e n t o 2 C a p i s t r a n o
Q u e s t i o n s
C O N T E N T
D E P L O Y M A G E N T O 2
Update Repository
Composer pull down
Sync files
Deploy static files
Enable maintenance
Enable modules
D E P L O Y M A G E N T O 2
Run setup scripts
Clear cache
Disable maintenance mode
Update permissions
Restart PHP FPM
C A P I S T R A N O
s
Capistrano is a framework for building automated deployment
scripts
Multiple stages
Parallel execution
Server roles
Community driven
It's just SSH
C A P I S T R A N O
s
Benefits:
Deploy automatically
Reduce risk for deploy process
Easy to customize
C A P I S T R A N O
s
Prerequisite:
Ruby version 2.0 or higher
A project that uses source control
Bundler, along with a Gemfile for your project
Note:
- Create a Gemfile by Bundle with 'bundle init'
command.
C A P I S T R A N O
s
How it working:
Connect to the server via forward SSH and
pull down codebase.
Create a release for each deploy time.
The current project will refer to latest success
release.
Fallback to latest success release if deploy
process to break down.
C A P I S T R A N O
s
Install:
Add Capistrano to your project's Gemfile:
group :development do
gem "capistrano", "~> 3.8"
end
Capify project:
bundle install
bundle exec cap install
C A P I S T R A N O
s
Folder Structure:
├── Capfile
├── config
│ ├── deploy
│ │ ├── production.rb
│ │ └── staging.rb
│ └── deploy.rb
└── lib
└── capistrano
└── tasks
C A P I S T R A N O
s
Configuring config/deploy.rb:
set :application, 'example'
set :repo_url, 'git@github.com:acme/example-com.git'
Update the :application and :repo_url values in config/deploy.rb:
For each stage, e.g 'config/deploy/production', set the branch
and :deploy_to folder for pulling code:
set :branch, 'master'
set :deploy_to, "/var/www/my_app_name"
C A P I S T R A N O
s
Configuring config/deploy/*.rb:
server 'www.example.com', user: 'www-data', roles: %w{app
db web}
set :deploy_to, '/var/www/html'
set :branch, proc { `git rev-parse --abbrev-ref master`.chomp
}
Single application server
C A P I S T R A N O
s
Customize tasks:
namespace :magento2 do
desc "Restart PHP FPM"
task :restart_php_fpm do
on roles(:all), in: :sequence, wait: 1 do
execute :sudo, 'service php7.0-fpm restart'
end
end
end
Define helper tasks in lib/capistrano/tasks file.
In my project, I also create a task for upload adminer.php file using for
staging site.
C A P I S T R A N O
s
Project Structure:
├── current -> latest release
├── releases
│ ├── 20170420014820
│ ├── 20170420014820
│
└── repo
│
└── shared
C A P I S T R A N O
s
Usage:
Single application server:
bundle exec cap <stage> deploy
# bundle exec cap production deploy
Multiple application server:
Refer to Capistrano documentation for detail on how to configure
multiple application servers.
List all available tasks:
bundle exec cap -T
M 2 C A P I S T R A N O
s
Install
Add the following to your project's Gemfile:
source 'https://rubygems.org'
gem 'capistrano-magento2'
Useful gem:
gem 'capistrano-composer'
gem 'capistrano-upload-config'
gem 'capistrano-file-permissions'
D E P L O Y S E T T I N G
s
Capistrano Built-Ins
set :linked_files, [
'app/etc/env.php',
'pub/.htaccess'
]
set :linked_dirs, [
'pub/media',
'var'
]
For prepared config files and keep the resource sync between
releases folders.
D E P L O Y S E T T I N G
s
Capistrano Built-Ins
set :config_files, %w{app/etc/env.php
pub/.htaccess}
# push link files after check them exist.
before 'deploy:check:linked_files', 'config:push'
Using capistrano-upload-config gem to push them into the server
Note:
- Link files must be named as filename.<stage>.extension, e.g
env.production.json in the repository project.
D E P L O Y S E T T I N G
s
Magento Deploy Settings
set :magento_deploy_setup_role, :all
set :magento_deploy_cache_shared, true
set :magento_deploy_languages, ['en_US']
set :magento_deploy_themes, []
set :magento_deploy_composer, true
set :magento_deploy_production, true
set :magento_deploy_maintenance, true
set :magento_deploy_confirm, []
D E P L O Y S E T T I N G
s
Magento Deploy Settings
Those tasks above for:
- Role for primary host.
- Cache operation.
- Setup languages for theme.
- Deploy static content files.
- Enables composer install.
- Enables production DI compilation.
- Enables use of maintenance mode.
- Used to require confirmation of deployment
D E P L O Y S E T T I N G
s
Magento Deploy Settings
set :magento_deploy_chmod_d, '0755'
set :magento_deploy_chmod_f, '0644'
set :magento_deploy_chmod_x, ['bin/magento']
set :file_permissions_roles, :all
set :file_permissions_paths, ["pub/static", "var"]
set :file_permissions_users, ["SERVER_USER"]
set :file_permissions_groups, ["SERVER_GROUP"]
set :file_permissions_chmod_mode, "0777"
before "deploy:updated", "deploy:set_permissions:acl"
D E P L O Y S E T T I N G
s
Magento Deploy Settings
Those commands above for setup permission and
ownership for all folders of project with some
specific for pub/static/ and var/ folder.
Capistrano using the setfacl to do that for
SERVER_USER and SERVER_GROUP account.
D E P L O Y S E T T I N G
s
Composer Auth Credentials
set :magento_auth_public_key,
'MAGENTO_USERNAME'
set :magento_auth_private_key,
'MAGENTO_PASSWORD'
This will execute that command below:
composer config --global --auth http-basic.repo.magento.com
MAGENTO_USERNAME MAGENTO_PASSWORD
D E P L O Y S E T T I N G
s
Magento Customize Tasks
before 'magento:deploy:verify', 'magento2:copy_config'
after 'magento:setup:static-content:deploy',
'magento2:add_adminer'
after 'magento:maintenance:disable',
'magento2:restart_php_fpm'
Note:
- The 'copy_config' is customized task, see details in Q&A
section.
Q U E S T I O N S
s
What the benefit of config.php.dist?
Answer:
It help you to controll what the modules you actually
want to using them in your project, it will converted to
config.php, so the your project must be have it in the
app/etc folder.
The customize task called 'copy_config' will help you to
do all of this, see in my example repository for how to
create this task.
Q U E S T I O N S
s
Why must to restart PHP FPM?
Answer:
We need to restart PHP FPM to flush cache of Zend
Opcache - a native extension built-in PHP.
Error: Don't know how to build task?
Answer:
Add require gem to the Capfile:
# Load Magento deployment tasks
require 'capistrano/magento2/deploy'
Q U E S T I O N S
s
Have any project for example?
Answer:
I created a Github repository, for example, I also using
it for deploying my Magento 2 site, you can refer it at
here:
https://github.com/unetstudio/magento-2-capistrano-
deploy
R E F E R E N C E S
s
https://github.com/capistrano/capistrano
https://github.com/davidalger/capistrano-magento2
https://github.com/unetstudio/magento-2-capistrano-
deploy
https://github.com/bundler/bundler
A B O U T M E
s
Hi there, I'm Duc Dao. A web developer living in Hanoi,
Vietnam. Currently, I'm working in SmartOSC
corporation and love to share knowledge.
Email: huuduc.uneti@gmail.com
Website: http://newbie-dev.net
D U C D A O
T H A N K Y O U !

Contenu connexe

Tendances

Secondary Certificate
Secondary CertificateSecondary Certificate
Secondary CertificateSantanu Laha
 
مجلة الانطلاقة الـ 34 لحركة حماس
مجلة الانطلاقة الـ 34 لحركة حماسمجلة الانطلاقة الـ 34 لحركة حماس
مجلة الانطلاقة الـ 34 لحركة حماسHamasMediaWb
 
Boletín 1 - Cálculo de Probabilidades (soluciones)
Boletín 1 - Cálculo de Probabilidades (soluciones)Boletín 1 - Cálculo de Probabilidades (soluciones)
Boletín 1 - Cálculo de Probabilidades (soluciones)Universidad de Vigo
 
Frank gambale -_chop_builder
Frank gambale -_chop_builderFrank gambale -_chop_builder
Frank gambale -_chop_builderGregLachlan
 
How to draw manga. vol. 10. getting started
How to draw manga. vol. 10. getting startedHow to draw manga. vol. 10. getting started
How to draw manga. vol. 10. getting startedIsshin Stark
 
Partituras da Disney para violino
Partituras da Disney para violinoPartituras da Disney para violino
Partituras da Disney para violinoDaniel Augusto
 
VC - Marti Misterija - 050 - Protokol Levijatan
VC - Marti Misterija - 050 - Protokol LevijatanVC - Marti Misterija - 050 - Protokol Levijatan
VC - Marti Misterija - 050 - Protokol LevijatanStripovizijacom
 
Zagor LUD 301 - Krik vile smrti.pdf
Zagor LUD 301 - Krik vile smrti.pdfZagor LUD 301 - Krik vile smrti.pdf
Zagor LUD 301 - Krik vile smrti.pdfStripovizijacom
 
Revista Natura ciclo 14 - 05 setembro 2013
Revista Natura ciclo 14 - 05 setembro 2013Revista Natura ciclo 14 - 05 setembro 2013
Revista Natura ciclo 14 - 05 setembro 2013Meus Cosméticos
 
435270481 o-grufalo
435270481 o-grufalo435270481 o-grufalo
435270481 o-grufaloMariGiopato
 
Akbar Birbal Story : Akbar’s Dream – Mocomi Kids
Akbar Birbal Story : Akbar’s Dream – Mocomi KidsAkbar Birbal Story : Akbar’s Dream – Mocomi Kids
Akbar Birbal Story : Akbar’s Dream – Mocomi KidsMocomi Kids
 
Cartões paula teles
Cartões paula telesCartões paula teles
Cartões paula telesmarisa campos
 
Epdf.pub lets learn-japanese-picture-dictionary
Epdf.pub lets learn-japanese-picture-dictionaryEpdf.pub lets learn-japanese-picture-dictionary
Epdf.pub lets learn-japanese-picture-dictionaryAmadiPinkney
 
Honda Scoopy SH50 manual 5 of 6 - PDF
Honda Scoopy SH50 manual 5 of 6 - PDFHonda Scoopy SH50 manual 5 of 6 - PDF
Honda Scoopy SH50 manual 5 of 6 - PDFJohnV12
 
Incident of KARBALA in Urdu
Incident of KARBALA in UrduIncident of KARBALA in Urdu
Incident of KARBALA in UrduMuniba-sheikh
 
IOM Appreciatian Letter
IOM Appreciatian LetterIOM Appreciatian Letter
IOM Appreciatian LetterMUSTANSIRC
 

Tendances (20)

Secondary Certificate
Secondary CertificateSecondary Certificate
Secondary Certificate
 
Psa unit 2
Psa unit 2Psa unit 2
Psa unit 2
 
مجلة الانطلاقة الـ 34 لحركة حماس
مجلة الانطلاقة الـ 34 لحركة حماسمجلة الانطلاقة الـ 34 لحركة حماس
مجلة الانطلاقة الـ 34 لحركة حماس
 
Boletín 1 - Cálculo de Probabilidades (soluciones)
Boletín 1 - Cálculo de Probabilidades (soluciones)Boletín 1 - Cálculo de Probabilidades (soluciones)
Boletín 1 - Cálculo de Probabilidades (soluciones)
 
Frank gambale -_chop_builder
Frank gambale -_chop_builderFrank gambale -_chop_builder
Frank gambale -_chop_builder
 
How to draw manga. vol. 10. getting started
How to draw manga. vol. 10. getting startedHow to draw manga. vol. 10. getting started
How to draw manga. vol. 10. getting started
 
Partituras da Disney para violino
Partituras da Disney para violinoPartituras da Disney para violino
Partituras da Disney para violino
 
VC - Marti Misterija - 050 - Protokol Levijatan
VC - Marti Misterija - 050 - Protokol LevijatanVC - Marti Misterija - 050 - Protokol Levijatan
VC - Marti Misterija - 050 - Protokol Levijatan
 
Zagor LUD 301 - Krik vile smrti.pdf
Zagor LUD 301 - Krik vile smrti.pdfZagor LUD 301 - Krik vile smrti.pdf
Zagor LUD 301 - Krik vile smrti.pdf
 
Revista Natura ciclo 14 - 05 setembro 2013
Revista Natura ciclo 14 - 05 setembro 2013Revista Natura ciclo 14 - 05 setembro 2013
Revista Natura ciclo 14 - 05 setembro 2013
 
435270481 o-grufalo
435270481 o-grufalo435270481 o-grufalo
435270481 o-grufalo
 
Rédiger sans fautes (cm2)
Rédiger sans fautes (cm2)Rédiger sans fautes (cm2)
Rédiger sans fautes (cm2)
 
Akbar Birbal Story : Akbar’s Dream – Mocomi Kids
Akbar Birbal Story : Akbar’s Dream – Mocomi KidsAkbar Birbal Story : Akbar’s Dream – Mocomi Kids
Akbar Birbal Story : Akbar’s Dream – Mocomi Kids
 
Cartões paula teles
Cartões paula telesCartões paula teles
Cartões paula teles
 
Epdf.pub lets learn-japanese-picture-dictionary
Epdf.pub lets learn-japanese-picture-dictionaryEpdf.pub lets learn-japanese-picture-dictionary
Epdf.pub lets learn-japanese-picture-dictionary
 
Honda Scoopy SH50 manual 5 of 6 - PDF
Honda Scoopy SH50 manual 5 of 6 - PDFHonda Scoopy SH50 manual 5 of 6 - PDF
Honda Scoopy SH50 manual 5 of 6 - PDF
 
Incident of KARBALA in Urdu
Incident of KARBALA in UrduIncident of KARBALA in Urdu
Incident of KARBALA in Urdu
 
12 pass certificate
12 pass certificate12 pass certificate
12 pass certificate
 
Erotik pur
Erotik purErotik pur
Erotik pur
 
IOM Appreciatian Letter
IOM Appreciatian LetterIOM Appreciatian Letter
IOM Appreciatian Letter
 

Similaire à Magento 2 Capistrano Deploy

Magento 2 Development
Magento 2 DevelopmentMagento 2 Development
Magento 2 DevelopmentDuke Dao
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolelliando dias
 
Magento2 From Setup To Deployment. Automate Everything
Magento2 From Setup To Deployment. Automate EverythingMagento2 From Setup To Deployment. Automate Everything
Magento2 From Setup To Deployment. Automate EverythingJuan Alonso
 
Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Yury Pliashkou
 
Professional deployment
Professional deploymentProfessional deployment
Professional deploymentIvelina Dimova
 
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
 
Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01rhemsolutions
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient waySylvain Rayé
 
Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year laterChristian Ortner
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for DevelopersAntons Kranga
 
Rock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment WorkflowsRock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment WorkflowsAOE
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-TranslatorDashamir Hoxha
 
How to install squid proxy on server or how to install squid proxy on centos o
How to install squid proxy on server  or how to install squid proxy on centos oHow to install squid proxy on server  or how to install squid proxy on centos o
How to install squid proxy on server or how to install squid proxy on centos oProxiesforrent
 
Getting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated VersionGetting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated VersionCFEngine
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierCarlos Sanchez
 

Similaire à Magento 2 Capistrano Deploy (20)

Magento 2 Development
Magento 2 DevelopmentMagento 2 Development
Magento 2 Development
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
Maven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension toolMaven 2.0 - Project management and comprehension tool
Maven 2.0 - Project management and comprehension tool
 
Magento2 From Setup To Deployment. Automate Everything
Magento2 From Setup To Deployment. Automate EverythingMagento2 From Setup To Deployment. Automate Everything
Magento2 From Setup To Deployment. Automate Everything
 
Capistrano
CapistranoCapistrano
Capistrano
 
Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11Capifony. Minsk PHP MeetUp #11
Capifony. Minsk PHP MeetUp #11
 
Professional deployment
Professional deploymentProfessional deployment
Professional deployment
 
Using Maven2
Using Maven2Using Maven2
Using Maven2
 
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
 
Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01
 
Capistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient wayCapistrano deploy Magento project in an efficient way
Capistrano deploy Magento project in an efficient way
 
Slim3 quick start
Slim3 quick startSlim3 quick start
Slim3 quick start
 
Infrastructure = code - 1 year later
Infrastructure = code - 1 year laterInfrastructure = code - 1 year later
Infrastructure = code - 1 year later
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for Developers
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
 
Rock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment WorkflowsRock-solid Magento Development and Deployment Workflows
Rock-solid Magento Development and Deployment Workflows
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-Translator
 
How to install squid proxy on server or how to install squid proxy on centos o
How to install squid proxy on server  or how to install squid proxy on centos oHow to install squid proxy on server  or how to install squid proxy on centos o
How to install squid proxy on server or how to install squid proxy on centos o
 
Getting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated VersionGetting Started With CFEngine - Updated Version
Getting Started With CFEngine - Updated Version
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 

Dernier

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
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
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
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
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
 

Dernier (20)

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
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
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
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
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
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Magento 2 Capistrano Deploy

  • 1. T H E T H E O R Y   A N D I M P L E M E N T M A G E N T O 2 C A P I S T R A N O
  • 2. D e p l o y M a g e n t o 2 C a p i s t r a n o M a g e n t o 2 C a p i s t r a n o Q u e s t i o n s C O N T E N T
  • 3. D E P L O Y M A G E N T O 2 Update Repository Composer pull down Sync files Deploy static files Enable maintenance Enable modules
  • 4. D E P L O Y M A G E N T O 2 Run setup scripts Clear cache Disable maintenance mode Update permissions Restart PHP FPM
  • 5. C A P I S T R A N O s Capistrano is a framework for building automated deployment scripts Multiple stages Parallel execution Server roles Community driven It's just SSH
  • 6. C A P I S T R A N O s Benefits: Deploy automatically Reduce risk for deploy process Easy to customize
  • 7. C A P I S T R A N O s Prerequisite: Ruby version 2.0 or higher A project that uses source control Bundler, along with a Gemfile for your project Note: - Create a Gemfile by Bundle with 'bundle init' command.
  • 8. C A P I S T R A N O s How it working: Connect to the server via forward SSH and pull down codebase. Create a release for each deploy time. The current project will refer to latest success release. Fallback to latest success release if deploy process to break down.
  • 9. C A P I S T R A N O s Install: Add Capistrano to your project's Gemfile: group :development do gem "capistrano", "~> 3.8" end Capify project: bundle install bundle exec cap install
  • 10. C A P I S T R A N O s Folder Structure: ├── Capfile ├── config │ ├── deploy │ │ ├── production.rb │ │ └── staging.rb │ └── deploy.rb └── lib └── capistrano └── tasks
  • 11. C A P I S T R A N O s Configuring config/deploy.rb: set :application, 'example' set :repo_url, 'git@github.com:acme/example-com.git' Update the :application and :repo_url values in config/deploy.rb: For each stage, e.g 'config/deploy/production', set the branch and :deploy_to folder for pulling code: set :branch, 'master' set :deploy_to, "/var/www/my_app_name"
  • 12. C A P I S T R A N O s Configuring config/deploy/*.rb: server 'www.example.com', user: 'www-data', roles: %w{app db web} set :deploy_to, '/var/www/html' set :branch, proc { `git rev-parse --abbrev-ref master`.chomp } Single application server
  • 13. C A P I S T R A N O s Customize tasks: namespace :magento2 do desc "Restart PHP FPM" task :restart_php_fpm do on roles(:all), in: :sequence, wait: 1 do execute :sudo, 'service php7.0-fpm restart' end end end Define helper tasks in lib/capistrano/tasks file. In my project, I also create a task for upload adminer.php file using for staging site.
  • 14. C A P I S T R A N O s Project Structure: ├── current -> latest release ├── releases │ ├── 20170420014820 │ ├── 20170420014820 │ └── repo │ └── shared
  • 15. C A P I S T R A N O s Usage: Single application server: bundle exec cap <stage> deploy # bundle exec cap production deploy Multiple application server: Refer to Capistrano documentation for detail on how to configure multiple application servers. List all available tasks: bundle exec cap -T
  • 16. M 2 C A P I S T R A N O s Install Add the following to your project's Gemfile: source 'https://rubygems.org' gem 'capistrano-magento2' Useful gem: gem 'capistrano-composer' gem 'capistrano-upload-config' gem 'capistrano-file-permissions'
  • 17. D E P L O Y S E T T I N G s Capistrano Built-Ins set :linked_files, [ 'app/etc/env.php', 'pub/.htaccess' ] set :linked_dirs, [ 'pub/media', 'var' ] For prepared config files and keep the resource sync between releases folders.
  • 18. D E P L O Y S E T T I N G s Capistrano Built-Ins set :config_files, %w{app/etc/env.php pub/.htaccess} # push link files after check them exist. before 'deploy:check:linked_files', 'config:push' Using capistrano-upload-config gem to push them into the server Note: - Link files must be named as filename.<stage>.extension, e.g env.production.json in the repository project.
  • 19. D E P L O Y S E T T I N G s Magento Deploy Settings set :magento_deploy_setup_role, :all set :magento_deploy_cache_shared, true set :magento_deploy_languages, ['en_US'] set :magento_deploy_themes, [] set :magento_deploy_composer, true set :magento_deploy_production, true set :magento_deploy_maintenance, true set :magento_deploy_confirm, []
  • 20. D E P L O Y S E T T I N G s Magento Deploy Settings Those tasks above for: - Role for primary host. - Cache operation. - Setup languages for theme. - Deploy static content files. - Enables composer install. - Enables production DI compilation. - Enables use of maintenance mode. - Used to require confirmation of deployment
  • 21. D E P L O Y S E T T I N G s Magento Deploy Settings set :magento_deploy_chmod_d, '0755' set :magento_deploy_chmod_f, '0644' set :magento_deploy_chmod_x, ['bin/magento'] set :file_permissions_roles, :all set :file_permissions_paths, ["pub/static", "var"] set :file_permissions_users, ["SERVER_USER"] set :file_permissions_groups, ["SERVER_GROUP"] set :file_permissions_chmod_mode, "0777" before "deploy:updated", "deploy:set_permissions:acl"
  • 22. D E P L O Y S E T T I N G s Magento Deploy Settings Those commands above for setup permission and ownership for all folders of project with some specific for pub/static/ and var/ folder. Capistrano using the setfacl to do that for SERVER_USER and SERVER_GROUP account.
  • 23. D E P L O Y S E T T I N G s Composer Auth Credentials set :magento_auth_public_key, 'MAGENTO_USERNAME' set :magento_auth_private_key, 'MAGENTO_PASSWORD' This will execute that command below: composer config --global --auth http-basic.repo.magento.com MAGENTO_USERNAME MAGENTO_PASSWORD
  • 24. D E P L O Y S E T T I N G s Magento Customize Tasks before 'magento:deploy:verify', 'magento2:copy_config' after 'magento:setup:static-content:deploy', 'magento2:add_adminer' after 'magento:maintenance:disable', 'magento2:restart_php_fpm' Note: - The 'copy_config' is customized task, see details in Q&A section.
  • 25. Q U E S T I O N S s What the benefit of config.php.dist? Answer: It help you to controll what the modules you actually want to using them in your project, it will converted to config.php, so the your project must be have it in the app/etc folder. The customize task called 'copy_config' will help you to do all of this, see in my example repository for how to create this task.
  • 26. Q U E S T I O N S s Why must to restart PHP FPM? Answer: We need to restart PHP FPM to flush cache of Zend Opcache - a native extension built-in PHP. Error: Don't know how to build task? Answer: Add require gem to the Capfile: # Load Magento deployment tasks require 'capistrano/magento2/deploy'
  • 27. Q U E S T I O N S s Have any project for example? Answer: I created a Github repository, for example, I also using it for deploying my Magento 2 site, you can refer it at here: https://github.com/unetstudio/magento-2-capistrano- deploy
  • 28. R E F E R E N C E S s https://github.com/capistrano/capistrano https://github.com/davidalger/capistrano-magento2 https://github.com/unetstudio/magento-2-capistrano- deploy https://github.com/bundler/bundler
  • 29. A B O U T M E s Hi there, I'm Duc Dao. A web developer living in Hanoi, Vietnam. Currently, I'm working in SmartOSC corporation and love to share knowledge. Email: huuduc.uneti@gmail.com Website: http://newbie-dev.net
  • 30. D U C D A O T H A N K Y O U !