This commit is contained in:
2025-06-23 09:30:04 +02:00
parent 9fc09be7de
commit 0da5d9305d
11 changed files with 444 additions and 40 deletions

View File

@@ -379,18 +379,58 @@ def init_routes(main_bp):
instances = Instance.query.order_by(Instance.name.asc()).all()
# Check status for each instance
# Get Git settings
git_settings = KeyValueSettings.get_value('git_settings')
gitea_url = git_settings.get('url') if git_settings else None
gitea_token = git_settings.get('token') if git_settings else None
gitea_repo = git_settings.get('repo') if git_settings else None
for instance in instances:
# 1. Check status
status_info = check_instance_status(instance)
instance.status = status_info['status']
instance.status_details = status_info['details']
# 2. Check deployed version
deployed_version = None
deployed_tag = None
deployed_commit = None
try:
version_url = f"{instance.main_url.rstrip('/')}/api/version"
resp = requests.get(version_url, timeout=5)
if resp.status_code == 200:
version_data = resp.json()
deployed_version = version_data.get('version', 'unknown')
deployed_tag = version_data.get('tag', 'unknown')
deployed_commit = version_data.get('commit', 'unknown')
except Exception as e:
deployed_version = None
deployed_tag = None
deployed_commit = None
instance.deployed_version = deployed_tag or deployed_version or 'unknown'
instance.deployed_branch = instance.deployed_branch or 'master'
# 3. Check latest version from Gitea (if settings available)
latest_version = None
deployed_branch = instance.deployed_branch or 'master'
if gitea_url and gitea_token and gitea_repo:
try:
headers = {'Accept': 'application/json', 'Authorization': f'token {gitea_token}'}
# Gitea API: /api/v1/repos/{owner}/{repo}/commits/{branch}
commit_url = f"{gitea_url}/api/v1/repos/{gitea_repo}/commits/{deployed_branch}"
commit_resp = requests.get(commit_url, headers=headers, timeout=5)
if commit_resp.status_code == 200:
latest_version = commit_resp.json().get('sha')
except Exception as e:
latest_version = None
instance.latest_version = latest_version or 'unknown'
instance.version_checked_at = datetime.utcnow()
db.session.commit()
# Get connection settings
portainer_settings = KeyValueSettings.get_value('portainer_settings')
nginx_settings = KeyValueSettings.get_value('nginx_settings')
git_settings = KeyValueSettings.get_value('git_settings')
cloudflare_settings = KeyValueSettings.get_value('cloudflare_settings')
return render_template('main/instances.html',
@@ -1975,4 +2015,36 @@ def init_routes(main_bp):
flash('This page is only available in master instances.', 'error')
return redirect(url_for('main.dashboard'))
return render_template('wiki/base.html')
return render_template('wiki/base.html')
@main_bp.route('/api/version')
def api_version():
version_file = os.path.join(current_app.root_path, 'version.txt')
version = 'unknown'
version_data = {}
if os.path.exists(version_file):
with open(version_file, 'r') as f:
content = f.read().strip()
# Try to parse as JSON first (new format)
try:
version_data = json.loads(content)
version = version_data.get('tag', 'unknown')
except json.JSONDecodeError:
# Fallback to old format (just commit hash)
version = content
version_data = {
'tag': 'unknown',
'commit': content,
'branch': 'unknown',
'deployed_at': 'unknown'
}
return jsonify({
'version': version,
'tag': version_data.get('tag', 'unknown'),
'commit': version_data.get('commit', 'unknown'),
'branch': version_data.get('branch', 'unknown'),
'deployed_at': version_data.get('deployed_at', 'unknown')
})