Converting legacy Docker setup to CMA
srcfolder and install CMA:
# if npm is not initialized, then run
npm init -y
# then install @scandipwa/magento-scripts package
npm i @scandipwa/magento-scripts@latest
# and make sure your package.json has the following scripts:
"start": "magento-scripts start",
"stop": "magento-scripts stop",
"cli": "magento-scripts cli",
"logs": "magento-scripts logs",
"link": "magento-scripts link",
"status": "magento-scripts status",
"exec": "magento-scripts exec",
"import-db": "magento-scripts import-db"
You need to adjust
require-devdependencies, ideally just replace them with the following ones which are shipped in default Magento 2.3 template:
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.jsand your configuration for
devServershould look like this:
// comment or remove lines below
// host: '0.0.0.0',
// public: 'scandipwa.local',
// allowedHosts: [
// add this to the config
// NOTE: to get magento port you can use [npm run status] command
'/graphql': 'http://localhost:<your magento port>'
Comment or remote
allowedHostsproperties and add
proxyproperty with a value of an object with mapping
/graphqlurl to our Magento url.
If you want to use a port other than 3003 for the frontend you can! Just edit
portproperty 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.
We have adjusted the project configuration enough to start working with CMA itself. Now we can try running the project.
srcfolder and run:
npm run start
To run frontend you will need to use a command
# go to frontend folder first
npm run watch
In general, that is it!
magento-scripts will do this automatically!
To preserve data in the database, you will need to do as follows:
- 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.To get new mysql volume name, run command:docker container inspect <mysql container>and here go to the property
HostConfig.Mountsand you should see volume name in a
- 2.To get an old mysql volume name you can just use template:
folder nameis your folder name, you can get it by running
- 2.Now, stop the project and run commands below with replaced
<old_volume>name values from the steps before.npm run stop # to stop the projectdocker volume rm <new_volume>docker volume create --name <new_volume>docker run --rm -it -v <old_volume>:/from:ro -v <new_volume>:/to alpine \ash -c "cd /from ; cp -av . /to"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>
Since we are not using a clean Docker setup anymore, we don't need
Dockerfilefiles as well as
Go to the root directory of the project and run:
rm ./Makefile ./Dockerfile* ./docker-compose.*
rm -rf ./build ./opt
deployfolder often has some necessary files, like
latest.sql, so we can keep it for now.