SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
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 !

Weitere ähnliche Inhalte

Was ist angesagt?

Kubernetes Clusters as a Service with Gardener
Kubernetes Clusters as a Service with GardenerKubernetes Clusters as a Service with Gardener
Kubernetes Clusters as a Service with GardenerQAware GmbH
 
Web Assembly Big Picture
Web Assembly Big PictureWeb Assembly Big Picture
Web Assembly Big PictureYousif Shalaby
 
Helm - Package Manager for Kubernetes
Helm - Package Manager for KubernetesHelm - Package Manager for Kubernetes
Helm - Package Manager for KubernetesKnoldus Inc.
 
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
"Certified Kubernetes Administrator Exam – how it was" by Andrii FedenishinKatherine Golovinova
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDPlcplcp1
 
Kafka Tutorial: Kafka Security
Kafka Tutorial: Kafka SecurityKafka Tutorial: Kafka Security
Kafka Tutorial: Kafka SecurityJean-Paul Azar
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceSUSE Labs Taipei
 
VMware NSX 101: What, Why & How
VMware NSX 101: What, Why & HowVMware NSX 101: What, Why & How
VMware NSX 101: What, Why & HowAniekan Akpaffiong
 
Workday's Next Generation Private Cloud
Workday's Next Generation Private CloudWorkday's Next Generation Private Cloud
Workday's Next Generation Private CloudSilvano Buback
 
Docker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesDocker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesSreenivas Makam
 
EMC Vnx master-presentation
EMC Vnx master-presentationEMC Vnx master-presentation
EMC Vnx master-presentationsolarisyougood
 
VMware vSphere 6.0 - Troubleshooting Training - Day 1
VMware vSphere 6.0 - Troubleshooting Training - Day 1VMware vSphere 6.0 - Troubleshooting Training - Day 1
VMware vSphere 6.0 - Troubleshooting Training - Day 1Sanjeev Kumar
 
NSX-T Architecture and Components.pptx
NSX-T Architecture and Components.pptxNSX-T Architecture and Components.pptx
NSX-T Architecture and Components.pptxAtif Raees
 
Inline command emc内部inline命令集
Inline command emc内部inline命令集Inline command emc内部inline命令集
Inline command emc内部inline命令集luweinet
 

Was ist angesagt? (20)

eBPF/XDP
eBPF/XDP eBPF/XDP
eBPF/XDP
 
eBPF Basics
eBPF BasicseBPF Basics
eBPF Basics
 
Kubernetes Clusters as a Service with Gardener
Kubernetes Clusters as a Service with GardenerKubernetes Clusters as a Service with Gardener
Kubernetes Clusters as a Service with Gardener
 
QEMU-SystemC (FDL)
QEMU-SystemC (FDL)QEMU-SystemC (FDL)
QEMU-SystemC (FDL)
 
Web Assembly Big Picture
Web Assembly Big PictureWeb Assembly Big Picture
Web Assembly Big Picture
 
Helm - Package Manager for Kubernetes
Helm - Package Manager for KubernetesHelm - Package Manager for Kubernetes
Helm - Package Manager for Kubernetes
 
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
"Certified Kubernetes Administrator Exam – how it was" by Andrii Fedenishin
 
Introduction to eBPF and XDP
Introduction to eBPF and XDPIntroduction to eBPF and XDP
Introduction to eBPF and XDP
 
Kafka Tutorial: Kafka Security
Kafka Tutorial: Kafka SecurityKafka Tutorial: Kafka Security
Kafka Tutorial: Kafka Security
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to Userspace
 
VMware NSX 101: What, Why & How
VMware NSX 101: What, Why & HowVMware NSX 101: What, Why & How
VMware NSX 101: What, Why & How
 
Workday's Next Generation Private Cloud
Workday's Next Generation Private CloudWorkday's Next Generation Private Cloud
Workday's Next Generation Private Cloud
 
Docker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesDocker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting Techniques
 
Kamailio - Secure Communication
Kamailio - Secure CommunicationKamailio - Secure Communication
Kamailio - Secure Communication
 
EMC Vnx master-presentation
EMC Vnx master-presentationEMC Vnx master-presentation
EMC Vnx master-presentation
 
VMware vSphere 6.0 - Troubleshooting Training - Day 1
VMware vSphere 6.0 - Troubleshooting Training - Day 1VMware vSphere 6.0 - Troubleshooting Training - Day 1
VMware vSphere 6.0 - Troubleshooting Training - Day 1
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
NSX-T Architecture and Components.pptx
NSX-T Architecture and Components.pptxNSX-T Architecture and Components.pptx
NSX-T Architecture and Components.pptx
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
 
Inline command emc内部inline命令集
Inline command emc内部inline命令集Inline command emc内部inline命令集
Inline command emc内部inline命令集
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 

Kürzlich hochgeladen (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

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 !