Magento Commerce Cloud setup

Alternatively to Magento Commerce Cloud consider using ReadyMage. ReadyMage is ScandiPWA optimized cloud hosting and supports Magento Commerce projects.

ScandiPWA setup on Magento Commerce Cloud requires adjusting 2 files in the project root folder that are used for deployment flow.

bitbucket-pipelines.yaml

Requires adjustments to allow pushing code from BitBucket of the git repository to Magento Cloud project repository. CI/CD is used for this purpose. Git authentication is made using public keys. Generate the key in the BitBucket repository and add it to the Magento Cloud in the admin panel.

Here is an example of how the bitbucket-pipelines.yaml file should be configured. It contains configuration for 2 environments:

  • production (using master branch);

  • stage (using stage branch).

Replace example credentials and git links with your project actual links.

pipelines:
  branches:
    master:
      - step:
          image: luzhzh/git-client
          script:
            - set -e
            - set -o pipefail
            - git clone --branch master git@bitbucket.org:exampleorganization/exampleproject.git exampleproject
            - cd exampleproject/
            - git config --global user.email "exampleemail@example.com"
            - git config --global user.name "Deploy Script"
            - git remote add mc example@git.eu-5.magento.cloud:example.git
            - git pull --no-edit mc master
            - git push mc master
            - cd ../
            - rm -rf exampleproject.git/
    stage:
      - step:
          image: luzhzh/git-client
          script:
            - set -e
            - set -o pipefail
            - git clone --branch stage git@bitbucket.org:exampleorganization/exampleproject.git exampleproject
            - cd exampleproject/
            - git config --global user.email "exampleemail@example.com"
            - git config --global user.name "Deploy Script"
            - git remote add mc example@git.eu-5.magento.cloud:example.git
            - git pull --no-edit mc stage
            - git push mc stage
            - cd ../
            - rm -rf exampleproject.git/
definitions:
  caches:
    node-custom: app/design/frontend/ExampleProject/pwa/node_modules

magento.app.yaml

ScandiPWA compilation is done in magento.app.yaml file. Within it options and commands are configured to be run during deployment.

Here is part of the file that is responsible for ScandiPWA compilation which has to be added to the existing magento.app.yaml file content.

hooks:
    # We run build hooks before your application has been packaged.
    build: |
        set -e

        git apply m2-patches/*.patch

        unset NPM_CONFIG_PREFIX
        curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | dash
        export NVM_DIR="$HOME/.nvm"
        [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
        nvm current
        nvm install 12.16.1

        (cd ./app/design/frontend/ExampleProject/pwa/ && rm -rf node_modules && npm ci)
        (cd ./app/design/frontend/ExampleProject/pwa/ && npm run build)

        php ./vendor/bin/ece-tools run scenario/build/generate.xml
        php ./vendor/bin/ece-tools run scenario/build/transfer.xml
    # We run deploy hook after your application has been deployed and started.
    deploy: |
        php ./vendor/bin/ece-tools run scenario/deploy.xml
    # We run post deploy hook to clean and warm the cache. Available with ECE-Tools 2002.0.10.
    post_deploy: |
        php ./vendor/bin/ece-tools run scenario/post-deploy.xml

Last updated