question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce environment specific configurations for Spartacus deployment on ccv2

See original GitHub issue

For angular developers it’s very common to use the environments file to distinguish different settings for different builds. This is often used for setting up different tokens for different environment. For example to target a different payment system, analytic system, tag manager, etc.

The build on Commerce Cloud is currently always using the production build. With this setup, the environment specific settings are not aligned with the build, as production build is always using the production environment settings.

Different options:

  1. We align the angular build with the build to ccv2 environments. This would result in specific builds for specific environments. This will make the builds no longer reusable cross environments.
  2. load environment settings from a file while bootstrapping the app. This would not be recommended for production builds as we introduce a blocking call before we can bootstrap the app (using config initializers)
  3. bake environment specific variables into UI, similarly to what we’ve done with the occ-backend-base-url. We would use backend properties, which gives the advantage of runtime configuration over build time configuration.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:14
  • Comments:44 (11 by maintainers)

github_iconTop GitHub Comments

7reactions
balajimohanncommented, Jun 20, 2021

Hi Team

Any information on when this may be prioritised? It would be great to just use the single build to deploy to multiple environments. Currently

Thanks, Bala

3reactions
mperncommented, May 22, 2021

Actually, strike that, the compiled down version would look very different potentially. Would need a different compiled version for each environment to make this robust unfortunately.

@simonkeytree - That’s where we disagree and that’s exactly what the immutable webapp approach warns against (Quote: “immutable static assets”, and the production bundle is one of those assets). The same compiled version is deployed everywhere, index.html acts as deployment descriptor and “runtime configuration”, in a way. (that’s not that different than using multiple environment.ts)

We only(?) need:

  • first-class, framework-level support for the env object by Spartacus
    • generate placeholder <script> block with pre-defined id and empty env object in schemas
    • ~Angular service to read values from env~ EDIT: environment should read unknown object properties from window.env (or some other fallback mechanism; not sure about SSR though)
    • If you break the env object (or <script>) block by accident, the build fails
  • CCv2 automation supports env (entrypoint script):
    • detect and activate correct index-<environment>.html with fallback to index.html (great idea!)
    • read/parse env object from correct index.html, merge object with Service Properties from the CCv2 Cloud Portal and write merged object back to index.html
    • highly visible logging of what happend:
      • which index.html was used
      • warning if env script block/placeholder could not be found in index.html
      • before and after values of env if it was merged with Service Properties, or info message that no Service Properties required merging
      • the effective/final env

Voila! You have per-environment configuration without an additional request to load the config and you can cache every version of your storefront forever (minus index.html, of course.)

TBH, I would settle for index.<environment>.html support and Service Property injection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deploy spartacus on Cloud - SAP Community
It's using the prod env file by default. For more details please see Introduce environment specific configurations for Spartacus deployment on ...
Read more >
Spartacus: a different configuration per environment on SAP ...
Since Spartacus is based on Angular, we tried the official approach mentioned by SAP that involves creating a different configuration file per ...
Read more >
Contributor Setup - Spartacus Documentation - SAP
Configure your back end URL in the projects/storefrontapp/src/environments/environment.ts file. The environment. · There are separate configuration files for B2C ...
Read more >
Spartacus CCv2 Build process for multiple enviroments
This is however the only configuration that is environment specific, the ticket referenced by Grin is indeed a feature that we like to...
Read more >
Webinar: Spartacus and SAP Commerce Cloud - YouTube
Here is your introduction to SAP's digital commerce platforms with a focus on the features and functions for Business to Consumer (B2C) and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found