mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-11-09 21:43:05 +09:00
- ImageUpdateCheck model + ImageUpdateService: compare an app's local RepoDigest against the registry's current index digest (via `docker buildx imagetools inspect`) for the same tag, and flag update_available when they differ. Shells out to docker like the rest of the Docker layer; degrades gracefully when the image is local-only or the registry is unreachable. - API: admin POST /api/v1/image-updates/applications/<id>/check and GET /api/v1/image-updates/applications/<id> for the latest result. - Application.to_dict gains a lightweight image_update badge (mirrors the existing image_scan badge). - 7 tests: digest diff/match/unknown, no-image, badge, endpoint, auth gate. One-click apply (pull + recreate) to follow. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from flask import Blueprint, jsonify
|
|
from flask_jwt_extended import jwt_required, get_jwt_identity
|
|
from app.models.user import User
|
|
from app.services.image_update_service import ImageUpdateService
|
|
|
|
image_updates_bp = Blueprint('image_updates', __name__)
|
|
|
|
|
|
def _admin():
|
|
user = User.query.get(get_jwt_identity())
|
|
return user if user and user.is_admin else None
|
|
|
|
|
|
@image_updates_bp.route('/applications/<int:app_id>/check', methods=['POST'])
|
|
@jwt_required()
|
|
def check(app_id):
|
|
"""Run a registry-digest comparison for the application's image now."""
|
|
if not _admin():
|
|
return jsonify({'error': 'Admin access required'}), 403
|
|
result = ImageUpdateService.check_application(app_id)
|
|
if not result['success']:
|
|
code = 404 if 'not found' in result['error'].lower() else 400
|
|
return jsonify({'error': result['error']}), code
|
|
return jsonify(result['check'])
|
|
|
|
|
|
@image_updates_bp.route('/applications/<int:app_id>', methods=['GET'])
|
|
@jwt_required()
|
|
def latest(app_id):
|
|
"""Return the most recent image-update check for the application (or null)."""
|
|
check_row = ImageUpdateService.latest_check(app_id)
|
|
return jsonify(check_row.to_dict() if check_row else None)
|