What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hello, how is it possible with the docker/sdk to use an external database instead of the docker imag

U01RA9UPLG1
U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

Hello, how is it possible with the docker/sdk to use an external database instead of the docker image?

Comments

  • U01LE4BMBK7
    U01LE4BMBK7 Posts: 241 πŸ§‘πŸ»β€πŸš€ - Cadet

    you should be able to configure another database via the
    config_default-X.php

    $config[PropelConstants::ZED_DB_HOST] = 'external_host_name_or_ip';
    
  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    Agree. Just provide your external db credentials via env vars.

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    is this somehow documented? what are the parameter for user?

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    should i create this file?

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    Check config/Shared/config_default.php as an example.

    It has something like

    $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.

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    Check the docs for how to set env vars via deploy file: https://documentation.spryker.com/docs/deploy-file-reference-10

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    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

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    aaaaahhhhh

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    i got it now with the variables πŸ™‚

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    Follow the documentation. Add your env vars to e. g. deploy.dev.yml, then run

    docker/sdk bootstrap deploy.dev.yml
    docker/sdk up
    

    Then, you should be able to use your env var values in config_default.php.

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    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.

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited March 2021

    Yeah I first need to get warmth with this. πŸ™‚

    When i once understand how it works we will move the credentials to local .env

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    I can recommend to use composer package symfony/dotenv.
    Then in e. g. config_default do

    $dotenv = new Dotenv();
    $dotenv->usePutenv();
    $dotenv->load(sprintf('%s/../../.env.local', __DIR__));
    

    Then you can get your env vars via getenv() .

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    where in the deploy.yml need i to put

         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

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    ah merci

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    i did this now and following error happens:
    `

    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
    
  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    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.

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    Sadly not the database service i removed before

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet
  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    @U01LKKBK97T do you have a working deploy.yml which you could anomyze and send us?

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet

    with this external db variables?

  • U01LKKBK97T
    U01LKKBK97T Posts: 287 πŸ§‘πŸ»β€πŸš€ - Cadet

    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.

  • U01LE4BMBK7
    U01LE4BMBK7 Posts: 241 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited March 2021

    what isn't working exactly? you should be able just to edit the config and it should connect

  • U01RA9UPLG1
    U01RA9UPLG1 Posts: 17 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited March 2021

    the bootstrap is not working with following deploy.yml file

    the error message is

  • sprymiker
    sprymiker Cloud Platform Architect Sprykee Posts: 781 πŸ§‘πŸ»β€πŸš€ - Cadet

    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.