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

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.

Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

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

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

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

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

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

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

  • Posts: 9 🧑🏻‍🚀 - Cadet

    I am using docker based setup

  • Posts: 9 🧑🏻‍🚀 - Cadet

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

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

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

  • Posts: 90 🧑🏻‍🚀 - Cadet

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

  • Posts: 90 🧑🏻‍🚀 - Cadet

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

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

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

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

    similar to

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

    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')
    
  • Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,115 ⚖️ - Guardians (admin)
    edited August 2022

    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?

  • Posts: 90 🧑🏻‍🚀 - Cadet

    nope. running in local linux based docker installation.

  • Posts: 9 🧑🏻‍🚀 - Cadet

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

  • Posts: 9 🧑🏻‍🚀 - Cadet

    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?

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

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

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

    hmm.. let my try to explain different:

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

    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';
    
  • Posts: 9 🧑🏻‍🚀 - Cadet

    Understood !

  • Posts: 90 🧑🏻‍🚀 - Cadet

    Thanks Florian!

Welcome!

It looks like you're new here. Sign in or register to get started.