feat: 删除.drone.yml && 采用build.sh手动构建镜像
This commit is contained in:
81
app.py
81
app.py
@@ -1,30 +1,40 @@
|
||||
from flask import Flask, jsonify
|
||||
import socket
|
||||
import os
|
||||
from datetime import datetime
|
||||
import random
|
||||
import socket
|
||||
from datetime import datetime
|
||||
|
||||
from flask import Flask, jsonify
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# 从环境变量读取版本号
|
||||
VERSION = os.getenv('APP_VERSION', 'v1.0')
|
||||
BUGGY = os.getenv('BUGGY', 'false').lower() == 'true'
|
||||
VERSION = os.getenv("APP_VERSION", "v1.0")
|
||||
BUGGY = os.getenv("BUGGY", "false").lower() == "true"
|
||||
|
||||
# 版本主题配置
|
||||
THEMES = {
|
||||
'v1.0': {'color': '#4A90E2', 'name': '蓝色经典版', 'features': '基础功能'},
|
||||
'v2.0': {'color': '#50C878', 'name': '绿色升级版', 'features': '新增健康检查、API接口'},
|
||||
'v2.1': {'color': '#50C878', 'name': '绿色稳定版', 'features': '性能优化、Bug修复'},
|
||||
'v3.0-buggy': {'color': '#E74C3C', 'name': '红色测试版', 'features': '⚠️ 此版本存在已知问题'}
|
||||
"v1.0": {"color": "#4A90E2", "name": "蓝色经典版", "features": "基础功能"},
|
||||
"v2.0": {
|
||||
"color": "#50C878",
|
||||
"name": "绿色升级版",
|
||||
"features": "新增健康检查、API接口",
|
||||
},
|
||||
"v2.1": {"color": "#50C878", "name": "绿色稳定版", "features": "性能优化、Bug修复"},
|
||||
"v3.0-buggy": {
|
||||
"color": "#E74C3C",
|
||||
"name": "红色测试版",
|
||||
"features": "⚠️ 此版本存在已知问题",
|
||||
},
|
||||
}
|
||||
|
||||
@app.route('/')
|
||||
|
||||
@app.route("/")
|
||||
def hello():
|
||||
# 模拟 v3.0-buggy 的问题
|
||||
if BUGGY and random.random() < 0.5:
|
||||
return "💥 服务异常:数据库连接失败", 500
|
||||
|
||||
theme = THEMES.get(VERSION, THEMES['v1.0'])
|
||||
theme = THEMES.get(VERSION, THEMES["v1.0"])
|
||||
|
||||
return f"""
|
||||
<!DOCTYPE html>
|
||||
@@ -39,10 +49,10 @@ def hello():
|
||||
max-width: 700px;
|
||||
margin: 50px auto;
|
||||
padding: 30px;
|
||||
background: linear-gradient(135deg, {theme['color']}22 0%, {theme['color']}44 100%);
|
||||
background: linear-gradient(135deg, {theme["color"]}22 0%, {theme["color"]}44 100%);
|
||||
}}
|
||||
.header {{
|
||||
background: {theme['color']};
|
||||
background: {theme["color"]};
|
||||
color: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px 10px 0 0;
|
||||
@@ -55,13 +65,13 @@ def hello():
|
||||
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||
}}
|
||||
.highlight {{
|
||||
color: {theme['color']};
|
||||
color: {theme["color"]};
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
}}
|
||||
.version-badge {{
|
||||
display: inline-block;
|
||||
background: {theme['color']};
|
||||
background: {theme["color"]};
|
||||
color: white;
|
||||
padding: 5px 15px;
|
||||
border-radius: 20px;
|
||||
@@ -91,7 +101,7 @@ def hello():
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1>🚀 {theme['name']}</h1>
|
||||
<h1>🚀 {theme["name"]}</h1>
|
||||
<div class="version-badge">版本 {VERSION}</div>
|
||||
</div>
|
||||
<div class="info">
|
||||
@@ -102,15 +112,15 @@ def hello():
|
||||
</tr>
|
||||
<tr>
|
||||
<td>🎓 学号服务</td>
|
||||
<td class="highlight">s{os.getenv('STUDENT_ID', '00')}</td>
|
||||
<td class="highlight">s{os.getenv("STUDENT_ID", "00")}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>⏰ 当前时间</td>
|
||||
<td class="highlight">{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</td>
|
||||
<td class="highlight">{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>✨ 版本特性</td>
|
||||
<td class="highlight">{theme['features']}</td>
|
||||
<td class="highlight">{theme["features"]}</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="auto-refresh">🔄 页面每3秒自动刷新,观察容器变化</div>
|
||||
@@ -119,21 +129,26 @@ def hello():
|
||||
</html>
|
||||
"""
|
||||
|
||||
@app.route('/api/version')
|
||||
|
||||
@app.route("/api/version")
|
||||
def version():
|
||||
return jsonify({
|
||||
'version': VERSION,
|
||||
'hostname': socket.gethostname(),
|
||||
'student_id': os.getenv('STUDENT_ID', '00'),
|
||||
'timestamp': datetime.now().isoformat(),
|
||||
'buggy': BUGGY
|
||||
})
|
||||
return jsonify(
|
||||
{
|
||||
"version": VERSION,
|
||||
"hostname": socket.gethostname(),
|
||||
"student_id": os.getenv("STUDENT_ID", "00"),
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
"buggy": BUGGY,
|
||||
}
|
||||
)
|
||||
|
||||
@app.route('/health')
|
||||
|
||||
@app.route("/health")
|
||||
def health():
|
||||
if BUGGY and random.random() < 0.3:
|
||||
return {'status': 'unhealthy'}, 503
|
||||
return {'status': 'healthy', 'version': VERSION}, 200
|
||||
if BUGGY and random.random() < 0.7:
|
||||
return {"status": "unhealthy"}, 503
|
||||
return {"status": "healthy", "version": VERSION}, 200
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=80)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=80)
|
||||
|
||||
Reference in New Issue
Block a user