WeareJH / workflow

A composer helper to improve development workflow
21 stars 4 forks source link

Feature Request: setting urls + cookie domain #111

Open shakyShane opened 6 years ago

shakyShane commented 6 years ago

When importing DB's from anywhere -> local, I always end up needing something like the following, can we make a helper command for it?

LOCAL_DOMAIN="daylong.m2"
LOCAL_URL="https://daylong.m2/"
workflow setup:store-config:set --base-url-secure="$LOCAL_URL"
workflow setup:store-config:set --base-url="$LOCAL_URL"
workflow sql -s "UPDATE core_config_data t SET t.value = '$LOCAL_DOMAIN' WHERE t.path = 'web/cookie/cookie_domain'"
maxbucknell commented 6 years ago

In Magento 2.2, it is possible to set configuration in config.php, and env.php. These are merged. I'd far prefer that things like base URLs were set up once in a file env.php.template, and then not touched after that.

At that point, your refined setup process with a shell script neatly solves this problem too.

maxbucknell commented 6 years ago

Another option that I've persistently used on Magento 1 and Magento 2 projects is an N98-Magerun script that sets config values. I've used these on basically every project I ever ran to automate configuration setting across environments.

In app/etc/store_config, there are four files, local.n98, dev.n98, staging.n98, and production.n98.

After pulling a database dump, running the command:

n98-magerun2 script < app/etc/store_config/local.n98

This file would contain something like:

config:store:set --scope-id=0 --scope=default -- 'web/secure/base_url' 'https://project.m2/'
config:store:set --scope-id=0 --scope=default -- 'web/unsecure/base_url' 'https://project.m2/'

config:store:set --scope-id=0 --scope=default -- 'web/secure/base_media_url' 'https://project.m2/media/'
config:store:set --scope-id=0 --scope=default -- 'web/secure/base_static_url' 'https://project.m2/static/'

config:store:set --scope-id=0 --scope=default -- 'web/unsecure/base_media_url' 'https://project.m2/media/'
config:store:set --scope-id=0 --scope=default -- 'web/unsecure/base_static_url' 'https://project.m2/static/'

config:store:set --scope-id=5 --scope=websites -- 'web/secure/base_url' 'https://project.m2/aus/'
config:store:set --scope-id=5 --scope=websites -- 'web/unsecure/base_url' 'https://project.m2/aus/'

These scripts with relevant environments would also run on deployments to the respective environments, and this would run in a nested fashion (so staging would run production.n98, followed by staging.n98, and dev would run these two in addition to dev.n98.

Since Magento 2.2, this is a worse solution than locking the values in env.php and config.php, but if we want to target every project we deliver, this is worth considering.