Skip to content

Commit b17033f

Browse files
committed
适配移动端网页,增加版本号显示
1 parent 1c0b9bb commit b17033f

6 files changed

Lines changed: 558 additions & 49 deletions

File tree

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ RUN chmod +x /usr/local/bin/entrypoint.sh
4747
# 暴露端口5000
4848
EXPOSE 5000
4949

50+
# 接收构建参数
51+
ARG APP_NAME
52+
ARG APP_VERSION
53+
5054
# 设置环境变量
5155
ENV FLASK_APP=app.py
5256
ENV FLASK_ENV=production
5357
ENV PUID=1000
5458
ENV PGID=1000
5559
ENV UMASK=022
60+
ENV APP_NAME=${APP_NAME}
61+
ENV APP_VERSION=${APP_VERSION}
5662

5763
# 使用entrypoint脚本
5864
ENTRYPOINT ["entrypoint.sh"]

app.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,38 @@
4848

4949
logger = logging.getLogger(__name__)
5050

51+
# 获取应用版本号
52+
def get_app_version():
53+
"""
54+
获取应用版本号,优先从git命令获取,失败则从环境变量获取,最后使用默认值
55+
"""
56+
# 尝试从git命令获取版本号
57+
try:
58+
# 执行git命令获取最新tag
59+
result = subprocess.run(
60+
['git', 'describe', '--tags', '--always'],
61+
capture_output=True,
62+
text=True,
63+
check=True
64+
)
65+
git_version = result.stdout.strip()
66+
if git_version:
67+
return git_version
68+
except (subprocess.CalledProcessError, FileNotFoundError):
69+
# git命令执行失败,从环境变量获取
70+
logger.warning("从git获取版本号失败,尝试从环境变量获取")
71+
72+
# 尝试从环境变量获取版本号
73+
env_version = os.environ.get('APP_VERSION')
74+
if env_version:
75+
return env_version
76+
77+
# 最后使用默认值
78+
return '未知'
79+
80+
# 初始化应用版本号
81+
APP_VERSION = get_app_version()
82+
5183
# 导入geopy库用于地址查询
5284
from geopy.geocoders import Nominatim
5385

@@ -2240,5 +2272,14 @@ def get_config():
22402272
logger.info(f"获取CPU核心数: {cpu_count}")
22412273
return jsonify({'base_dir': BASE_DIR, 'cpu_count': cpu_count})
22422274

2275+
@app.route('/get_version')
2276+
def get_version():
2277+
"""
2278+
获取应用版本号
2279+
返回: JSON格式的版本号信息
2280+
"""
2281+
logger.info(f"获取应用版本号: {APP_VERSION}")
2282+
return jsonify({'version': APP_VERSION})
2283+
22432284
if __name__ == '__main__':
22442285
app.run(debug=True, host='0.0.0.0', port=5000)

0 commit comments

Comments
 (0)