后台增加自动部署更新功能

This commit is contained in:
2026-08-10 21:41:36 +08:00
parent 2022664e7e
commit df35018805
9 changed files with 513 additions and 5 deletions
+110
View File
@@ -0,0 +1,110 @@
{% extends "admin/base_site.html" %}
{% load i18n %}
{% block extrastyle %}
{{ block.super }}
<style>
.deploy-header {
display: flex;
align-items: center;
gap: 16px;
margin-bottom: 16px;
flex-wrap: wrap;
}
.deploy-status {
display: inline-block;
padding: 4px 12px;
border-radius: 4px;
font-weight: 600;
font-size: 0.9rem;
}
.deploy-status.running { background: #fff7e6; color: #d46b08; }
.deploy-status.success { background: #f6ffed; color: #389e0d; }
.deploy-status.failed { background: #fff1f0; color: #cf1322; }
.deploy-meta {
color: #666;
font-size: 0.9rem;
margin-bottom: 12px;
}
.deploy-output {
background: #1e1e1e;
color: #d4d4d4;
font-family: "Consolas", "Monaco", "Courier New", monospace;
font-size: 0.85rem;
line-height: 1.5;
padding: 16px;
border-radius: 6px;
white-space: pre-wrap;
word-break: break-all;
max-height: 600px;
overflow-y: auto;
border: 1px solid #333;
}
.deploy-actions { margin-top: 16px; }
.deploy-actions a {
display: inline-block;
padding: 8px 16px;
background: #165DFF;
color: #fff;
border-radius: 4px;
text-decoration: none;
margin-right: 8px;
font-size: 0.9rem;
}
.deploy-actions a:hover { background: #0E42D2; }
.spinner {
display: inline-block;
width: 14px;
height: 14px;
border: 2px solid #d46b08;
border-top-color: transparent;
border-radius: 50%;
animation: spin 0.8s linear infinite;
vertical-align: middle;
margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
</style>
{% endblock %}
{% block content %}
<div class="deploy-header">
<h1 style="margin:0;">{{ title }}</h1>
{% if log.status == 'running' %}
<span class="deploy-status running">
<span class="spinner"></span>{% trans '执行中' %}
</span>
{% elif log.status == 'success' %}
<span class="deploy-status success">{% trans '成功' %}</span>
{% elif log.status == 'failed' %}
<span class="deploy-status failed">{% trans '失败' %}</span>
{% endif %}
</div>
<div class="deploy-meta">
{% if log.triggered_by %}{% trans '触发者' %}: {{ log.triggered_by.username }} · {% endif %}
{% trans '开始' %}: {{ log.started_at|date:"Y-m-d H:i:s" }}
{% if log.finished_at %} · {% trans '结束' %}: {{ log.finished_at|date:"Y-m-d H:i:s" }} · {% trans '耗时' %}: {{ log.duration }}{% endif %}
</div>
<div class="deploy-output" id="deploy-output">{{ log.output|default:'(暂无输出)' }}</div>
<div class="deploy-actions">
{% if is_running %}
<a href="" onclick="location.reload();return false;">{% trans '刷新查看进度' %}</a>
{% else %}
<a href="{% url 'admin:core_deploylog_changelist' %}">{% trans '返回列表' %}</a>
<a href="{% url 'admin:core_deploy_trigger' %}"
onclick="return confirm('确认从 Git 拉取最新代码并重启服务吗?');">
{% trans '再次部署' %}
</a>
{% endif %}
</div>
{% if is_running %}
<script>
// 自动刷新:每 3 秒拉取最新日志
setTimeout(function() { location.reload(); }, 3000);
</script>
{% endif %}
{% endblock %}