-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple-docker-lander.py
101 lines (90 loc) · 3.02 KB
/
simple-docker-lander.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
from bottle import route, run, template
import os
import yaml
DEFAULT_CONFIG = {
'site-name': 'simple-docker-lander',
'link-mode': 'default',
'links': [
{'name': 'Service 1', 'href': 'https://www.google.com/'},
{'name': 'Service 2', 'href': 'https://www.reddit.com/'},
{'name': 'Twitter', 'href': 'https://www.twitter.com/', 'group': 'Social Networks'},
{'name': 'Facebook', 'href': 'https://www.facebook.com/', 'group': 'Social Networks'}
]
}
if __name__ == '__main__':
config_env_var = yaml.safe_load(os.environ.get('CONFIG', '')) or {}
# Merge the default config with the env config
config = DEFAULT_CONFIG.copy()
config.update(config_env_var)
groups = [
{'name': 'default', 'links': []}
]
groups_index_map = {'default': 0}
for link in config['links']:
if 'group' in link:
if link['group'] in groups_index_map:
groups[groups_index_map[link['group']]]['links'].append(link)
else:
groups_index_map[link['group']] = len(groups)
groups.append({
'name': link['group'],
'links': [link]
})
else:
groups[0]['links'].append(link)
@route('/')
def index():
return template('''<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>{{ config['site-name'] }}</title>
<style>
ul {
list-style-type: none;
margin: 0;
}
body > ul {
padding: 0;
}
.group-name {
font-weight: bold;
}
</style>
</head>
<body>
% if len(groups[0]['links']) > 0:
<ul>
% for link in groups[0]['links']:
<li><a href="{{ link['href'] }}"{{!' target="_blank"' if config['link-mode'] == 'tab' else ""}}>{{ link['name'] }}</a></li>
% end
</ul>
<br />
% end
% for group in groups[1:]:
<div class="group">
<span class="group-name">{{ group['name'] }}</span>
<ul>
% for link in group['links']:
<li><a href="{{ link['href'] }}"{{!' target="_blank"' if config['link-mode'] == 'tab' else ""}}>{{ link['name'] }}</a></li>
% end
</ul>
</div>
<br />
% end
</body>
</html>''', config=config, groups=groups)
kwargs = {
'server': 'gunicorn',
'host': '0.0.0.0',
'port': '80',
'workers': 10,
}
if 'SSL_KEYFILE' in os.environ:
kwargs['keyfile'] = os.environ['SSL_KEYFILE']
if 'SSL_CERTFILE' in os.environ:
kwargs['certfile'] = os.environ['SSL_CERTFILE']
if 'WORKERS' in os.environ:
kwargs['workers'] = int(os.environ['WORKERS'])
run(**kwargs)