* Magento: Fix artifact_path generation - Fix 1. Add -p parameter to mkdir command {{artifact_path}} could be configured with multiple folders such as build/artifacts - Fix 2. run() -> runLocally() The {{artifact_dir}} is used to keep artifacts archive file. It should be called at CI server only and not at target server. Then the task `artifact:upload` uploads this file at target server host under {{release_path}}. It is not needed to have {{artifact_dir}} at target server. * Update docs
12 KiB
How to Deploy a Magento 2 Project
require 'recipe/magento2.php';
Deployer is a free and open source deployment tool written in PHP. It helps you to deploy your Magento 2 application to a server. It is very easy to use and has a lot of features.
Three main features of Deployer are:
- Provisioning - provision your server for you.
- Zero downtime deployment - deploy your application without a downtime.
- Rollbacks - rollback your application to a previous version, if something goes wrong.
Additionally, Deployer has a lot of other features, like:
- Easy to use - Deployer is very easy to use. It has a simple and intuitive syntax.
- Fast - Deployer is very fast. It uses parallel connections to deploy your application.
- Secure - Deployer uses SSH to connect to your server.
- Supports all major PHP frameworks - Deployer supports all major PHP frameworks.
You can read more about Deployer in Getting Started.
The deploy task of Magento 2 consists of:
- deploy:prepare – Prepares a new release
- deploy:info – Displays info about deployment
- deploy:setup – Prepares host for deploy
- deploy:lock – Locks deploy
- deploy:release – Prepares release
- deploy:update_code – Updates code
- deploy:shared – Creates symlinks for shared files and dirs
- deploy:writable – Makes writable dirs
- deploy:vendors – Installs vendors
- deploy:clear_paths – Cleanup files and/or directories
- deploy:magento – Magento2 deployment operations
- magento:build – Magento2 build operations
- magento:compile – Compiles magento di
- magento:deploy:assets – Deploys assets
- magento:config:import – Config Import
- magento:upgrade:db – Upgrades magento database
- magento:cache:flush – Flushes Magento Cache
- magento:build – Magento2 build operations
- deploy:publish – Publishes the release
- deploy:symlink – Creates symlink to release
- deploy:unlock – Unlocks deploy
- deploy:cleanup – Cleanup old releases
- deploy:success –
The magento2 recipe is based on the common recipe.
Configuration
static_content_locales
By default setup:static-content:deploy uses en_US
.
To change that, simply put set('static_content_locales', 'en_US de_DE');
in you deployer script.
'en_US'
magento_themes
You can also set the themes to run against. By default it'll deploy
all themes - add('magento_themes', ['Magento/luma', 'Magento/backend']);
[
]
static_content_jobs
Also set the number of conccurent jobs to run. The default is 1
Update using: set('static_content_jobs', '1');
'1'
content_version
return time();
shared_files
Overrides shared_files from recipe/deploy/shared.php
.
[
'app/etc/env.php',
'var/.maintenance.ip',
]
shared_dirs
Overrides shared_dirs from recipe/deploy/shared.php
.
[
'var/composer_home',
'var/log',
'var/export',
'var/report',
'var/import',
'var/import_history',
'var/session',
'var/importexport',
'var/backups',
'var/tmp',
'pub/sitemap',
'pub/media',
'pub/static/_cache'
]
writable_dirs
Overrides writable_dirs from recipe/deploy/writable.php
.
[
'var',
'pub/static',
'pub/media',
'generated',
'var/page_cache'
]
clear_paths
Overrides clear_paths from recipe/deploy/clear_paths.php
.
[
'generated/*',
'pub/static/_cache/*',
'var/generation/*',
'var/cache/*',
'var/page_cache/*',
'var/view_preprocessed/*'
]
magento_version
// detect version
$versionOutput = run('{{bin/php}} {{release_or_current_path}}/bin/magento --version');
preg_match('/(\d+\.?)+(-p\d+)?$/', $versionOutput, $matches);
return $matches[0] ?? '2.0';
maintenance_mode_status_active
// detect maintenance mode active
$maintenanceModeStatusOutput = run("{{bin/php}} {{release_or_current_path}}/bin/magento maintenance:status");
return strpos($maintenanceModeStatusOutput, MAINTENANCE_MODE_ACTIVE_OUTPUT_MSG) !== false;
enable_zerodowntime
Deploy without setting maintenance mode if possible
true
artifact_file
artifact deployment section settings section
'artifact.tar.gz'
artifact_dir
'artifacts'
artifact_excludes_file
'artifacts/excludes'
build_from_repo
If set to true, the artifact is built from a clean copy of the project repository instead of the current working directory
false
repository
Overrides repository from recipe/common.php
.
Set this value if "build_from_repo" is set to true. The target to deploy must also be set with "--branch", "--tag" or "--revision"
null
artifact_path
if (!testLocally('[ -d {{artifact_dir}} ]')) {
runLocally('mkdir -p {{artifact_dir}}');
}
return get('artifact_dir') . '/' . get('artifact_file');
bin/tar
:::info Autogenerated The value of this configuration is autogenerated on access. :::
additional_shared_files
Array of shared files that will be added to the default shared_files without overriding
additional_shared_dirs
Array of shared directories that will be added to the default shared_dirs without overriding
Tasks
magento:compile
Compiles magento di.
Tasks
magento:deploy:assets
Deploys assets.
magento:sync:content_version
Syncs content version.
magento:maintenance:enable
Enables maintenance mode.
magento:maintenance:disable
Disables maintenance mode.
magento:config:import
Config Import.
magento:upgrade:db
Upgrades magento database.
magento:cache:flush
Flushes Magento Cache.
deploy:magento
Magento2 deployment operations.
This task is group task which contains next tasks:
magento:build
Magento2 build operations.
This task is group task which contains next tasks:
deploy
Deploys your project.
This task is group task which contains next tasks:
artifact:package
Packages all relevant files in an artifact.
tasks section
artifact:upload
Uploads artifact in release folder for extraction.
artifact:extract
Extracts artifact in release path.
build:remove-generated
Clears generated files prior to building.
build:prepare
Prepare local artifact build.
deploy:additional-shared
Adds additional files and dirs to the list of shared files and dirs.