-
Notifications
You must be signed in to change notification settings - Fork 18
/
config.py
65 lines (55 loc) · 2.68 KB
/
config.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
import os
import logging
from urlparse import urlparse
class Config(dict):
"""
Global config. CEXEC does not boot up unless all variables defined here are
initialized
"""
def __init__(self):
self['HOME'] = os.getenv('HOME', '/root')
self['USER_BUFFER_TIMEOUT'] = 2
self['MAX_USER_LOG_SIZE'] = 12 * 1024 * 1024
self['CONSOLE_BUFFER_LENGTH'] = 20
self['CONSOLE_FLUSH_INTERVAL'] = 3
self['RUN_MODE'] = os.getenv('RUN_MODE', 'PROD')
if 'prod' in self['RUN_MODE'].lower():
self['LOG_LEVEL'] = 'INFO'
elif 'beta' in self['RUN_MODE'].lower():
self['LOG_LEVEL'] = 'INFO'
else:
self['LOG_LEVEL'] = 'DEBUG'
self['SHIPPABLE_API_URL'] = os.getenv('SHIPPABLE_API_URL', '')
self['SHIPPABLE_VORTEX_URL'] = "{0}/vortex".format(self['SHIPPABLE_API_URL'])
self['SHIPPABLE_API_RETRY_INTERVAL'] = os.getenv('SHIPPABLE_API_RETRY_INTERVAL', '')
self['SYSTEM_LOGGING_ENABLED'] = False
self['USER_SYSTEM_LOGGING_ENABLED'] = True
self['MESSAGE_DIR'] = os.getenv('MESSAGE_DIR', '/tmp/cexec')
self['MESSAGE_JSON_NAME'] = os.getenv('MESSAGE_JSON_NAME', 'message.json')
self['WHO'] = os.getenv('WHO', 'cexec')
self['SSH_DIR'] = os.getenv('SSH_DIR', '/tmp/ssh')
self['ARTIFACTS_DIR'] = os.getenv('ARTIFACTS_DIR', '/shippableci')
self['MAX_CONSOLES_SIZE_MB'] = os.getenv('MAX_CONSOLES_SIZE_MB', 16)
self['MAX_CONSOLES_SIZE_BYTES'] = self['MAX_CONSOLES_SIZE_MB'] * 1024 * 1024
# New build runner switch/params
self['IS_NEW_BUILD_RUNNER_SUBSCRIPTION'] = \
os.getenv('IS_NEW_BUILD_RUNNER_SUBSCRIPTION') == 'true'
self['MAX_LOG_LINES_TO_FLUSH'] = \
int(os.getenv('MAX_LOG_LINES_TO_FLUSH', 20))
self['MAX_LOGS_FLUSH_WAIT_TIME_IN_S'] = \
float(os.getenv('MAX_LOGS_FLUSH_WAIT_TIME_IN_S', 3))
self['LOGS_FILE_READ_WAIT_TIME_IN_S'] = \
float(os.getenv('LOGS_FILE_READ_WAIT_TIME_IN_S', 0.1))
for k, v in self.iteritems():
if v == '':
print('{0} has no value. Make sure the container environment has a '
'variable {0} with a valid value'.format(k))
raise Exception('{0} has no value. Make sure the container environment has a '
'variable {0} with a valid value'.format(k))
# Convert SHIPPABLE_API_RETRY_INTERVAL to an int
self['SHIPPABLE_API_RETRY_INTERVAL'] = int(
self['SHIPPABLE_API_RETRY_INTERVAL'])
def __str__(self):
for k, v in self.iteritems():
print('{0} - {1}'.format(k, v))
return ''