Calling Developers!
We are reenergizing our code contribution process! Learn More

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 Everyone, I am trying to access custom development config from file src/config/Shared/config_d

Options
U03RJQT5AN4
U03RJQT5AN4 Posts: 9 🧑🏻‍🚀 - Cadet

Hello Everyone, I am trying to access custom development config from file src/config/Shared/config_default-development.php but not able to access it through Config::get(). I have tried after bootstraping with deploy.dev.yml and cleared cache as well but nothing works.

Comments

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,034 ⚖️ - Guardians (admin)
    Options

    hi, this config is not loaded if you do not use vagrant setup (or if you touched sth else)

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,034 ⚖️ - Guardians (admin)
    Options

    Please have a look in vendor/spryker/config/src/Spryker/Shared/Config/Config.php which config gets loaded when

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,034 ⚖️ - Guardians (admin)
    edited August 2022
    Options

    environment should be defined by “environment: docker.dev” in the deploy.dev.yml

  • U03RJQT5AN4
    U03RJQT5AN4 Posts: 9 🧑🏻‍🚀 - Cadet
    Options

    I am using docker based setup

  • U03RJQT5AN4
    U03RJQT5AN4 Posts: 9 🧑🏻‍🚀 - Cadet
    Options

    Which means config_default-docker.dev.php is the one loaded when using docker based setup instead of config_default-development.php ?

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,034 ⚖️ - Guardians (admin)
    Options

    yes. if it exists. By default you should put everything in config_default.php

  • U035GSLDLVD
    U035GSLDLVD Posts: 90 🧑🏻‍🚀 - Cadet
    Options

    if we have environment specific credentials like different keys for production and development environment, where should we put that?

  • U035GSLDLVD
    U035GSLDLVD Posts: 90 🧑🏻‍🚀 - Cadet
    Options

    because config_default.php is the default file which will be initialised for all the environments.

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,034 ⚖️ - Guardians (admin)
    Options

    credentials etc should normally be set via env-variables. Overall a best-practise is to set env-specific config values via environment variables

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,034 ⚖️ - Guardians (admin)
    Options

    similar to

    $config[MailConstants::SMTP_HOST] = getenv('SPRYKER_SMTP_HOST') ?: null;
    
  • U035GSLDLVD
    U035GSLDLVD Posts: 90 🧑🏻‍🚀 - Cadet
    Options

    Thanks Florian! does it mean we need to have different env-variables for each environment? like

    getenv('spryker_dev_SMTP') for dev and for prod getenv('spryker_prod_SMTP')
    
  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,034 ⚖️ - Guardians (admin)
    edited August 2022
    Options

    no, same env-variable. the values would be set different by the deploy-script (the one which setup the services in the cloud etc). Are you in the spryker cloud?

  • U035GSLDLVD
    U035GSLDLVD Posts: 90 🧑🏻‍🚀 - Cadet
    Options

    nope. running in local linux based docker installation.

  • U03RJQT5AN4
    U03RJQT5AN4 Posts: 9 🧑🏻‍🚀 - Cadet
    Options

    @florian.scholz deploy-script means jenkins script used in the cloud?

  • U03RJQT5AN4
    U03RJQT5AN4 Posts: 9 🧑🏻‍🚀 - Cadet
    Options

    currently, we are trying to do that in local ubuntu installation with docker. getenv() will pick those variables from? deply.dev.yml? or .env file inside spryker installation dir?

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,034 ⚖️ - Guardians (admin)
    Options

    yes, for local environment i guess - but you wrote about

    if we have environment specific credentials like different keys for production and development environment
    
  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,034 ⚖️ - Guardians (admin)
    Options

    hmm.. let my try to explain different:

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,034 ⚖️ - Guardians (admin)
    edited August 2022
    Options

    first rule: you should not store any credentials in code!

    imagine you have two new settings:
    my-third-party-service-user and my-third-party-password

    you would set sth like in config_default.php

    $config[MyConstants::MY_THIRD_PARTY_SERVICE_USER] = getenv('SPRYKER_MY_THIRD_PARTY_SERVICE_USER') ?: null;
    $config[MyConstants::MY_THIRD_PARTY_SERVICE_PASSWORD] = getenv('SPRYKER_MY_THIRD_PARTY_SERVICE_PASSWORD') ?: null;
    

    When you deploy to staging or production you can align with the dev-ops team to set the env-variables to the dedicated values while deploying the services.

    This is the way to go for deployment but does not help you yet for you local environment.

    For local development you have two possibilities:

    A (clean way):
    create config_local.php (IN ADDITION TO THE PREVIOUS CODE!) and put

    $config[MyConstants::MY_THIRD_PARTY_SERVICE_USER] = 'my-user';
    $config[MyConstants::MY_THIRD_PARTY_SERVICE_PASSWORD] = 'my-password';
    

    B (will be committed, so not good for credentials):
    set the default to your credentials rather then null in the config_default.php

    $config[MyConstants::MY_THIRD_PARTY_SERVICE_USER] = getenv('SPRYKER_MY_THIRD_PARTY_SERVICE_USER') ?: 'my-user';
    $config[MyConstants::MY_THIRD_PARTY_SERVICE_PASSWORD] = getenv('SPRYKER_MY_THIRD_PARTY_SERVICE_PASSWORD') ?: 'my-password';
    
  • U03RJQT5AN4
    U03RJQT5AN4 Posts: 9 🧑🏻‍🚀 - Cadet
    Options

    Understood !

  • U035GSLDLVD
    U035GSLDLVD Posts: 90 🧑🏻‍🚀 - Cadet
    Options

    Thanks Florian!