This is a gitlab deployer tool inspired from magento-actions for gitlab-ci users. Install, build, test and deploy magento through gitlab-ci.
Also checkout
The Magento zero downtime deployment written tutorial.
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.
If you're not familiar with CI/CD on gitlab, we do offer hands on trainning and setup, see details about the offer here
- install magento from gitlab-ci
- install pwa-studio from gitlab-ci
- install magento from mage-os repo
- Magento and/or pwa-studio build
- Coding standard check
- Magento security scanners files
- Magento modules security scanner
- Unit testing
- Zero-downtime-deployer
- Integration tests
- Static testing
- Phpstan
- Mess detector
- OVERRIDING THE DEFAULT SCRIPTS
- Complex build & deploy strategies
- see more on the forum
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.
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
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 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.
static-test-all:
extends: .static-test:stage:test
unit-test-all:
extends: .unit-test:stage:test
unit-test-testsuite:
variables:
INPUT_TESTSUITE: "Magento_Unit_Tests_Other"
extends: .unit-test-testsuite:stage:test
unit-test-custom-path
variables:
INPUT_UNIT_TEST_SUBSET_PATH: 'vendor/magento/module-email/Test/Unit'
extends: .unit-test-custom-path:stage:test
coding-standard:
variables:
INPUT_EXTENSION: 'magento/vendor/magento/module-email'
extends: .coding-standard:test:stage
mess-detector:
variables:
INPUT_PROCESS: "phpstan"
INPUT_MD_PATH: 'magento/vendor/magento/module-email' # path to the src to analyse
extends: phpstan:test:stage
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
security-scan-files:
extends: .security-scan-files:stage:test
security-scan-module:
extends: .security-scan-module:stage:test
integration-test-testsuite:
variables:
INPUT_TESTSUITE: "Memory Usage Tests"
extends: .integration-test-testsuite:stage:test
integration-test-class:
variables:
INPUT_INTEGRATION_CLASS: "./testsuite/Magento/MemoryUsageTest.php"
extends: .integration-test-class:stage:test
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-staging:
extends: .deploy-staging:stage:deploy
cleanup-staging:
extends: .cleanup-staging:stage:cleanup
This job is dependent on a build job
deploy-production:
extends: .deploy-production:stage:deploy
cleanup-production:
extends: .cleanup-production:stage:cleanup
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
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.
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