diff options
author | Giorgenes Gelatti <ggelatti@gitlab.com> | 2019-09-04 09:13:18 +0300 |
---|---|---|
committer | Giorgenes Gelatti <ggelatti@gitlab.com> | 2019-09-09 05:21:00 +0300 |
commit | ab43a0f3fa2390e3a8033765bb6e88ed96bf99d8 (patch) | |
tree | 46120bb9dcd5f0f8a13ba66c1898877077ab10a3 | |
parent | 833cc9206fe3b40a86ebaa75a0b3ab9aad782d2d (diff) |
Make tag#delete use dummy tags hack
-rw-r--r-- | lib/container_registry/tag.rb | 13 | ||||
-rw-r--r-- | spec/lib/container_registry/tag_spec.rb | 28 |
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/container_registry/tag.rb b/lib/container_registry/tag.rb index ebea84fa1ca..c3c16f94615 100644 --- a/lib/container_registry/tag.rb +++ b/lib/container_registry/tag.rb @@ -107,6 +107,19 @@ module ContainerRegistry # rubocop: enable CodeReuse/ActiveRecord def delete + # Replace the image with a dummy image, + # so we don't delete the original image + client.put_dummy_tag(repository.path, name) + + # put_dummy changes the tag digest, + # so we make sure we're fetching the up-to-date one + clear_memoization(:digest) + + delete_image + end + + # Deletes the image associated with this tag + def delete_image return unless digest client.delete_repository_tag(repository.path, digest) diff --git a/spec/lib/container_registry/tag_spec.rb b/spec/lib/container_registry/tag_spec.rb index 110f006536b..a219b68fa3c 100644 --- a/spec/lib/container_registry/tag_spec.rb +++ b/spec/lib/container_registry/tag_spec.rb @@ -179,11 +179,39 @@ describe ContainerRegistry::Tag do end end + describe '#delete_image' do + before do + stub_request(:delete, 'http://registry.gitlab/v2/group/test/manifests/sha256:digest') + .with(headers: headers) + .to_return(status: 200) + end + + it 'correctly deletes the image' do + expect(tag.delete_image).to be_truthy + end + end + describe '#delete' do before do stub_request(:delete, 'http://registry.gitlab/v2/group/test/manifests/sha256:digest') .with(headers: headers) .to_return(status: 200) + + stub_request(:post, 'http://registry.gitlab/v2/group/test/blobs/uploads/') + .with(headers: headers) + .to_return(status: 200, headers: { 'Location' => 'http://registry.gitlab/v2/group/test/blobs/uploads/foobar123' }) + + stub_request(:put, 'http://registry.gitlab/v2/group/test/blobs/uploads/foobar123?digest=sha256:73b20b59e1a1c2b20e508616702aefe0022c9ff785398d7b1965c08846356ad4') + .with(headers: headers) + .to_return(status: 201, headers: {}) + + stub_request(:put, 'http://registry.gitlab/v2/group/test/blobs/uploads/foobar123?digest=sha256:3454bd3db87cdbd71feefd8d42dd32674e032d2e50daa5c8ad79135e872646c5') + .with(headers: headers) + .to_return(status: 201, headers: {}) + + stub_request(:put, 'http://registry.gitlab/v2/group/test/manifests/tag') + .with(headers: headers) + .to_return(status: 200, headers: {}) end it 'correctly deletes the tag' do |