-
Notifications
You must be signed in to change notification settings - Fork 8
/
initialize_dotenvs.py
executable file
·115 lines (106 loc) · 4.01 KB
/
initialize_dotenvs.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python
# This will create your initial .env files
# These are not to be checked in to git, as you may populate them
# with confidential information
# Standard Library
import os
import random
import string
def random_string(n):
return "".join(
random.choice(string.ascii_letters + string.digits) for _ in range(n)
)
CONFIG = [
{
"name": ".django",
"sections": [
{
"name": "General",
"envvars": [
("USE_DOCKER", "yes"),
("DJANGO_SECRET_KEY", lambda: random_string(20)),
("IPYTHONDIR", "/app/.ipython"),
("DOCUMENTCLOUD_URL", "https://dev.documentcloud.org"),
("SQUARELET_WHITELIST_VERIFIED_JOURNALISTS", "False"),
("REQUESTS_CA_BUNDLE", "/etc/ssl/certs/ca-certificates.crt"),
("OEMBED_URL_REGEX", "(dev[.])?"),
],
},
{
"name": "Redis",
"envvars": [
("REDIS_URL", "redis://documentcloud_redis:6379/0"),
(
"REDIS_PROCESSING_URL",
"redis://documentcloud_processing_redis:6379/0",
),
("REDIS_PROCESSING_PASSWORD", ""),
],
},
{
"name": "Squarelet",
"envvars": [("SQUARELET_KEY", ""), ("SQUARELET_SECRET", "")],
},
{"name": "JWT", "envvars": [("JWT_VERIFYING_KEY", "")]},
{
"name": "Processing Environment",
"envvars": [
("ENVIRONMENT", "local-minio"),
("SERVERLESS", "False"),
("DOC_PROCESSING_URL", "mock://process.dev.documentcloud.org"),
(
"SIDEKICK_PROCESSING_URL",
"mock://sidekick.dev.documentcloud.org",
),
("PROGRESS_URL", "mock://progress.dev.documentcloud.org"),
("IMPORT_URL", "mock://import.dev.documentcloud.org"),
("API_CALLBACK", "https://api.dev.documentcloud.org/api/"),
("PROCESSING_TOKEN", lambda: random_string(64)),
("DOCUMENT_BUCKET", "documents"),
("SERVERLESS", "False"),
("USE_TIMEOUT", "False"),
("TIMEOUTS", "15,30,60,120"),
],
},
{
"name": "MinIO",
"envvars": [
("MINIO_ACCESS_KEY", lambda: random_string(64)),
("MINIO_SECRET_KEY", lambda: random_string(64)),
("MINIO_URL", "http://minio.documentcloud.org:9000"),
],
},
],
},
{
"name": ".postgres",
"sections": [
{
"name": "PostgreSQL",
"envvars": [
("POSTGRES_HOST", "documentcloud_postgres"),
("POSTGRES_PORT", "5432"),
("POSTGRES_DB", "documentcloud"),
("POSTGRES_USER", lambda: random_string(30)),
("POSTGRES_PASSWORD", lambda: random_string(60)),
],
}
],
},
]
def main():
os.makedirs(".envs/.local/", 0o775)
for file_config in CONFIG:
with open(".envs/.local/{}".format(file_config["name"]), "w") as file_:
for section in file_config["sections"]:
for key in ["name", "url", "description"]:
if key in section:
file_.write("# {}\n".format(section[key]))
file_.write("# {}\n".format("-" * 78))
for var, value in section["envvars"]:
file_.write(
"{}={}\n".format(var, value() if callable(value) else value)
)
file_.write("\n")
if __name__ == "__main__":
main()