Commit 3e4264c4 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch '215715-registry-repository-create-fix' into 'master'

Fix race condition on container repository creation

See merge request gitlab-org/gitlab!65358
parents f68b448a 8ff1ec36
......@@ -153,7 +153,8 @@ class ContainerRepository < ApplicationRecord
end
def self.create_from_path!(path)
build_from_path(path).tap(&:save!)
safe_find_or_create_by!(project: path.repository_project,
name: path.repository_name)
end
def self.build_root_repository(project)
......
......@@ -281,6 +281,16 @@ RSpec.describe ContainerRepository do
expect(repository.name).to be_empty
end
end
context 'when repository already exists' do
let(:path) { project.full_path + '/some/image' }
it 'returns the existing repository' do
container_repository = create(:container_repository, project: project, name: 'some/image')
expect(repository.id).to eq(container_repository.id)
end
end
end
describe '.build_root_repository' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment