Пример #1
0
 def test_push_same_blob(self, db_with_data1):
     p = db_with_data1.Package.get("titi/rocketchat", ">1.2", 'kpm')
     assert p.package == "titi/rocketchat"
     assert p.release == "2.0.1"
     assert p.digest == "d3b54b7912fe770a61b59ab612a442eac52a8a5d8d05dbe92bf8f212d68aaa80"
     blob = db_with_data1.Blob.get("titi/rocketchat", p.digest)
     bdb = appr_blob.get_blob(p.digest, appr_app_model.models_ref)
     newblob = db_with_data1.Blob("titi/app2", blob.b64blob)
     p2 = db_with_data1.Package("titi/app2", "1.0.0", "helm", newblob)
     p2.save()
     b2db = appr_blob.get_blob(p2.digest, appr_app_model.models_ref)
     assert b2db.id == bdb.id
Пример #2
0
def create_app_release(repo, tag_name, manifest_data, digest, models_ref, force=False):
  """ Create a new application release, it includes creating a new Tag, ManifestList,
      ManifestListManifests, Manifest, ManifestBlob.

      To deduplicate the ManifestList, the manifestlist_json is kept ordered by the manifest.id.
      To find the insert point in the ManifestList it uses bisect on the manifest-ids list.
  """
  ManifestList = models_ref.ManifestList
  ManifestListManifest = models_ref.ManifestListManifest
  Blob = models_ref.Blob
  ManifestBlob = models_ref.ManifestBlob

  with db_transaction():
    # Create/get the package manifest
    manifest = manifest_model.get_or_create_manifest(manifest_data, manifest_data['mediaType'],
                                                     models_ref)
    # get the tag
    tag = tag_model.get_or_initialize_tag(repo, tag_name, models_ref)

    if tag.manifest_list is None:
      tag.manifest_list = ManifestList(media_type=ManifestList.media_type.get_id(LIST_MEDIA_TYPE),
                                       schema_version=SCHEMA_VERSION,
                                       manifest_list_json=[], )

    elif tag_model.tag_media_type_exists(tag, manifest.media_type, models_ref):
      if force:
        delete_app_release(repo, tag_name, manifest.media_type.name, models_ref)
        return create_app_release(repo, tag_name, manifest_data, digest, models_ref, force=False)
      else:
        raise PackageAlreadyExists("package exists already")

    list_json = tag.manifest_list.manifest_list_json
    mlm_query = (ManifestListManifest
                 .select()
                 .where(ManifestListManifest.manifest_list == tag.manifest_list))
    list_manifest_ids = sorted([mlm.manifest_id for mlm in mlm_query])
    insert_point = bisect.bisect_left(list_manifest_ids, manifest.id)
    list_json.insert(insert_point, manifest.manifest_json)
    list_manifest_ids.insert(insert_point, manifest.id)
    manifestlist = manifest_list_model.get_or_create_manifest_list(list_json, LIST_MEDIA_TYPE,
                                                                   SCHEMA_VERSION, models_ref)
    manifest_list_model.create_manifestlistmanifest(manifestlist, list_manifest_ids, list_json,
                                                    models_ref)

    tag = tag_model.create_or_update_tag(repo, tag_name, models_ref, manifest_list=manifestlist,
                                         tag_kind="release")
    blob_digest = digest

    try:
      (ManifestBlob
       .select()
       .join(Blob)
       .where(ManifestBlob.manifest == manifest,
              Blob.digest == _ensure_sha256_header(blob_digest)).get())
    except ManifestBlob.DoesNotExist:
      blob = blob_model.get_blob(blob_digest, models_ref)
      ManifestBlob.create(manifest=manifest, blob=blob)
    return tag