Skip to content

configuration via environment variables #2625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Pertel opened this issue Oct 10, 2016 · 8 comments
Closed

configuration via environment variables #2625

Pertel opened this issue Oct 10, 2016 · 8 comments

Comments

@Pertel
Copy link

Pertel commented Oct 10, 2016

Hi
Is there a recommended way to provide configuration via environment variables, instead of hardcoding it in a specific environment..ts file, or rolling my own script to do it?

I'm not well versed in webpack, so perhaps there is a simple way to do it, which is not specific to angular-cli. On the other hand, the webpack configuration is mostly inaccessible, so perhaps that is not viable.

There are quite a few ways to do this of course, so I'm asking if there is a recommended / supported way of doing it, instead of everybody just rolling their own solutions.

Thanks

@filipesilva
Copy link
Contributor

The way we support in the CLI is the environment files as documented in https://github.com/angular/angular-cli#build-targets-and-environment-files. There isn't any other way for now.

@colltoaction
Copy link

Sorry to hijack the thread, but let me ask a related question: what if you want to have secrets that shouldn't be stored along with your code? It's pretty common to have configuration in environmental variables in your server (for example in Azure you set them up through an admin panel).

@Pertel
Copy link
Author

Pertel commented Oct 12, 2016

That's a very relevant question, and it's the same reason I asked the original question. We deploy our apps using Docker, so all configuration is done using env variables. Besides, it's just not a good idea to store config in source control. Maybe it would be a good idea to have a template for the environment file, and have all the actual files in gitignore.

@filipesilva
Copy link
Contributor

My recommendation in that case is to either:

  • drop in one of these env files in a secure build environment, then build and deploy
  • load configuration at runtime using a custom mechanism

@memark
Copy link

memark commented Jan 26, 2017

Another common requirement is the "build once, deploy many" workflow (i.e. not rebuild each time for a new environment. My experience is that most enterprise devops pipelines work like that.) Are there any plans to support this?

The obvious relation to this issue thread is that it's a common mechanism to select your config file by means of an environment variable.

In fact, I opened a SO question about this just yesterday.
https://stackoverflow.com/questions/41848495/build-once-deploy-many-with-angular-cli

@filipesilva
Copy link
Contributor

There's more information on this in #3855. Of special relevance is #3855 (comment), which explains why the CLI isn't opinionated on runtime configs, and there's a simple example in a followup comment.

So that sort of thing is already supported, it just has nothing to do with the build system.

@donburgess
Copy link

Would like to add that if anyone is trying to build secrets into their webapp they're exposing those secrets to anyone who visits their website anyway. It would be better to have your secrets managed by a proxy.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants