Giter Site home page Giter Site logo

magento2-ddev-installation's Introduction

Magento 2 installation with DDEV

Version Installation with Varnish Installation with Static and Unit tests End-to-end tests MFTF tests

A GitHub Action to install Magento 2 with DDEV.

Table of Contents

Quick start

We will suppose here that you want to test on a Magento 2.4.5 instance with PHP 8.1.

You can add the following step in your workflow:

- uses: julienloizelet/magento2-ddev-installation@v3
  with:
    php_version: "8.1"
    magento_version: "2.4.5"

This step will install a Magento 2.4.5 instance with PHP 8.1.

In the steps that follow, you will be able to run any DDEV commands to interact with the Magento 2 environment.

Inputs

Available keys

The following keys are available as step.with keys:


  • php_version (String)

PHP version to use in the web container.

Default: 8.2.

Allowed values are: 7.2, 7.3, 7.4, 8.1, 8.2, 8.3.

Please choose a PHP version that is compatible with the magento_version below.


  • database (String)

Database version and type to use.

Default: Empty.

Admissible values are those allowed by DDEV.

If empty, mariadb:10.2 will be used for Magento version < 2.4.1 and mariadb:10.4 for Magento version >= 2.4.1.

Please choose a DDEV database version and type that is compatible with the magento_version below.


  • magento_repository (String)

Where to install Magento from.

Default: https://mirror.mage-os.org/.

Could be "https://mirror.mage-os.org/", "https://repo.magento.com/" or any available repository.

Please choose a repository that handle the magento_version below.


  • magento_edition (String)

The edition of Magento to install.

Default: magento/project-community-edition

Could be "magento/project-community-edition", "magento/project-enterprise-edition" or any available edition.


  • magento_version (String)

The Magento release version to install.

Default: 2.4.7.

You can use X.Y.Z format or X.Y.Z-pN format for patch release.

Allowed versions are 2.3.0, 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.3.5, 2.3.6, 2.3.7, 2.4.0, 2.4.1, 2.4.2, 2.4.3,2.4.4, 2.4.5, 2.4.6, 2.4.7 and any of their patches versions.

Please note that available versions depend on the chosen magento_repository.


  • composer_auth (String)

Composer authentication credentials.

Default: "".

You have to pass a JSON string. For example:

{
  "http-basic": {
    "repo.magento.com": {
      "username": "**********************",
      "password": "**********************"
    }
  }
}

As GitHub allows saving multiline secret, you can use a secret to store this sensitive value. Just copy/paste the json in a M2_COMPOSER_AUTH secret and use it like this: composer_auth: ${{ secrets.M2_COMPOSER_AUTH }}.


  • varnish_setup (Boolean)

Install with ready-to-use Varnish.

Default: false.

You should use quote to set true: varnish_setup: "true".


Examples

  • Magento 2.3.7-p4 (magento/project-community-edition) , from https://repo.magento.com/, with PHP 7.4 and without Varnish:
with:
  php_version: "7.4"
  magento_version: "2.3.7-p4"
  magento_repository: "https://repo.magento.com/"
  composer_auth: ${{ secrets.M2_COMPOSER_AUTH }}
  • Magento 2.4.4 (magento/project-community-edition) , from https://mirror.mage-os.org/, with PHP 8.1 and with Varnish:
with:
  php_version: "8.1"
  magento_version: "2.4.4"
  varnish_setup: "true"

Outputs

The following keys are available as outputs keys:


  • m2_url (String)

The freshly installed Magento 2 instance url. Example: https://m245.ddev.site.


Usage

Test your Magento 2 instance

You could run all the DDEV basic commands and some specific ones coming from some DDEV add-ons

Examples

For example, you could run these commands in some other steps:

ddev magento config:set admin/security/password_is_forced 0
ddev magento config:set admin/security/password_lifetime 0
ddev magento module:disable Magento_TwoFactorAuth
ddev magento indexer:reindex
ddev magento c:c

MFTF

If you want to use the Magento Functional Testing Framework, here is an example of implementation : MFTF tests

Test a module

Once you have run this action, you will be able to install and activate a module. Thus, you will be able to run all kind of tests : static tests (coding standards), unit tests, integration tests, or any other end-to-end tests.

Examples

Before reading below, you could read the examples here:

How to

To do that, you could use the following folder structure :

$GITHUB_WORKSPACE
│   
│ (Magento 2 sources installed with composer)    
│
└───.ddev
│   │   
│   │ (DDEV files)
│   
└───my-own-modules
    │   
    │
    └───<some-path>
       │   
       │ (Sources of a module)
         

by adapting the following steps:

- name: Clone module files
  uses: actions/checkout@v4
  with:
    path: my-own-modules/<some-path>
- name: Prepare composer repositories
  run: |
      ddev composer config --unset repositories.0
      ddev composer config repositories.0 '{"type": "path", "url":"my-own-modules/<some-path>",  "canonical": true, "options": {"symlink": false}}'
      ddev composer config repositories.1 '{"type": "composer", "url":"<the-magento-repository>",  "exclude": ["<some-package-name>"]}'
- name: Add module as composer dependency
  run: ddev composer require <some-package-name>:@dev --no-interaction
- name: Install module
  run: |
    ddev magento module:enable <some-extension-name>
    ddev magento setup:upgrade

Then, you could run:

  • PHP Code Sniffer: ddev phpcs my-own-modules/<some-path>
  • PHP Mess Detector: ddev phpmd my-own-modules/<some-path>
  • PHP Stan: ddev phpstan my-own-modules/<some-path>
  • Unit test: ddev phpunit my-own-modules/<some-path>/Test/Unit

Technical details

For you information, the setup of Magento 2 is launch with the following settings:

bin/magento setup:install \
   --base-url=https://m245.ddev.site \
   --db-host=db \
   --db-name=db \
   --db-user=db \
   --db-password=db \
   --backend-frontname=admin \
   --admin-firstname=admin \
   --admin-lastname=admin \
   [email protected] \
   --admin-user=admin \
   --admin-password=admin123 \
   --language=en_US \
   --currency=USD \
   --timezone=America/Chicago \
   --use-rewrites=1 \
   --elasticsearch-host=elasticsearch --search-engine=elasticsearch7

The Magento 2 environment is a Docker environment created with DDEV and comes with the following services:

  • web: PHP (version depends on php_version input), nginx-fpm, NodeJs
  • db: Depends on the database input
  • elastisearch
  • memcached
  • redis

Finally, the structure of your $GITHUB_WORKSPACE will look like below.

$GITHUB_WORKSPACE
│   
│ (Magento 2 sources installed with composer)    
│
└───.ddev
    │   
    │ (DDEV files)

License

MIT

Contribute

Anyone is welcome to submit a pull request to this repository.

Contributed and maintained by julienloizelet

magento2-ddev-installation's People

Contributors

julienloizelet avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

berkcelc

magento2-ddev-installation's Issues

Installation fails from some versions of Magento since DDEV 1.23.0

Starting with DDEV 1.23.0 (released on 2024-04-17), it looks like the used MariaDb version is not compatible anymore with some Magento versions.

For example, it failed for Magento 2.4.0 with this error message:

Current version of RDBMS is not supported. Used Version: 10.6.17-MariaDB-1:  
  10.6.17+maria~ubu2004-log. Supported versions: MySQL-8, MySQL-5.7, MariaDB-  
  (10.2-10.4)        

(see https://github.com/julienloizelet/magento2-ddev-installation/actions/runs/8718767718/job/23916680766)

We could let the user pass it as a new input (like the php_version input).

Something like database:"mysql:5.7" , or database:"mariadb:10.2" with a default value to something compatible with a maximum of Magento versions (probably mysql:5.7)

Running the Action script locally using nektos/act fails

Hi @julienloizelet,
First, I would like to thank you for creating and sharing the very useful GitHub Action.

I have been trying to test it locally using https://github.com/nektos/act.

The process runs fine until a certain point, and then it fails.
Following is the relevant output.

Do you know what's causing it and how it could be resolved?

Much appreciate it!

Itay

....
| Created a new local CA 💥
| The local CA is now installed in the system trust store! ⚡️
| 
| Could not connect to a docker provider. Please start or install a docker provider.
| For install help go to: https://ddev.readthedocs.io/en/latest/users/install/
[Coding standards/Static test suite]   ❌  Failure - Main Install DDEV
[Coding standards/Static test suite] exitcode '1': failure
[Coding standards/Static test suite]   ⚙  ::set-output:: m2_url=
[Coding standards/Static test suite]   ❌  Failure - Main Install Magento 2
[Coding standards/Static test suite] exitcode '1': failure
[Coding standards/Static test suite] ⭐ Run Post Install Magento 2
[Coding standards/Static test suite]   🐳  docker cp src=/Users/itay/.cache/act/[email protected]/ dst=/var/run/act/actions/[email protected]/
[Coding standards/Static test suite]   🐳  docker exec cmd=[chown -R 1001:1001 /var/run/act/actions/[email protected]/] user=0 workdir=
[Coding standards/Static test suite]   ✅  Success - Post Install Magento 2
[Coding standards/Static test suite] 🏁  Job failed
Error: Job 'Static test suite' failed

...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.