I'm having issues setting the CRYPT_KEY environment variable in production mode. I can see CRYPT_KEY and env:CRYPT_KEY using the magento-cloud variable:list command, but it isn't recognized when I run docker commands. Inside bin/magento-docker bash, if I run vendor/bin/ece-tools env:config:show, I see the admin email and password that are used to login to the docker container. It looks like ece-tools inside magento-docker bash show the environment variables that are used, and the environment variables from magento-cloud variables:list aren't copied to docker. Would someone be able to explain the difference between these two commands, and how to set CRYPT_KEY inside magento-docker?
I got some help from Joe Shelton, wagento-joe, on the magento Slack, #cloud-docker channel.
magento-cloud CLI manages Cloud environments. It won't interact with a local environment or docker environment.
The crypt key can be set manually in the env.php file, but it seems that the file was overwritten in one of the build steps.
To set environment variables locally, use docker-compose.override.yml or .docker/config.env. I used .docker/config.env. MAGENTO_CLOUD_VARIABLES inside .docker/config.env is a base64 encoded json string.
To set a new crypt key:
- In the Magento instance admin, go to System > Other Settings > Manage Encryption Key
- Generate a new key and save it for later
- Decode MAGENTO_CLOUD_VARIABLES in .docker/config.env to get the existing cloud variables
- Add the crypt key with CRYPT_KEY as the JSON key
- Encode the JSON and replace the existing MAGENTO_CLOUD_VARIABLES with the encoded JSON string