Add the resource_key back to the repository build.
This commit is contained in:
parent
b9580c1c29
commit
c13f7cd9df
8 changed files with 20 additions and 18 deletions
|
@ -237,6 +237,7 @@ class RepositoryBuild(BaseModel):
|
|||
uuid = CharField(default=uuid_generator, index=True)
|
||||
repository = ForeignKeyField(Repository, index=True)
|
||||
access_token = ForeignKeyField(AccessToken)
|
||||
resource_key = CharField(index=True)
|
||||
job_config = TextField()
|
||||
phase = CharField(default='waiting')
|
||||
started = DateTimeField(default=datetime.now)
|
||||
|
|
|
@ -775,14 +775,15 @@ def get_all_repo_users(namespace_name, repository_name):
|
|||
|
||||
|
||||
def get_repository_for_resource(resource_key):
|
||||
joined = Repository.select().join(RepositoryBuild)
|
||||
query = joined.where(RepositoryBuild.resource_key == resource_key).limit(1)
|
||||
result = list(query)
|
||||
if not result:
|
||||
try:
|
||||
return (Repository
|
||||
.select()
|
||||
.join(RepositoryBuild)
|
||||
.where(RepositoryBuild.resource_key == resource_key)
|
||||
.get())
|
||||
except Repository.DoesNotExist:
|
||||
return None
|
||||
|
||||
return result[0]
|
||||
|
||||
|
||||
def get_repository(namespace_name, repository_name):
|
||||
try:
|
||||
|
@ -1420,11 +1421,12 @@ def list_repository_builds(namespace_name, repository_name,
|
|||
return query
|
||||
|
||||
|
||||
def create_repository_build(repo, access_token, job_config_obj,
|
||||
def create_repository_build(repo, access_token, job_config_obj, dockerfile_id,
|
||||
display_name, trigger=None):
|
||||
return RepositoryBuild.create(repository=repo, access_token=access_token,
|
||||
job_config=json.dumps(job_config_obj),
|
||||
display_name=display_name, trigger=trigger)
|
||||
display_name=display_name, trigger=trigger,
|
||||
resource_key=dockerfile_id)
|
||||
|
||||
|
||||
def create_webhook(repo, params_obj):
|
||||
|
|
|
@ -1252,15 +1252,14 @@ def request_repo_build(namespace, repository):
|
|||
logger.debug('**********Md5: %s' % display_name)
|
||||
|
||||
host = urlparse.urlparse(request.url).netloc
|
||||
repo = '%s/%s/%s' % (host, repo.namespace, repo.name)
|
||||
repo_tag_base = '%s/%s/%s' % (host, repo.namespace, repo.name)
|
||||
job_config = {
|
||||
'docker_tags': ['latest'],
|
||||
'build_subdir': '',
|
||||
'repository': repo,
|
||||
'resource_key': dockerfile_id,
|
||||
'repository': repo_tag_base,
|
||||
}
|
||||
build_request = model.create_repository_build(repo, token, job_config,
|
||||
display_name)
|
||||
dockerfile_id, display_name)
|
||||
dockerfile_build_queue.put(json.dumps({
|
||||
'build_uuid': build_request.uuid,
|
||||
'namespace': namespace,
|
||||
|
|
|
@ -84,10 +84,10 @@ def build_trigger_webhook(namespace, repository, trigger_uuid):
|
|||
'docker_tags': tags,
|
||||
'repository': repo,
|
||||
'build_subdir': subdir,
|
||||
'resource_key': dockerfile_id,
|
||||
}
|
||||
build_request = model.create_repository_build(trigger.repository, token,
|
||||
job_config, name, trigger)
|
||||
job_config, dockerfile_id,
|
||||
name, trigger)
|
||||
|
||||
dockerfile_build_queue.put(json.dumps({
|
||||
'build_uuid': build_request.uuid,
|
||||
|
|
|
@ -327,9 +327,9 @@ def populate_database():
|
|||
'repository': repo,
|
||||
'docker_tags': ['latest'],
|
||||
'build_subdir': '',
|
||||
'resource_key': '701dcc3724fb4f2ea6c31400528343cd',
|
||||
}
|
||||
build = model.create_repository_build(building, token, job_config,
|
||||
'701dcc3724fb4f2ea6c31400528343cd'
|
||||
'build-name', trigger)
|
||||
build.uuid = 'deadbeef-dead-beef-dead-beefdeadbeef'
|
||||
build.save()
|
||||
|
|
Binary file not shown.
|
@ -858,7 +858,7 @@ class TestGetRepoBuilds(ApiTestCase):
|
|||
assert 'status' in build
|
||||
|
||||
|
||||
class TestRequearRepoBuild(ApiTestCase):
|
||||
class TestRequestRepoBuild(ApiTestCase):
|
||||
def test_requestrepobuild(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
|
@ -871,7 +871,7 @@ class TestRequearRepoBuild(ApiTestCase):
|
|||
# Request a (fake) build.
|
||||
self.postResponse('api.request_repo_build',
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
||||
data=dict(file_id = 'foobarbaz'),
|
||||
data=dict(file_id='foobarbaz'),
|
||||
expected_code=201)
|
||||
|
||||
# Check for the build.
|
||||
|
|
|
@ -274,7 +274,7 @@ class DockerfileBuildWorker(Worker):
|
|||
|
||||
job_config = json.loads(repository_build.job_config)
|
||||
|
||||
resource_url = user_files.get_file_url(job_config['resource_key'])
|
||||
resource_url = user_files.get_file_url(repository_build.resource_key)
|
||||
tag_names = job_config['docker_tags']
|
||||
build_subdir = job_config['build_subdir']
|
||||
repo = job_config['repository']
|
||||
|
|
Reference in a new issue