Converting legacy Docker setup to CMA
We have an older magento-docker setup for ScandiPWA 1, 2, 3 but since it is not very versatile when it comes to development, you can "upgrade" it to use CMA!

1. Install CMA

Go to src folder and install CMA:
1
# if npm is not initialized, then run
2
npm init -y
3
4
# then install @scandipwa/magento-scripts package
5
npm i @scandipwa/[email protected]
6
7
# and make sure your package.json has the following scripts:
8
{
9
...
10
"scripts": {
11
"start": "magento-scripts start",
12
"stop": "magento-scripts stop",
13
"cli": "magento-scripts cli",
14
"logs": "magento-scripts logs",
15
"link": "magento-scripts link",
16
"status": "magento-scripts status",
17
"exec": "magento-scripts exec",
18
"import-db": "magento-scripts import-db"
19
}
20
...
21
}
Copied!

2. Adjust composer dev packages

You need to adjust require-dev dependencies, ideally just replace them with the following ones which are shipped in default Magento 2.3 template:
1
{
2
...
3
"require-dev": {
4
"allure-framework/allure-phpunit": "~1.2.0",
5
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
6
"friendsofphp/php-cs-fixer": "~2.14.0",
7
"lusitanian/oauth": "~0.8.10",
8
"magento/magento-coding-standard": "*",
9
"magento/magento2-functional-testing-framework": "~2.6.4",
10
"pdepend/pdepend": "2.5.2",
11
"phpcompatibility/php-compatibility": "^9.3",
12
"phpmd/phpmd": "@stable",
13
"phpstan/phpstan": "^0.12.2",
14
"phpunit/phpunit": "~6.5.0",
15
"sebastian/phpcpd": "~3.0.0",
16
"squizlabs/php_codesniffer": "~3.4.0"
17
}
18
...
19
}
Copied!

3. Adjust theme webpack configuration

Magento does not serve theme files in older ScandiPWA versions so we need to reconfigure webpack devserver.
Go to file app/design/frontend/Scandiweb/pwa/src/config/webpack.development.config.js and your configuration for devServer should look like this:
webpack.development.config.js
1
{
2
watchContentBase: true,
3
publicPath: '/',
4
historyApiFallback: true,
5
port: 3003,
6
https: false,
7
overlay: true,
8
compress: true,
9
inline: true,
10
hot: true,
11
// comment or remove lines below
12
13
// host: '0.0.0.0',
14
// public: 'scandipwa.local',
15
// allowedHosts: [
16
// '.local'
17
// ],
18
19
// add this to the config
20
// NOTE: to get magento port you can use [npm run status] command
21
proxy: {
22
'/graphql': 'http://localhost:<your magento port>'
23
}
24
}
Copied!
Comment or remote host, public and allowedHosts properties and add proxy property with a value of an object with mapping /graphql url to our Magento url.
[NOTE] You can define Magento port using --port option in start command. (Docs)
If you want to use a port other than 3003 for the frontend you can! Just edit port property in this config file.
Note that you cannot use ports below 1024 because it will require root privileges and for your own safety we do not recommend running scripts as root.

4. Run the project and resolve possible issues.

We have adjusted the project configuration enough to start working with CMA itself. Now we can try running the project.
Go to src folder and run:
1
npm run start
Copied!
To run frontend you will need to use a command watch:
1
# go to frontend folder first
2
cd app/design/frontend/Scandiweb/pwa
3
4
npm run watch
Copied!
In general, that is it!

[BONUS]

Preserve data from the old setup

To preserve data in the database, you will need to do as follows:
  1. 1.
    After you run magento setup, new MySQL volume will be created. You will need to get old mysql volume name and new one.
    1. 1.
      To get new mysql volume name, run command:
      1
      docker container inspect <mysql container>
      Copied!
      and here go to the property HostConfig.Mounts and you should see volume name in a Source field.
    2. 2.
      To get an old mysql volume name you can just use template: <folder name>_mysql-data where folder name is your folder name, you can get it by running basename "$PWD" command.
  2. 2.
    Now, stop the project and run commands below with replaced <new_volume> name and <old_volume> name values from the steps before.
    1
    npm run stop # to stop the project
    2
    3
    docker volume rm <new_volume>
    4
    5
    docker volume create --name <new_volume>
    6
    7
    docker run --rm -it -v <old_volume>:/from:ro -v <new_volume>:/to alpine \
    8
    ash -c "cd /from ; cp -av . /to"
    Copied!
    That's it! If you want to save some space, you can delete the old volume altogether by running the command: docker volume rm <old_volume>

Delete unsed files

Since we are not using a clean Docker setup anymore, we don't need docker-compose.*.yml files, Dockerfile files as well as build and opt folder.
Go to the root directory of the project and run:
1
rm ./Makefile ./Dockerfile* ./docker-compose.*
2
3
rm -rf ./build ./opt
Copied!
deploy folder often has some necessary files, like latest.sql , so we can keep it for now.
Last modified 5mo ago