Hello, how is it possible with the docker/sdk to u...
# docker
b
Hello, how is it possible with the docker/sdk to use an external database instead of the docker image?
h
you should be able to configure another database via the
config_default-X.php
Copy code
$config[PropelConstants::ZED_DB_HOST] = 'external_host_name_or_ip';
👍 1
p
Agree. Just provide your external db credentials via env vars.
👍 1
b
is this somehow documented? what are the parameter for user?
should i create this file?
p
Check config/Shared/config_default.php as an example. It has something like
Copy code
$config[PropelConstants::ZED_DB_ENGINE]
    = $config[PropelQueryBuilderConstants::ZED_DB_ENGINE]
    = strtolower(getenv('SPRYKER_DB_ENGINE') ?: '') ?: PropelConfig::DB_ENGINE_PGSQL;
$config[PropelConstants::ZED_DB_HOST] = getenv('SPRYKER_DB_HOST');
$config[PropelConstants::ZED_DB_PORT] = getenv('SPRYKER_DB_PORT');
$config[PropelConstants::ZED_DB_USERNAME] = getenv('SPRYKER_DB_USERNAME');
$config[PropelConstants::ZED_DB_PASSWORD] = getenv('SPRYKER_DB_PASSWORD');
$config[PropelConstants::ZED_DB_DATABASE] = getenv('SPRYKER_DB_DATABASE');
$config[PropelConstants::ZED_DB_REPLICAS] = json_decode(getenv('SPRYKER_DB_REPLICAS') ?: '[]', true);
$config[PropelConstants::USE_SUDO_TO_MANAGE_DATABASE] = false;
Env var for user for example is SPRYKER_DB_USERNAME.
👍 1
Check the docs for how to set env vars via deploy file: https://documentation.spryker.com/docs/deploy-file-reference-10
👍 1
b
many thanks, i see now ZED_DB_USERNAME and ZED_DB_PASSWord for our postgres setuop, but i dont get it how in the file is written ZED_DB_USERNAME and then you say SPRYKER_DB_USERNAME as variable
aaaaahhhhh
i got it now with the variables 🙂
p
Follow the documentation. Add your env vars to e. g. deploy.dev.yml, then run
Copy code
docker/sdk bootstrap deploy.dev.yml
docker/sdk up
Then, you should be able to use your env var values in config_default.php.
I'm assuming that you're using the docker/sdk. In case your changes are needed for local development as a start, I'd recommend to use deploy.dev.yml for configuring env vars. This will affect your local env only. Also be aware that security-wise it's really bad to have credentials in yml files and commit them to your code repository. Unfortunately, Spryker doesn't offer anything better out of the box. At least nothing that I'm aware of. We decided to use Dotenv to load local .env files instead of adding sensitive env vars to deploy files. Those .env files aren't committed to the code repo. But I leave that up to you, just mentioning.
b
Yeah I first need to get warmth with this. 🙂 When i once understand how it works we will move the credentials to local .env
p
I can recommend to use composer package
symfony/dotenv
. Then in e. g. config_default do
Copy code
$dotenv = new Dotenv();
$dotenv->usePutenv();
$dotenv->load(sprintf('%s/../../.env.local', __DIR__));
Then you can get your env vars via
getenv()
.
👍 1
b
where in the deploy.yml need i to put
Copy code
SPRYKER_DB_ENGINE: "DB_ENGINE_PGSQL"
     SPRYKER_DB_HOST: "xxxx"
     SPRYKER_DB_PORT: "5432"
     SPRYKER_DB_USERNAME: "xxxx"
     SPRYKER_DB_PASSWORD: "xxxx"
     SPRYKER_DB_DATABASE: "postgres"
? in your mention documentation i can't flolow where to put this. Otherwise please show with heading line i need to re-read
b
ah merci
i did this now and following error happens: `
Copy code
Running generator
PHP Notice:  Undefined index: DE in /data/index.php on line 210
PHP Notice:  Undefined index: DE in /data/index.php on line 303
PHP Warning:  array_replace_recursive(): Expected parameter 1 to be an array, null given in /data/index.php on line 304
PHP Notice:  Undefined index: DE in /data/index.php on line 318
PHP Notice:  Undefined index: DE in /data/index.php on line 210
PHP Fatal error:  Uncaught Twig\Error\LoaderError: Template "env/database/.env.twig" is not defined in "env/application/zed.env.twig" at line 25. in /data/vendor/twig/twig/src/Loader/ChainLoader.php:98
Stack trace:
#0 /data/vendor/twig/twig/src/Environment.php(299): Twig\Loader\ChainLoader->getCacheKey('env/database/.e...')
#1 /data/vendor/twig/twig/src/Environment.php(381): Twig\Environment->getTemplateClass('env/database/.e...')
#2 /data/vendor/twig/twig/src/Template.php(335): Twig\Environment->loadTemplate('env/database/.e...', NULL)
#3 /data/vendor/twig/twig/src/Environment.php(418) : eval()'d code(68): Twig\Template->loadTemplate('env/database/.e...', 'env/application...', 25)
#4 /data/vendor/twig/twig/src/Template.php(407): __TwigTemplate_64e7675df8da3481952f197c98ec39fc33132be6d48b6a901bfbd8429e3ca59d->doDisplay(Array, Array)
#5 /data/vendor/twig/twig/src/Template.php(380): Twig\Template->displayWithErrorHandling(Array, Array)
#6 /data/vendor/twig/twig/src/Template.php(392): Twig\Template->display(Array)
#7 /data/vendor in /data/vendor/twig/twig/src/Loader/ChainLoader.php on line 98
p
Hm... I think it still tries to init the local db that you don't want to use. Check if removing the services > database from deploy-dev.yml helps. There's still a chance that it's not that easy to connect an external db. I'm just guessing, too. Maybe somebody from Spryker can jump in and enlighten us.
b
Sadly not the database service i removed before
@gorgeous-yacht-94368 fyi
@polite-lunch-97479 do you have a working deploy.yml which you could anomyze and send us?
with this external db variables?
p
No. We're connecting to the db the standard way, haven't done what you're trying to achieve. Our env vars for local environment are all taken from .env.local.
h
what isn't working exactly? you should be able just to edit the config and it should connect
b
the bootstrap is not working with following deploy.yml file the error message is
h
It won’t work this way. All the env vars defined in image (in deploy.yml) will be overridden by env vars coming from docker. You need to remap env vars (use new custom ones) in config_default… and then you can set them in deploy.yml. According the error. You still need database defined in deploy.yml. docker/sdk cannot work without it at the moment. And it won’t be a problem for you if you have custom config for the database.