Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

updateLocalEnv.ts 1.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  1. import fs from "fs";
  2. import yaml from "js-yaml";
  3. const file = fs.readFileSync("chart/env/prod.yaml", "utf8");
  4. // have to do a weird stringify/parse because of some node error
  5. const prod = JSON.parse(JSON.stringify(yaml.load(file)));
  6. const vars = prod.envVars as Record<string, string>;
  7. const secrets = prod.externalSecrets.parameters;
  8. let PUBLIC_CONFIG = "";
  9. Object.entries(vars).forEach(([key, value]) => {
  10. PUBLIC_CONFIG += `${key}=\`${value}\`\n`;
  11. });
  12. let SECRET_CONFIG =
  13. (fs.existsSync(".env.SECRET_CONFIG")
  14. ? fs.readFileSync(".env.SECRET_CONFIG", "utf8")
  15. : process.env.SECRET_CONFIG) ?? "";
  16. if (!SECRET_CONFIG) {
  17. console.log(
  18. "SECRET_CONFIG is not defined. We will now try to fill in secrets found in the prod environemnt with environment variables."
  19. );
  20. Object.keys(secrets).forEach((key) => {
  21. const value = process.env[key];
  22. if (!value) {
  23. throw new Error(
  24. `Secret ${key} was found in prod.yaml but was not available as an environment variable.`
  25. );
  26. }
  27. SECRET_CONFIG += `${key}=${value}\n`;
  28. });
  29. }
  30. // Prepend the content of the env variable SECRET_CONFIG
  31. const full_config = `${PUBLIC_CONFIG}\n${SECRET_CONFIG}`;
  32. // Write full_config to .env.local
  33. fs.writeFileSync(".env.local", full_config);
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...