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

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
@@ -0,0 +1,23 @@
{% extends "admin/change_list.html" %}
{% load i18n %}
{% block object-tools-items %}
{% if deploy_url %}
{% if has_running %}
<li>
<span style="display:inline-block;padding:8px 12px;color:#999;cursor:not-allowed;">
{% trans '部署进行中…' %}
</span>
</li>
{% else %}
<li>
<a href="{{ deploy_url }}" class="addlink"
style="background-color:#165DFF;color:#fff;"
onclick="return confirm('确认从 Git 拉取最新代码并重启服务吗?\n\n执行步骤:\n1. git pull\n2. pip install\n3. migrate\n4. collectstatic\n5. supervisorctl restart');">
{% trans '一键部署更新' %}
</a>
</li>
{% endif %}
{% endif %}
{{ block.super }}
{% endblock %}
+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 %}
+1 -1
View File
@@ -44,7 +44,7 @@
<div class="col-lg-4 col-md-6">
<div class="card h-100">
{% if product.main_image %}
<img src="{{ product.main_image.url }}" class="card-img-top" alt="{% ml_field product 'name' %}" style="height: 220px; object-fit: cover;">
<img src="{{ product.main_image.url }}" class="card-img-top" alt="{% ml_field product 'name' %}" style="height: 260px; object-fit: contain; background: #f7f8fa; padding: 0.5rem;">
{% endif %}
<div class="card-body">
<h5 class="card-title">{% ml_field product 'name' %}</h5>