This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
86 lines (60 loc) · 2.15 KB
/
app.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
from flask import Flask, Response, render_template, redirect, url_for, flash
from docker import Client
from docker.utils import kwargs_from_env
import config
from util import pretty_json
from manifold import Manifold
app = Flask(__name__)
app.config.from_object(config.FlaskConfig)
doc = Client(**kwargs_from_env())
host_config = doc.create_host_config(
publish_all_ports=True,
)
manifold = Manifold(app, doc)
manifold.nginx_write_and_reload()
@app.route('/all')
def all_containers():
minions = manifold.minions(trunc=True, all=True)
return render_template('containers.html', minions=minions)
@app.route('/')
def containers():
minions = manifold.minions(trunc=True)
return render_template('containers.html', minions=minions)
@app.route('/container/<cont_id>/start')
def start(cont_id):
doc.start(container=cont_id)
manifold.nginx_write_and_reload()
return redirect(url_for('containers'))
@app.route('/container/<cont_id>/pause')
def pause(cont_id):
doc.pause(container=cont_id)
return redirect(url_for('containers'))
@app.route('/container/<cont_id>/unpause')
def unpause(cont_id):
doc.unpause(container=cont_id)
return redirect(url_for('containers'))
@app.route('/container/<cont_id>/login')
def login(cont_id):
minion = manifold.minion_by_id(cont_id)
return redirect(minion.build_url())
@app.route('/container/<cont_id>/logs')
def logs(cont_id):
return manifold.dock.logs(cont_id).decode('utf8').replace('\n', '<br/>')
@app.route('/pull')
def pull():
image = manifold.config.DOCKER_IMAGE
def gen():
yield b'Pulling image. Please wait! (streaming)<br/>'
for line in doc.pull(image, stream=True):
yield '{}<br/>'.format(pretty_json(line.decode('utf8')))
return Response(gen())
@app.route('/new')
def new():
# TODO: de-hardcode the tag
image = manifold.config.image_with_tag('latest')
manifold.dock.create_container(image=image, host_config=host_config)
flash('New container created for image {}'.format(image))
return redirect(url_for('containers'))
if __name__ == '__main__':
# not accessible through docker if only local
app.run(host='0.0.0.0')