def validate_docker_image(*, pk: uuid.UUID, app_label: str, model_name: str): model = apps.get_model(app_label=app_label, model_name=model_name) instance = model.objects.get(pk=pk) if not instance.image: if instance.user_upload: with transaction.atomic(): instance.user_upload.copy_object(to_field=instance.image) instance.user_upload.delete() # Another validation job will be launched to validate this return else: # No image to validate return try: image_sha256 = _validate_docker_image_manifest(instance=instance) except ValidationError as e: model.objects.filter(pk=instance.pk).update(image_sha256="", ready=False, status=oxford_comma(e)) send_invalid_dockerfile_email(container_image=instance) return push_container_image(instance=instance) model.objects.filter(pk=instance.pk).update(image_sha256=image_sha256, ready=True)
def validate_docker_image(*, pk: uuid.UUID, app_label: str, model_name: str): model = apps.get_model(app_label=app_label, model_name=model_name) instance = model.objects.get(pk=pk) if not instance.image: # Create the image from the staged file uploaded_image = StagedAjaxFile(instance.staged_image_uuid) with uploaded_image.open() as f: instance.image.save(uploaded_image.name, File(f)) try: image_sha256 = _validate_docker_image_manifest(model=model, instance=instance) except ValidationError: send_invalid_dockerfile_email(container_image=instance) raise model.objects.filter(pk=instance.pk).update( image_sha256=f"sha256:{image_sha256}", ready=True)