Merge pull request #987 from coreos-inc/multimanifest

Make manifest generation safe for multiple callers
This commit is contained in:
josephschorr 2015-12-08 14:12:39 -05:00
commit 37dec895ce

View file

@ -2,6 +2,7 @@ import logging
import jwt.utils
import json
from peewee import IntegrityError
from flask import make_response, request, url_for
from collections import namedtuple, OrderedDict
from jwkest.jws import SIGNER_ALGS, keyrep
@ -410,7 +411,15 @@ def _generate_and_store_manifest(namespace, repo_name, tag_name):
# Sign the manifest with our signing key.
manifest = builder.build(docker_v2_signing_key)
manifest_row = model.tag.associate_generated_tag_manifest(namespace, repo_name, tag_name,
manifest.digest, manifest.bytes)
return manifest_row
# Write the manifest to the DB. If an existing manifest already exists, return the
# one found.
try:
return model.tag.associate_generated_tag_manifest(namespace, repo_name, tag_name,
manifest.digest, manifest.bytes)
except IntegrityError:
try:
return model.tag.load_tag_manifest(namespace, repo_name, tag_name)
except model.InvalidManifestException:
raise model.DataModelException('Could not load or generate manifest')