Skip to content

Commit 6d5c776

Browse files
author
yyhuni
committed
chore: improve version detection and update deployment configuration
- Update version detection to support IMAGE_TAG environment variable for Docker containers - Add fallback mechanism to check multiple version file paths (/app/VERSION and project root) - Add IMAGE_TAG environment variable to docker-compose.dev.yml and docker-compose.yml - Fix frontend access URL in start.sh to include correct port (8083) - Update upgrade warning message in update.sh to recommend fresh installation with latest code - Improve robustness of version retrieval with better error handling for missing files
1 parent bf058dd commit 6d5c776

File tree

5 files changed

+26
-7
lines changed

5 files changed

+26
-7
lines changed

backend/apps/common/views/version_views.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,26 @@
2323

2424
def get_current_version() -> str:
2525
"""读取当前版本号"""
26-
version_file = Path(__file__).parent.parent.parent.parent.parent / 'VERSION'
27-
try:
28-
return version_file.read_text(encoding='utf-8').strip()
29-
except FileNotFoundError:
30-
return "unknown"
26+
import os
27+
28+
# 方式1:从环境变量读取(Docker 容器中推荐)
29+
version = os.environ.get('IMAGE_TAG', '')
30+
if version:
31+
return version
32+
33+
# 方式2:从文件读取(开发环境)
34+
possible_paths = [
35+
Path('/app/VERSION'),
36+
Path(__file__).parent.parent.parent.parent.parent / 'VERSION',
37+
]
38+
39+
for path in possible_paths:
40+
try:
41+
return path.read_text(encoding='utf-8').strip()
42+
except (FileNotFoundError, OSError):
43+
continue
44+
45+
return "unknown"
3146

3247

3348
def compare_versions(current: str, latest: str) -> bool:

docker/docker-compose.dev.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ services:
4444
restart: always
4545
env_file:
4646
- .env
47+
environment:
48+
- IMAGE_TAG=${IMAGE_TAG:-dev}
4749
ports:
4850
- "8888:8888"
4951
depends_on:

docker/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ services:
4848
restart: always
4949
env_file:
5050
- .env
51+
environment:
52+
- IMAGE_TAG=${IMAGE_TAG}
5153
depends_on:
5254
redis:
5355
condition: service_healthy

docker/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ echo -e "${BOLD}${GREEN}══════════════════
182182
echo ""
183183
echo -e "${BOLD}访问地址${NC}"
184184
if [ "$WITH_FRONTEND" = true ]; then
185-
echo -e " XingRin: ${CYAN}https://${ACCESS_HOST}/${NC}"
185+
echo -e " XingRin: ${CYAN}https://${ACCESS_HOST}:8083/${NC}"
186186
echo -e " ${YELLOW}(HTTP 会自动跳转到 HTTPS)${NC}"
187187
else
188188
echo -e " API: ${CYAN}通过前端或 nginx 访问(后端未暴露 8888)${NC}"

update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ echo ""
9494

9595
# 测试性功能警告
9696
echo -e "${BOLD}${YELLOW}[!] 警告:此功能为测试性功能,可能会导致升级失败${NC}"
97-
echo -e "${YELLOW} 建议运行 ./uninstall.sh 后重新执行 ./install.sh 进行全新安装${NC}"
97+
echo -e "${YELLOW} 建议运行 ./uninstall.sh 后重新clone最新代码进行全新安装${NC}"
9898
echo ""
9999
echo -n -e "${YELLOW}是否继续更新?(y/N) ${NC}"
100100
read -r ans_continue

0 commit comments

Comments
 (0)