Merge branch 'initial_fix' of krzysiej/docker_flask into master

This commit was merged in pull request #2.
This commit is contained in:
2018-03-22 11:10:05 +01:00
committed by krzysiej
5 changed files with 50 additions and 42 deletions

View File

@@ -1,2 +1,8 @@
# docker_flask # docker_flask
## Run
`set FLASK_APP=index.py
set FLASK_DEBUG=1
set
flask run -p 5001`

View File

@@ -5,6 +5,7 @@ import re
import unidecode import unidecode
import datetime import datetime
import base64 import base64
import json
# #
# from flask_wtf import FlaskForm # from flask_wtf import FlaskForm
@@ -184,7 +185,12 @@ def containers_all_action(client_name):
def container_action(client_name, short_id=None): def container_action(client_name, short_id=None):
if client_name in clients: if client_name in clients:
container = clients[client_name].containers.get(short_id) container = clients[client_name].containers.get(short_id)
return render_template('container.html', container=container, client_name=client_name) # parsed = json.loads(container.attrs)
# print()
return render_template('container.html', container=container, client_name=client_name,
container_attributes=json.dumps(container.attrs, indent=4))
else: else:
flash('Client name \'%s\' not found' % client_name) flash('Client name \'%s\' not found' % client_name)
return redirect(url_for('index')) return redirect(url_for('index'))
@@ -380,5 +386,6 @@ def slugify(text):
app.secret_key = b'\xd7:o\\\xaayFe\x1ey\x08m9\xe4\xbc!\xee\x0e>\xd1Z\x99-\xbb' app.secret_key = b'\xd7:o\\\xaayFe\x1ey\x08m9\xe4\xbc!\xee\x0e>\xd1Z\x99-\xbb'
# http://flask.pocoo.org/snippets/133/ @TODO
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0", port=5002, debug=True, threaded=True) app.run(host="0.0.0.0", port=5001, debug=True, threaded=True)

View File

@@ -110,4 +110,18 @@ padding: 5px 15px;
.details__entrypoint { display: inline-block; width: 210px; } .details__entrypoint { display: inline-block; width: 210px; }
.details__image { display: inline-block; } .details__image { display: inline-block; }
.details__more-info {display: none; } .details__more-info { margin: 5px 10px; }
.more-info__ports { }
.more-info__ports--line {
display: list-item;
list-style-position: inside;
margin: 8px 8px;
}
.container_attribute {
}
.container_attribute-details {
white-space: pre;
line-height: 1.1em;
}

View File

@@ -1,7 +1,8 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block body %} {% block body %}
<h1><a href="/">Dashboard</a> &raquo; {{ client_name }} &raquo; <a href="/{{ client_name }}/containers">Containers</a> &raquo; {{ container.name }}</h1> <h1><a href="/">Dashboard</a> &raquo; {{ client_name }} &raquo; <a href="/{{ client_name }}/containers">Containers</a>
&raquo; {{ container.name }}</h1>
<form action="{{ url_for('rename_container', client_name=client_name) }}" method="post"> <form action="{{ url_for('rename_container', client_name=client_name) }}" method="post">
<p><input type="text" name="name" size="60" value="{{ container.name }}"><!-- <p><input type="text" name="name" size="60" value="{{ container.name }}"><!--
@@ -10,8 +11,7 @@
</form> </form>
<h2>Details</h2> <h2>Details</h2>
<pre> <div class="container_attribute">
{{ container.attrs|pprint }} <div class="container_attribute-details">{{ container_attributes }}</div>
</div>
</pre>
{% endblock %} {% endblock %}

View File

@@ -28,26 +28,11 @@
container.attrs.Config.Labels['com.docker.compose.project'] }}</a></h2> container.attrs.Config.Labels['com.docker.compose.project'] }}</a></h2>
{% endif%} {% endif%}
<!--<table>-->
<!--<thead>-->
<!--<tr>-->
<!--<th>COMPOSE PROJECT</th>-->
<!--<th>CONTAINER ID</th>-->
<!--<th>NAME</th>-->
<!--<th>COMMAND</th>-->
<!--<th>CREATED</th>-->
<!--<th>STATUS</th>-->
<!--<th>PORTS</th>-->
<!--<th>IMAGE</th>-->
<!--</tr>-->
<!--</thead>-->
<!--<tbody>-->
<div class="details"> <div class="details">
<div> <div>
<div class="details__status details__status--{{ container.status }}">{{ container.status }}</div> <div class="details__status details__status--{{ container.status }}">{{ container.status }}
<div class="details__name"><a class="button--link" </div><div
class="details__name"><a class="button--link"
href="/{{ client_name }}/containers/id/{{ container.short_id }}">{{ href="/{{ client_name }}/containers/id/{{ container.short_id }}">{{
container.name container.name
}}</a></div> }}</a></div>
@@ -61,17 +46,15 @@
<div class="details__more-info"> <div class="details__more-info">
<div class="more-info__ports"> <div class="more-info__ports">
{% for port in container.attrs['NetworkSettings']['Ports'] %} {% for port in container.attrs['NetworkSettings']['Ports'] %}
{{ port }}
{% if container.attrs['NetworkSettings']['Ports'][port] is not none %} {% if container.attrs['NetworkSettings']['Ports'][port] is not none %}
{% if container.attrs['NetworkSettings']['Ports'][port] is not none and {% if container.attrs['NetworkSettings']['Ports'][port] is not none and
container.attrs['NetworkSettings']['Ports'][port]|length > 0 %} container.attrs['NetworkSettings']['Ports'][port]|length > 0 %}
{% for port_exposed in container.attrs['NetworkSettings']['Ports'][port] %} {% for port_exposed in container.attrs['NetworkSettings']['Ports'][port] %}
->{{ port_exposed['HostIp'] }}:{{ port_exposed['HostPort'] }} <span class="more-info__ports--line">{{ port }} -> {{ port_exposed['HostIp'] }}:{{ port_exposed['HostPort'] }}</span>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
@@ -80,17 +63,15 @@
</div> </div>
<div class="details__controll"> <div class="details__controll">
<a class="button--link" href="/{{ client_name }}/containers/log/{{ container.short_id }}">log</a> <a class="button--link" href="/{{ client_name }}/containers/log/{{ container.short_id }}">log
<a class="button--link" href="/{{ client_name }}/containers/export/{{ container.short_id }}">export</a> </a><a class="button--link" href="/{{ client_name }}/containers/export/{{ container.short_id }}">export
{% if (container.status == 'exited') or (container.status == 'created') %} </a>{% if (container.status == 'exited') or (container.status == 'created') %}<a class="button--link"
<a class="button--link" href="/{{ client_name }}/containers/start/{{ container.short_id }}">start</a> href="/{{ client_name }}/containers/start/{{ container.short_id }}">start
<a class="button--link" href="/{{ client_name }}/containers/remove/{{ container.short_id }}">remove</a> </a><a class="button--link" href="/{{ client_name }}/containers/remove/{{ container.short_id }}">remove</a>
{% endif %} {% endif %}{% if container.status == 'running' %}
<a class="button--link" href="/{{ client_name }}/containers/stop/{{ container.short_id }}">stop
{% if container.status == 'running' %} </a><a class="button--link" href="/{{ client_name }}/containers/restart/{{ container.short_id }}">restart
<a class="button--link" href="/{{ client_name }}/containers/stop/{{ container.short_id }}">stop</a> </a><a class="button--link" href="/{{ client_name }}/containers/top/{{ container.short_id }}">top</a>
<a class="button--link" href="/{{ client_name }}/containers/restart/{{ container.short_id }}">restart</a>
<a class="button--link" href="/{{ client_name }}/containers/top/{{ container.short_id }}">top</a>
{% endif %} {% endif %}
</div> </div>
</div> </div>