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:
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:
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:
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:
To run frontend you will need to use a command watch
:
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:
After you run magento setup, new MySQL volume will be created. You will need to get old mysql volume name and new one.
To get new mysql volume name, run command:
and here go to the property
HostConfig.Mounts
and you should see volume name in aSource
field.To get an old mysql volume name you can just use template:
<folder name>_mysql-data
wherefolder name
is your folder name, you can get it by runningbasename "$PWD"
command.
Now, stop the project and run commands below with replaced
<new_volume>
name and<old_volume>
name values from the steps before.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:
deploy
folder often has some necessary files, like latest.sql
, so we can keep it for now.
Last updated