docker-registry-sync 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzUzOWU0NTYzYjIxOTU0NmE1NTg2Zjg4M2U2MDdiY2Y4MTBkYmRhNw==
4
+ OTY5YTA1Y2I2Y2M2Nzk0OTQ3MjE3ZGY0MjUyNmYyNjJlYmVmZDU5Yw==
5
5
  data.tar.gz: !binary |-
6
- M2JiMmQ2OWExODdiMGIzZTBmMzQ2M2Q3ZGExNzAyOTdkZmJhMzY4NQ==
6
+ Yjg0ZGZkNzcwNjRiMWQwOWI2YzAyMTg2NGNkYjMzNWVkY2NkM2E2ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2FlMjc2YWU5MWQwM2U2NDY2MWE2OWZkMzA4MjM2N2M3NDYzZWNkYTllNzMw
10
- MDgyNDA3MjhmZjEzNTZkNjQyOWZjZDc2OWM3ZmUyOTgzZWMzZTliZjAzOTc0
11
- NjU3YmU4NmQ5MzhlZWFjZDViYTczMzM5Yjc1ZTE4ODY3M2QxNWE=
9
+ NGVmMDkzNzgzNzI4YTQ1MDliYTJiNGNjMGUxYjA1ZDA3ODc3MmU5MzgzYjUy
10
+ ODk3NWFkMDJmM2FiNTM1MDY5OGNlYjVlMzcwMjNhY2FjZDA5OTM2ZDU1Mjcy
11
+ NmRkMGRmODAzNWM1OWI3ZDVkNmU0NGFiZTEzZDYzZDg2NTExMDk=
12
12
  data.tar.gz: !binary |-
13
- MjkzODFhMzkzMWVkOTBlMWM1NGY1NDc0NDA4OTUyNzExMWE3MzAwNzUwNDNk
14
- MWQ1YmZiNjdhOTVmZGZkMzQyNzg2MTY2MDE2NzgwOWJhZmMyYTM5ZGRmMTJj
15
- MDk3NGRhZjNkYTEwM2Y1ZGFlOTVlNDlhZTdmZTI4NjExODI0MGM=
13
+ N2FiMjhiMWM4YTZlMTVhMDNiOGU3MTA0NzUyMmE5NjE0M2M3NzA2ZDYxNWI4
14
+ ZTk2Mzc1MTM1OGMzZTJiMTU5ZDA3Yjc5YjFkNmY2OGQ1MGYzNTM5OGU1ZWI4
15
+ OTllNWMxNjhiYmNkZTAxMGY2MTAzMGY2NTAwZmQwM2U2NTk2ODE=
@@ -56,7 +56,7 @@ module Docker
56
56
  if image_exists?(image, bucket, region)
57
57
  success = sync_tag(image, tag, bucket, region)
58
58
  else
59
- success = sync_image(image, bucket, region)
59
+ success = sync_repo(image, bucket, region)
60
60
  end
61
61
  end
62
62
  success ? 0 : 1
@@ -107,7 +107,7 @@ module Docker
107
107
  end
108
108
  else
109
109
  @config.logger.info("Syncing image: #{data['image']} to #{data['target']['region']}:#{data['target']['bucket']}")
110
- if sync_image(data['image'], data['target']['bucket'], data['target']['region'], data['source']['bucket'], data['source']['region'])
110
+ if sync_repo(data['image'], data['target']['bucket'], data['target']['region'], data['source']['bucket'], data['source']['region'])
111
111
  @config.logger.info("Finished syncing image: #{data['image']} to #{data['target']['region']}:#{data['target']['bucket']}")
112
112
  finalize_message(message.receipt_handle)
113
113
  else
@@ -32,18 +32,21 @@ module Docker
32
32
  def debug(msg)
33
33
  if do_log?(:debug, Docker::Registry::Sync.config.log_level)
34
34
  STDOUT.puts "[DEBUG] #{msg}"
35
+ STDOUT.flush
35
36
  end
36
37
  end
37
38
 
38
39
  def info(msg)
39
40
  if do_log?(:info, Docker::Registry::Sync.config.log_level)
40
41
  STDOUT.puts "[INFO] #{msg}"
42
+ STDOUT.flush
41
43
  end
42
44
  end
43
45
 
44
46
  def error(msg)
45
47
  if do_log?(:error, Docker::Registry::Sync.config.log_level)
46
48
  STDERR.puts "[ERROR] #{msg}"
49
+ STDERR.flush
47
50
  end
48
51
  end
49
52
  end
@@ -18,34 +18,6 @@ module Docker
18
18
  end
19
19
  end
20
20
 
21
- def sync_prefix(source_client, target_client, target_bucket, prefix, source_bucket = nil)
22
- source_bucket ||= @config.source_bucket
23
- keys = []
24
- img_resp = source_client.list_objects(bucket: source_bucket, prefix: prefix)
25
-
26
- loop do
27
- img_resp.contents.each do |item|
28
- keys << item.key
29
- end
30
- if img_resp.last_page?
31
- break
32
- else
33
- img_resp.next_page
34
- end
35
- end
36
- sync_keys(target_client, target_bucket, keys)
37
- end
38
-
39
- def sync_keys(target_client, target_bucket, keys, source_bucket = nil)
40
- source_bucket ||= @config.source_bucket
41
- keys.each do |key|
42
- @config.logger.info "Syncing key #{source_bucket}/#{key} to bucket #{target_bucket}"
43
- target_client.copy_object(acl: 'bucket-owner-full-control',
44
- bucket: target_bucket,
45
- key: key,
46
- copy_source: "#{source_bucket}/#{key}")
47
- end
48
- end
49
21
 
50
22
  def sync_tag(image, tag, bucket, region, source_bucket = nil, source_region = nil)
51
23
  source_region ||= @config.source_region
@@ -58,11 +30,10 @@ module Docker
58
30
  keys = ["tag#{tag}_json", "tag_#{tag}", '_index_images'].map do |key|
59
31
  "registry/repositories/#{image}/#{key}"
60
32
  end
61
- sync_keys(s3_target, bucket, keys)
33
+ sync_keys(s3_target, bucket, keys, source_bucket)
62
34
 
63
- img_id_resp = s3_source.get_object(bucket: source_bucket, key: "registry/repositories/#{image}/tag_#{tag}")
64
- img_prefix = "registry/images/#{img_id_resp.body.read}/"
65
- sync_prefix(s3_source, s3_target, bucket, img_prefix)
35
+ img_id = s3_source.get_object(bucket: source_bucket, key: "registry/repositories/#{image}/tag_#{tag}").body.read
36
+ sync_image(img_id, bucket, region, source_bucket, source_region)
66
37
  rescue Exception => e
67
38
  @config.logger.error "An unexpected error occoured while syncing tag #{image}:#{tag}: #{e}"
68
39
  false
@@ -71,28 +42,68 @@ module Docker
71
42
  end
72
43
  end
73
44
 
74
- def sync_image(image, bucket, region, source_bucket = nil, source_region = nil)
45
+ def sync_repo(repo, bucket, region, source_bucket = nil, source_region = nil)
75
46
  source_region ||= @config.source_region
76
47
  source_bucket ||= @config.source_bucket
77
48
  s3_source = Aws::S3::Client.new(region: source_region)
78
49
  s3_target = Aws::S3::Client.new(region: region)
79
50
 
80
51
  begin
81
- rep_prefix = "registry/repositories/#{image}/"
82
- sync_prefix(s3_source, s3_target, bucket, rep_prefix)
52
+ rep_prefix = "registry/repositories/#{repo}/"
53
+ sync_prefix(s3_source, s3_target, bucket, rep_prefix, source_bucket)
83
54
 
84
- img_index_resp = s3_source.get_object(bucket: source_bucket, key: "registry/repositories/#{image}/_index_images")
55
+ img_index_resp = s3_source.get_object(bucket: source_bucket, key: "registry/repositories/#{repo}/_index_images")
85
56
  JSON.load(img_index_resp.body.read).each do |image|
86
- image_prefix = "registry/images/#{image['id']}/"
87
- sync_prefix(s3_source, s3_target, bucket, image_prefix)
57
+ sync_image(image['id'], bucket, region, source_bucket, source_region)
88
58
  end
89
59
  rescue Exception => e
90
- @config.logger.error "An unexpected error occoured while syncing image #{image}: #{e}"
60
+ @config.logger.error "An unexpected error occoured while syncing repo #{repo}: #{e}"
91
61
  false
92
62
  else
93
63
  true
94
64
  end
95
65
  end
66
+
67
+ def sync_image(image_id, bucket, region, source_bucket = nil, source_region = nil)
68
+ source_region ||= @config.source_region
69
+ source_bucket ||= @config.source_bucket
70
+ s3_source = Aws::S3::Client.new(region: source_region)
71
+ s3_target = Aws::S3::Client.new(region: region)
72
+
73
+ ancestry_resp = s3_source.get_object(bucket: source_bucket, key: "registry/images/#{image_id}/ancestry")
74
+ # Ancestry includes self
75
+ JSON.load(ancestry_resp.body.read).each do |image|
76
+ sync_prefix(s3_source, s3_target, bucket, "registry/images/#{image}/", source_bucket)
77
+ end
78
+ end
79
+
80
+ @private
81
+ def sync_prefix(source_client, target_client, target_bucket, prefix, source_bucket)
82
+ keys = []
83
+ img_resp = source_client.list_objects(bucket: source_bucket, prefix: prefix)
84
+
85
+ loop do
86
+ img_resp.contents.each do |item|
87
+ keys << item.key
88
+ end
89
+ if img_resp.last_page?
90
+ break
91
+ else
92
+ img_resp.next_page
93
+ end
94
+ end
95
+ sync_keys(target_client, target_bucket, keys, source_bucket)
96
+ end
97
+
98
+ def sync_keys(target_client, target_bucket, keys, source_bucket)
99
+ keys.each do |key|
100
+ @config.logger.info "Syncing key #{source_bucket}/#{key} to bucket #{target_bucket}"
101
+ target_client.copy_object(acl: 'bucket-owner-full-control',
102
+ bucket: target_bucket,
103
+ key: key,
104
+ copy_source: "#{source_bucket}/#{key}")
105
+ end
106
+ end
96
107
  end
97
108
  end
98
109
  end
@@ -1,7 +1,7 @@
1
1
  module Docker
2
2
  module Registry
3
3
  module Sync
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-registry-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Oldfield