cancel
Showing results for 
Search instead for 
Did you mean: 

CDS Profiles not set correctly

arminhatting
Participant

Hello experts,

I am trying to set a specific profile for my CAP project.

If I follow this description (https://cap.cloud.sap/docs/node.js/cds-env#profiles), I would expect to be able to set a profile using the NODE_ENV environment variable as long as I don't use any flags.

For example, if I set NODE_ENV = 'test', I would expect the profile to be set to 'test' only.

However, if I execute the following


$env:NODE_ENV='test'
cds env

The following profiles are set:

Why is the profile 'development' still active?

How can I remove this profile?

Note: When I set NODE_ENV = 'production', the development profile disappears from the profiles variable:

Thanks for your help

david_kunz2
Advisor
Advisor
0 Kudos

Hi armin.hatting ,

Thanks for this report. On macOS, it works for me:

echo $NODE_ENV
production
echo $CDS_ENV
<undefined>
cds env get profiles
[ 'production' ]


I will ask a colleague to verify that on a Windows machine.
Best regards,
David

arminhatting
Participant
0 Kudos

Hello david.kunz2,

as I mentioned in the question, it also works for me for the production profile.

Try another profile like test.

Same behaviour on linux:

echo $NODE_ENV
test
echo $CDS_ENV
<undefined>
cds env get profiles
[ 'test', 'development' ]

Best regards,

Armin

david_kunz2
Advisor
Advisor
0 Kudos

Hi Armin,

Okay, I can reproduce that. I will ask a colleague if this is the desired behaviour. Keep in mind, that some test runners set the env variable themselves, so maybe ['test', 'development'] is needed to ensure that also in automatic tests, the 'development' profile is loaded. If so, it should be documented.
Best regards,
David

Accepted Solutions (1)

Accepted Solutions (1)

david_kunz2
Advisor
Advisor
0 Kudos

Hi armin.hatting ,

I looked at the code so it seems to be the following (which makes sense): If NODE_ENV/CDS_ENV is not `production`, then we add `development` to the profiles, or in words:

"When you're not in production, you're developing".

I will update the documentation accordingly.

If you want to have a profile which is only enabled if you explicitly set it, you must not use `development`.

Best regards,
David

arminhatting
Participant
0 Kudos

Hi david.kunz2,

thanks for your explanation.

However, the logic you describe does not seem to apply to the environment variable CDS_ENV:

echo $CDS_ENV
production
echo $NODE_ENV
<undefined>
cds env get profiles
[ 'production', 'development' ] 

What would be the best practice for using different profiles in a BTP landscape with three environments?

  • For production environment I would use the 'production' profile and set it via NODE_ENV
  • For the test environment, I would set NODE_ENV='test' and ensure that the development profile is not used.
  • For the development environment, I can't use the development profile (because it would interfere in the test environment). So I define a new environment, e.g. NODE_ENV='dev'?

Does the active development profile have any other effects on the CDS framework?

Best regards,

Armin

david_kunz2
Advisor
Advisor
0 Kudos

Hi armin.hatting ,

> For production environment I would use the 'production' profile and set it via NODE_ENV

Yes, that's what production environments usually do (e.g. Cloud Foundry does it). That's why the special case `NODE_ENV != production && CDS_ENV == production` doesn't exist in practise, but I can fix that.

> For the test environment, I would set NODE_ENV='test' and ensure that the development profile is not used.

Usually, test runners set that automatically (e.g. Jest).> For the development environment, I can't use the development profile (because it would interfere in the test environment). So I define a new environment, e.g. NODE_ENV='dev'?

If you want an environment which is _only_ used if specifically set up, then you can use `dev`.

Best regards,
David
tobias_steckenborn
Active Participant
0 Kudos

david.kunz2, has this been incorporated into the documentation yet?

I am currently struggling with the case where I want to set a credentials.url in the case of development but a credentials.destination in the case of hybrid or production. Unfortunately, when hybrid is loaded, both the URL and the destination are loaded, resulting in an error.

Do you have any recommendations on how to avoid this?

david_kunz2
Advisor
Advisor
0 Kudos

Hi tobias_steckenborn ,

Yes, I changed the documentation to

> If the profile is not set to production, the development profile is automatically enabled.

I see, I guess in this case you'd need to use a 'custom' development profile (e.g. `dev`) because `development` would be active.

Maybe we can tweak the mechanism a bit and not merge configurations of two (active) profiles but only use the one which is explicitly enabled, in your case `hybrid`.

I will discuss this with the team.

Best regards,
David

david_kunz2
Advisor
Advisor
0 Kudos

Hi tobias_steckenborn ,

- Looking at our code, the remote service should only fallback to credentials.url if credentials.destination is not set. Maybe this was different in your version.

- If this doesn't work, you can also set credentials.url: false in your hybrid profile.

Best regards,
David

Answers (0)