Magento2 Deployment with Deployer (Skeleton)

Overview

MageDeploy2 Base

Magento2 Deployment Setup using Robo and Deployer. This is the base project you should base your deployments on. It provides an configurable and customizable setup to create push deployments for Magento2.

Getting Started

Requirements

  • deployer/deployer
  • consolidation/robo
  • mwltr/magedeploy2
  • netz98/n98-deployer

Prerequisites

MageDeploy2 requires deployer and robo to be available on your system.

Those Tools can be used globaly or added as a requirement to your local composer.json.

The path to those tools can be configured in the magedeploy2.php

Furthermore gtar ( gnu-tar) is required, it can be installed via brew

brew install gnu-tar

Installation

Create a new deployment setup

composer create-project mwltr/magedeploy2-base <dir>

Robo needs to be installed using composer, otherwise the usage of custom Tasks is not available. See the Robo Documentation Including Additional Tasks

Configure Deployment

This tool assumes you have a git repository containing the magento composer.json. Furthermore your local build environment can clone said repository and download the Magento packages using composer.

MageDeploy2 Configuration

To configure the MageDeploy2 use the following command:

./vendor/bin/robo config:init

It will guide you throught the most important configuration options. Don't worry you can edit the magedeploy2.php lateron.

Next, run

./vendor/bin/robo validate

to validate your build environment is setup.

Setup local build environment

If you are done with the configuration in magedeploy2.php, you can see if your build environment can be setup. To do so run this command:

./vendor/bin/robo deploy:magento-setup develop

You can use a different branch depending on your git repository setup.

After the magento-setup has run successfully, you can now generate the assets by running the command:

./vendor/bin/robo deploy:artifacts-generate

After this command is complete you should see the packages beneath shop.

At this point we are sure that the local build setup is working and we can now continue with releasing our project.

Deployer Configuration

After the Installation and general configuration of magedeploy2, you have to edit the deploy.php file to suit your needs. To evaluate we will create a local deployment target. To do so create run

cp config/local.php.dist config/local.php

and set the config values according to your local deploy target.

Check the configuration in deploy.php and adjust it to your requirements. The default configurations and tasks are defined in \N98\Deployer\Recipe\Magento2Recipe. You can also have a look at all the configurations available in the Deployer Documentation

Setting up deploy directory tree

After you are done with setting the configuration, you can now initialize the directory tree of the deploy target run

./vendor/bin/dep deploy:prepare local

This will create the required directories on your local deploy target.

Setting up deploy target (optional)

If you want to set up your deploy target as well you can use the command

./vendor/bin/dep server:setup local

It will make an initial deployment to push your code to the deploy target.

When this is done navigate to your local deploy_path and run the magento install command to setup the database. This might look something like this:

cd <deploy_path>
php bin/magento setup:install --db-host=127.0.0.1 --db-name=magedeploy2_dev_test_1_server --db-user=root [email protected] 
--admin-firstname=Admin --admin-lastname=Admin --admin-password=admin123 --admin-user=admin 
--backend-frontname=admin --base-url=http://magedeploy2_dev --base-url-secure=https://magedeploy2_dev 
--currency=EUR --language=en_US --session-save=files --timezone=Europe/Berlin --use-rewrites=1

Now we have Magento database and configuration on our deploy target and are ready to continue with the final step.

Deploying the project

At this point, you have setup the build environment and target environment and can finally start with the actual deployment. You can do so by running:

./vendor/bin/dep deploy local

Congrats you have successfully setup your deployment pipeline and run the first deployment!

CONFIGURATION FILES

magedeploy2.php

This is the config file to set all parameters required for the deployment in general.

The most common settings are to adjust on a project basis:

  • deploy/git_url (path to your git repository)
  • deploy/themes (the themes that are to be generated)
  • build/db (the database settings for the build environment)

A complete list of configuration options is provided further down.

env

Key Description Default
git_bin Path to git executable /usr/local/bin/git
php_bin Path to php executable /usr/local/bin/php
tar_bin Path to tar executable /usr/local/bin/gtar
composer_bin Path to composer executable /usr/local/bin/composer.phar
deployer_bin Path to deployer executable /usr/local/bin/deployer.phar

deploy

Key Description Default
git_url Git-Url to your repository
git_dir Sub-directory on build server to clone the repository to shop
app_dir If you have your magento composer.json in another sub-dir
themes An array of themes to compile
assets List of assets to generate
clean_dirs list of dirs to clean on each deployment

build/db

Contains the database configuration being used to create and update a local magento setup during deployment.

deploy.php

This file is for the actual deployment of your project to the server. It has a basic setup that should work on most of the environments. You can adjust this to your needs as well. Leave out unwanted steps, add new ones, exchange existing ones, etc.

The deploy.php uses the N98\Deploy\Recipe\Magento2Recipe as base recipe and overwrites some of the default settings.

The server configuration is defined using the config/*.php files.

CUSTOM PROJECT CHANGES

General

Replace all ADD_XXX to suit your demands.

Files to customize and check:

.ssh/config

This deployment uses a native ssh client with a ssh-config file per default. It needs to be defined in .ssh/config and needs to match with your server configs beneath config.

CAUTION

The Hostname in the .ssh/config has to be an IP otherwise an error during the deployment will occur.

.ssh/known_hosts

A list of known hosts can also be added within this directory: .ssh/known_hosts Keys can be added here, e.g.

  • 127.128.129.130 ssh-rsa {long_public_key}
  • 127.128.129.131 ssh-rsa {long_public_key2}

config/*

Take a look at config/production.php and config/staging.php` and change it accordingly.

Jenkinsfile

The Jenkinsfile defines the Jenkins Pipeline. It has to be adjusted to the project needs.

deploy.php

deploy.php is the main entry point that can be used to customize.

Getting Started

Install dependencies with composer install

start deployment with ./dep deploy staging

COMMANDS

config:init

Generate a new magedeploy2.php. Be aware: this will overwrite your existing configuration

validate

Validates that

  • the bin config values are execuatble,
  • the git repository is reachable

deploy

Triggers the deployment with all it's stages

deploy:magento-setup

Runs all tasks in the stage magento-setup. It will setup or update a local Magento instance by pulling the source-code from git, installing composer dependencies and installing or updating a local database.

deploy:artifacts-generate

Runs the Magento di:compile and setup:static-content-deploycommands to generate the assets. It is using your configurartion from the magedeploy2.php.

After generating those assets it will create packages, again according to your configuration.

deploy:deploy

This command will invoke deployer to release your project and push the prepared artifacts to the server.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Matthias Walter - Initial work - mwr

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Comments
  • What is the new expected way to run cleanup

    What is the new expected way to run cleanup

    I noticed CleanupTasks was removed from n98/deployer, also your upgrade documentation mentions removing CleanupTasks from the pipeline.

    I wonder how are release rotation supposed to be handled in the new version.

    opened by barbazul 2
  • Add a task/step to build assets with HTTPS

    Add a task/step to build assets with HTTPS

    If you are planning on using HTTPS (which, you should) Magento requires an additional run of static-content:deploy with the environment variable HTTPS set to "on" in order to produce output in the secure subfolder.

    Now, the only files generated in this subfolder are requirejs configuration files, so the second run does not need to recreate all the JS and CSS.

    Right now, I am running the following command manually after each deploy (we are not yet on production) which fix the issues found:

    export HTTPS=on; php bin/magento setup:static-content:deploy --no-javascript --no-css --no-less --no-images --no-fonts --no-html --no-misc --no-html-minify en_US es_AR

    The --no-* arguments prevent all assets from being generated again.

    This extra run should be mandatory, and not optional I think (it should be part of the default Magento command).

    opened by barbazul 2
  • Prevent error

    Prevent error "Call to undefined function Deployer\local()"

    When following the readme an error "Call to undefined function Deployer\local()" occured while using the "local" deployment based on the file config/local.php.dist.

    When changing the function call to $local = localhost('local'); everything works as expected.

    opened by decius7bc 1
  • cachetool not compatible with php < 7.1 anymore

    cachetool not compatible with php < 7.1 anymore

    The task "cachetool:clear:opcache" from "deployer/recipies" always downloads the most up to date version. As of today this is version 4.0.0. But this is not compatible with PHP versions smaller than 7.1 anymore (https://github.com/gordalina/cachetool/issues/73).

    The deployer recipe is already updated and can be used with version 6.1.2 (https://github.com/deployphp/recipes/releases/tag/6.1.2). But currently the composer.json here does not load the 6.1.x versions.

    opened by shuryoka 0
  • Initial Deployments - Init Database

    Initial Deployments - Init Database

    For first time deployments to a server it might be helpful to have a command available that can initialize the database on the remote server for us.

    The connection to that database would need to provided some how.

    Not sure yet how to achieve this in the best way.

    opened by mwr 0
  • Add Documentation on how-to add custom RoboTasks or DeployTasks

    Add Documentation on how-to add custom RoboTasks or DeployTasks

    Per project one might have to have to customize exsting tasks or add additional tasks.

    There needs to be some documentation on how to create local tasks beneath a src dir. Furthermore some doc on how to include tasks using composer might be helpful as well.

    opened by mwr 2
  • Create environment specific configuration (local/build)

    Create environment specific configuration (local/build)

    At the moment there is only one magedeploy.php with one configuration for the build database. The database authentication data might probably differ between local setups and a build-server. So there needs to be a solution on having both.

    opened by mwr 0
Owner
Matthias Walter
Senior PHP Developer working with Magento2, laravel, symfony
Matthias Walter
Extract and evolution of the magento2-currency-precision module from the magento2-jp project from @Magento

Currency Precision Module for Magento 2 This module aims to help merchants to manage easily their currency precision in Magento 2. DISCLAIMER Initiall

OpenGento 3 Dec 17, 2021
Magento2 Turkish Translation / Magento2 Türkçe Çevirisi

Magento 2 Türkçe Dil Paketi Magento2 için Türkçe Dil Paketi Magento2 içinde standart olarak gelen tüm tercüme dosyaları derlenmiş ve bu paket oluşturu

Hidayet Ok 28 Dec 13, 2022
Tool based on deployer.org to perform zero downtime deployments of Magento 2 projects

Magento 2 Deployer Plus Reliable fully-automated deployments tool for Magento 2. Zero downtime deployments on Magento versions >= 2.2 Automating your

Juan Alonso 194 Dec 27, 2022
Docker-magento2 - 🐳 Docker containers with all required Magento 2 dependencies installed available as FPM through Nginx and CLI

Magento 2 Docker A collection of Docker images for running Magento 2 through nginx and on the command line. Quick Start cp composer.env.sample compose

Meanbee 454 Dec 27, 2022
Magento2 + Varnish + PHP7 + Redis + SSL (cluster ready)

Docker Magento2: Varnish + PHP7 + Redis + SSL cluster ready docker-compose infrastructure Infrastructure overview Container 1: MariaDB Container 2: Re

Fabrizio Balliano 332 Dec 30, 2022
Guest to Customer for Magento2 - Quickly and easily convert existing guest checkout customers to registered customers.

Guest to Customer for Magento 2.0 For Magento 2.0.x, 2.1.x, 2.2.x, 2.3.x and 2.4.x In general E-commerce, shoppers do not like to create an account du

MagePal :: Magento Extensions 66 Oct 7, 2022
Magento2 British Language Pack (en_GB)

Links Website: https://github.com/cubewebsites/magento2-language-en-gb What's Up With The Fork? This fork is created from the original for 3 main reas

Ashraf Vali 3 Apr 28, 2021
Magento2 Spanish (Argentina) language pack build from Crowdin community translation tool.

Magento2-language-es_ar Magento2 Spanish (Argentina) language pack build from Crowdin community translation tool. Paquete de idioma de Español (Argent

SemExpert 2 Apr 7, 2021
Simple Gulpfile for Magento2

Magento 2 gulpfile Gulp tasks and configuration necessary to setup gulp-based front-end workflow for deploying and watching theme customizations. Requ

Rocket Web FED 18 May 18, 2021
Developer Toolbar for Magento2

Developer Toolbar for Magento2 About Hope this debug toolbar can speed up Magento2 development module. Any feedback and idea to improve this toolbar w

Vincent Pietri 423 Dec 28, 2022
A simple script to convert extensions from Magento1 to Magento2

ConvertM1M2 Background The purpose of this script is to automate as much as possible the initial conversion of a Magento 1 extension, and allow develo

Boris Gurvich 144 Dec 14, 2022
Magento2 Plugin for Conversion Pixel/API of Tiktok

Tiktok Conversion Pixel Analytics Plugin Magento2 Table of Contents About Getting Started About Tiktok Pixel is the Plugin used to track events, which

Rishi Gupta 3 Jun 27, 2022
Laradeploy offers you to automate deployment using a GitHub webhook.

Introduction Laradeploy offers you to automate deployment using a GitHub webhook. Simple and fast just make a git push to GitHub deploy the new modifi

Gentrit Abazi 10 Feb 21, 2022
Nextcloud AIO stands for Nextcloud All In One and provides easy deployment and maintenance with most features included in this one Nextcloud instance.

Nextcloud All In One Beta This is beta software and not production ready. But feel free to use it at your own risk! We expect there to be rough edges

Nextcloud 1.1k Jan 4, 2023
Magento Deployment Scripts

Magento Deployment Scripts Author: Fabrizio Branca This is a collection of scripts used to build/package, deploy and install Magento projects. Import

AOE 71 Sep 29, 2022
Lumen on Docker - Skeleton project with Nginx, MySQL & PHP 8 | Aws ECS, Google Kubernates, Azure Container Engine

Docker infrastructure for Lumen Description Microservice Lumen is a starting skeleton based on Docker and Lumen Framework. This project helps to devel

Fabrizio Cafolla 218 Sep 25, 2022
🧬 Nano is a zero-config, no skeleton, minimal Hyperf distribution that allows you to quickly build a Hyperf application with just a single PHP file.

Nano is a zero-config, no skeleton, minimal Hyperf distribution that allows you to quickly build a Hyperf application with just a single PHP file.

Hyperf 273 Jan 4, 2023
It is a simple blog application coded with PHP, HTML, CSS. You can develop, edit. You can see it as a skeleton. ⚡

PHP-BLOG-SYSTEM Simple blog system Features Adding Text Update Text Text Deletion User Login and register Bootstrap Design Profile Page How to use blo

Selçuk 2 Aug 21, 2022
PHP Framework - Damian PHP - Skeleton

Damian PHP Framework - Skeleton A powerful PHP Framework in PHP 8.1 - Beautiful code & Elegant syntax This Open Source Framework is developed by Steph

Stephen Damian - Laravel Developer 2 Dec 15, 2022