Skip to content

Commit

Permalink
view history of previous deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonthomas committed Aug 7, 2012
1 parent 41af16d commit 5541fab
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
27 changes: 24 additions & 3 deletions chief.py
Expand Up @@ -20,6 +20,7 @@ def do_update(app_name, app_settings, webapp_ref, who):
deploy = app_settings['script']
log_dir = os.path.join(settings.OUTPUT_DIR, app_name)
timestamp = int(time.time())
datetime = time.strftime("%b %d %Y %H:%M:%S", time.localtime())
if not os.path.isdir(log_dir):
os.mkdir(log_dir)

Expand All @@ -32,14 +33,14 @@ def pub(event):
d = {'event': event, 'ref': webapp_ref, 'who': who}
redis.publish(app_settings['pubsub_channel'], json.dumps(d))

def history():
def history(status):
redis = redislib.Redis(**settings.REDIS_BACKENDS['master'])
d = {'user': who, 'ref': webapp_ref}
d = {'timestamp':timestamp, 'datetime': datetime,
'status': status, 'user': who, 'ref': webapp_ref}
key = "%s:%s" % (app_name, timestamp)
redis.hmset(key, d)

try:
history()
pub('BEGIN')
yield 'Updating! revision: %s\n' % webapp_ref

Expand All @@ -57,11 +58,22 @@ def history():

run('deploy', output)
pub('DONE')
history('Success')
yield 'All done!'
except:
pub('FAIL')
history('Fail')
raise

def get_history(app_name, app_settings):
redis = redislib.Redis(**settings.REDIS_BACKENDS['master'])
results = []
key_prefix = "%s:*" % app_name
for history in redis.keys(key_prefix):
results.append(redis.hgetall(history))
return sorted(results, key=lambda k: k['timestamp'], reverse=True)


@app.route("/<webapp>", methods=['GET', 'POST'])
def index(webapp):
if webapp not in settings.WEBAPPS.keys():
Expand All @@ -82,3 +94,12 @@ def index(webapp):

return render_template("index.html", app_name=webapp,
form=form, errors=errors)

@app.route("/<webapp>/history", methods=['GET'])
def history(webapp):
if webapp not in settings.WEBAPPS.keys():
abort(404)
else:
app_settings = settings.WEBAPPS[webapp]
results = get_history(webapp, app_settings)
return render_template("history.html", results=results)
58 changes: 58 additions & 0 deletions templates/history.html
@@ -0,0 +1,58 @@
<html>
<head>
<style type="text/css">
#table {
border: 1px solid #DFDFDF;
background-color: #F9F9F9;
width: 100%;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;
font-family: Arial,"Bitstream Vera Sans",Helvetica,Verdana,sans-serif;
color: #333;
}
#table td, #table th {
border-top-color: white;
border-bottom: 1px solid #DFDFDF;
color: #555;
}
#table th {
text-shadow: rgba(255, 255, 255, 0.796875) 0px 1px 0px;
font-family: Georgia,"Times New Roman","Bitstream Charter",Times,serif;
font-weight: normal;
padding: 7px 7px 8px;
text-align: left;
line-height: 1.3em;
font-size: 14px;
}
#table td {
font-size: 12px;
padding: 4px 7px 2px;
vertical-align: top;
}
</style>
</head>
<body>
<table id="table">
<thead>
<tr>
<th>Date</th>
<th>User</th>
<th>Ref</th>
<th>Status</th>
<th>Log</th>
</tr>
</thead>
<tbody>
{% for result in results %}
<tr>
<td>{{ result.datetime }}</td>
<td>{{ result.user }}</td>
<td>{{ result.ref }}</td>
<td>{{ result.status }}</td>
<td><a href="logs/{{ app_name }}/{{ result.ref }}.{{ result.timestamp }}">view</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</html>

0 comments on commit 5541fab

Please sign in to comment.