feat(updates): NetBird container image update management
- New image_service.py: Docker Hub digest check (no pull), local digest/ID
comparison, pull_all_images, per-customer container image status, and
update_customer_containers (docker compose up -d, data-safe)
- Monitoring endpoints: GET /images/check (hub vs local + per-customer
needs_update), POST /images/pull (background), POST /customers/update-all
- Deployment endpoint: POST /{id}/update-images (single-customer update)
- Monitoring page: "NetBird Container Updates" card with Check / Pull / Update
All buttons; image status table and per-customer update table with inline
update buttons
- i18n: added keys in en.json and de.json
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,8 +7,8 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.database import SessionLocal, get_db
|
||||
from app.dependencies import get_current_user
|
||||
from app.models import Customer, Deployment, User
|
||||
from app.services import docker_service, netbird_service
|
||||
from app.models import Customer, Deployment, SystemConfig, User
|
||||
from app.services import docker_service, image_service, netbird_service
|
||||
from app.utils.security import decrypt_value
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -207,6 +207,50 @@ async def get_customer_credentials(
|
||||
}
|
||||
|
||||
|
||||
@router.post("/{customer_id}/update-images")
|
||||
async def update_customer_images(
|
||||
customer_id: int,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Recreate a customer's containers to pick up newly pulled images.
|
||||
|
||||
Images must already be pulled via POST /monitoring/images/pull.
|
||||
Bind-mounted data is preserved — no data loss.
|
||||
"""
|
||||
if current_user.role != "admin":
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Admin only.")
|
||||
|
||||
customer = _require_customer(db, customer_id)
|
||||
deployment = db.query(Deployment).filter(Deployment.customer_id == customer_id).first()
|
||||
if not deployment:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="No deployment found for this customer.",
|
||||
)
|
||||
|
||||
config = db.query(SystemConfig).filter(SystemConfig.id == 1).first()
|
||||
if not config:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail="System not configured."
|
||||
)
|
||||
|
||||
instance_dir = f"{config.data_dir}/{customer.subdomain}"
|
||||
result = await image_service.update_customer_containers(instance_dir, deployment.container_prefix)
|
||||
|
||||
if not result["success"]:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=result.get("error", "Failed to update containers."),
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"Containers updated for customer '%s' (prefix: %s) by '%s'.",
|
||||
customer.name, deployment.container_prefix, current_user.username,
|
||||
)
|
||||
return {"message": f"Containers updated for '{customer.name}'."}
|
||||
|
||||
|
||||
def _require_customer(db: Session, customer_id: int) -> Customer:
|
||||
"""Helper to fetch a customer or raise 404.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user