Skip to content

This is an extension of magento-actions for gitlab-ci. Install, build, test and deploy magento.

License

Notifications You must be signed in to change notification settings

MAD-I-T/gitlab-ci-magento

Repository files navigation

gitlab-ci-magento

This is a gitlab deployer tool inspired from magento-actions for gitlab-ci users. Install, build, test and deploy magento through gitlab-ci.

Intro tutorial in video

magento zero downtime in video gitlab-ci

Also checkout

The Magento zero downtime deployment written tutorial.

Usage

Include the template (ie https://raw.githubusercontent.com/MAD-I-T/gitlab-ci-magento/v3.30/.magento-actions-full-template.yml) in your .gitlab-ci.yml and extend the of jobs/actions you want to trigger. (more about include property on gitlab)

Like in .gitlab-ci-usage-sample.yml this will trigger the build and some test. The project must respect the following scafolding :

├── .gitlab.ci
├── README.md 
├── magento # directory where you Magento source files should go 
└── pwa-studio # optional pwa-studio directory for pwa src code

You can check the .gitlab-ci-install-sample.yml to help setup the project for you. For the runner to be able to push the magento and/or pwa-studio directory to the repo. You must declare a deploys key in Settings>Repository>Deploy Keys with a write access. Watch the video below or read the article to see how to create and use the mandatory gitlab-ci variables (ssh_config, ssh key, etc...). The full list of variables are available in the template file. Also see full list of actions.

Zero-downtime tutorial in video

magento zero downtime in video gitlab-ci

If you're not familiar with CI/CD on gitlab, we do offer hands on trainning and setup, see details about the offer here

List of available actions

Install magento

If you want to push the files to the repo pass INPUT_NO_PUSH to 0.

install-magento:
  variables:
    INPUT_MAGENTO_VERSION: "2.4.5-p1"
    INPUT_NO_PUSH: 1
  extends: .install-magento:stage:install

One can use our magento-devbox as local dev env. Linux and mac os supported.

install PWA-studio

Donwload / Install the latest pwa-studio src If you want to push the files to the repo pass INPUT_NO_PUSH to 0. It is also possible to specify a specific pwa-studio version you want through INPUT_VERSION variable.

pwa-studio:stage:install:
  variables:
    INPUT_NO_PUSH: 1
  extends: .pwa-studio:stage:install

install magento from mage-os

If you want to push the files to the repo pass INPUT_NO_PUSH to 0.

install-mage-os-magento:
  variables:
    INPUT_MAGENTO_VERSION: "2.4.5-p1"
    INPUT_NO_PUSH: 1
  extends: .install-mage-os:stage:install

Run build

Run all magento and/or pwa-studio apps

build:
  extends: .build:stage

By default the build processor will try and build all available themes in your project.

Nonetheless, check the following link, if you wish to limit the build to specific theme(s) and/or locale(s). Also hyva based themes are supported.

Run all magento static tests

static-test-all:
  extends: .static-test:stage:test

Run all magento unit tests

unit-test-all:
  extends: .unit-test:stage:test

Unit test filtered by testsuite

unit-test-testsuite:
  variables:
    INPUT_TESTSUITE: "Magento_Unit_Tests_Other"
  extends: .unit-test-testsuite:stage:test

Unit test filtered by path

unit-test-custom-path
  variables:
    INPUT_UNIT_TEST_SUBSET_PATH: 'vendor/magento/module-email/Test/Unit'
  extends: .unit-test-custom-path:stage:test

Magento coding standard check

coding-standard:
  variables:
    INPUT_EXTENSION: 'magento/vendor/magento/module-email'
  extends: .coding-standard:test:stage

Run phpstan

mess-detector:
  variables:
    INPUT_PROCESS: "phpstan"
    INPUT_MD_PATH: 'magento/vendor/magento/module-email' # path to the src to analyse
  extends: phpstan:test:stage

Run mess detector

mess-detector:
  variables:
    INPUT_PROCESS: "mess-detector"
    INPUT_MD_PATH: 'magento/vendor/magento/module-email' # path to the src to mess detect
  extends: .mess-detector:test:stage

Scan magento files for vulnerabilities

security-scan-files:
  extends: .security-scan-files:stage:test

Scan magento modules for vulnerabilities

security-scan-module:
  extends: .security-scan-module:stage:test

Integration test filtered by testsuite

integration-test-testsuite:
  variables:
    INPUT_TESTSUITE: "Memory Usage Tests"
  extends: .integration-test-testsuite:stage:test

Integration test on specific class

integration-test-class:
  variables:
    INPUT_INTEGRATION_CLASS: "./testsuite/Magento/MemoryUsageTest.php"
  extends: .integration-test-class:stage:test

Integration test filtered by name

integration-test-class-filter:
  variables:
    INPUT_TESTSUITE: "Memory Usage Tests"
    INPUT_INTEGRATION_CLASS: "./testsuite/Magento/MemoryUsageTest.php"
    INPUT_INTEGRATION_FILTER: "testAppReinitializationNoMemoryLeak"
  extends: .integration-test-class-filter:stage:test

Deploy magento to staging server

deploy-staging:
  extends: .deploy-staging:stage:deploy

cleanup if the staging deployment fails

cleanup-staging:
  extends: .cleanup-staging:stage:cleanup

Deploy magento to prod

This job is dependent on a build job

deploy-production:
  extends: .deploy-production:stage:deploy

cleanup if the production deployment fails

cleanup-production:
  extends: .cleanup-production:stage:cleanup

Overriding

One can override the default scripts in the parent project (i.e magento-actions). use the INPUT_OVERRIDE_SETTINGS variable set it to 1. You'll also have to create scripts or config dirs in the root of your project. Here's an example of project scafolding to override the action's default configs

├── .gitlab-ci.yml
├── README.md 
└── magento # directory where you Magento source files should go
└── config # the filenames must be similar to thoses of the action ex: config/integration-test-config.php 
└── scripts #  ex: scripts/build.sh to override the build behaviour 

Complex strategies

Build magento only in a git repo containing magento and pwa-studio directory

build:
  variables
    INPUT_MAGENTO_ONLY: 1
  extends: .build:stage

Build pwa-studio only in a git repo containing magento and pwa-studio directory

build:
  variables
    INPUT_PWA_STUDIO_ONLY: 1
  extends: .build:stage

deploy magento only in a git repo containing magento and pwa-studio directory

deploy-production:
  variables
    INPUT_MAGENTO_ONLY: 1
  extends: .deploy-production:stage:deploy

deploy pwa-studio only in a git repo containing magento and pwa-studio directory

deploy-production:
  variables
    INPUT_PWA_STUDIO_ONLY: 1
  extends: .deploy-production:stage:deploy

Deploy magento and pwa-studio to different servers from one repo.

Apply patches & hotfixes during building process

To apply specific magento patches and hotfixes:

  • put the .patch files in m2-hotfixes directory and/or use .magento.env.yaml file (more info)
  • if .magento.env.yaml is present the patches are applied using magento qutality tools. Otherwise, the patch command line is used see here
  • then enable the patcher by setting INPUT_APPLY_PATCHES to 1 during the build process as follows :
build:
  variables
    INPUT_APPLY_PATCHES: 1
  extends: .build:stage

About

This is an extension of magento-actions for gitlab-ci. Install, build, test and deploy magento.

Resources

License

Stars

Watchers

Forks

Packages