retag 0.1.0.73710
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +43 -0
- data/lib/retag/image.rb +50 -0
- data/lib/retag/logger.rb +34 -0
- data/lib/retag/service.rb +48 -0
- data/lib/retag/utils.rb +55 -0
- data/lib/retag/version.rb +8 -0
- data/lib/retag.rb +13 -0
- metadata +241 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 21c93d3dc99eeea3246460f4dfa166d52eabd222e26c834fb70e01efa67a9b76
|
4
|
+
data.tar.gz: df60a6f712e511f377dfdf6f9d30d9023f4c805716c2bb5ba059b788adcbc83f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb34a11116989b740c3befb0b3707df6d81bffda5712740eaa4a7fdad83f8aa7f580f280a1ecbfa82690df5331b845db0ed7462285606fe8c29e09d44209b24e
|
7
|
+
data.tar.gz: e400dcf1c51a19ba40b7139e88b26dfeffc1914e7c2bdc8f851401f8c97cb1fc7fefae1330c2135869c700ee313048a0cf280cde6089b35cc6e7fb48763eaaaa
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014-2022 Рнд Софт
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Retag
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/retag`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'retag'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install retag
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/retag. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/retag/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Retag project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/retag/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/retag/image.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Retag
|
5
|
+
class Image
|
6
|
+
|
7
|
+
include Utils
|
8
|
+
attr_reader :full, :image, :tag
|
9
|
+
|
10
|
+
def initialize(image, tag, suffix: nil)
|
11
|
+
@image = image
|
12
|
+
@tag = tag
|
13
|
+
@tag = "#{tag}-#{suffix}" if suffix.present?
|
14
|
+
@full = "#{image}:#{tag}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def retag!(newtag = tag)
|
18
|
+
uri = ::URI.parse("https://#{image}")
|
19
|
+
repo = uri.path
|
20
|
+
repo[0..0] = ''
|
21
|
+
uri.path = ''
|
22
|
+
|
23
|
+
content_type = 'application/vnd.docker.distribution.manifest.v2+json'
|
24
|
+
|
25
|
+
Tempfile.create('manifest') do |file|
|
26
|
+
manifest = JSON.parse(cmd!("curl -s -u '#{dockerauth(uri.host)}' -H 'Accept: #{content_type}' '#{uri}/v2/#{repo}/manifests/#{tag}' -o -", capture: true).strip)
|
27
|
+
raise manifest unless manifest.dig('layers') || manifest.dig('config')
|
28
|
+
|
29
|
+
file.write(manifest.to_json)
|
30
|
+
file.flush
|
31
|
+
result = cmd!("curl -s -u '#{dockerauth(uri.host)}' -H 'Content-Type: #{content_type}' -H 'Accept: #{content_type}' -X PUT --data-binary @#{file.path} '#{uri}/v2/#{repo}/manifests/#{newtag}' -o -", capture: true).strip
|
32
|
+
raise result unless result.empty?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def pull(img = full)
|
37
|
+
cmd!("docker pull -q #{img}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def push(img = full)
|
41
|
+
cmd!("docker push -q #{img}")
|
42
|
+
end
|
43
|
+
|
44
|
+
def rm(img = full)
|
45
|
+
cmd!("docker rmi #{img}")
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/lib/retag/logger.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
|
4
|
+
module Retag
|
5
|
+
class Logger < ::Logger
|
6
|
+
|
7
|
+
def shift(spaces: 2, &block)
|
8
|
+
if block_given?
|
9
|
+
with_shift(spaces: spaces, &block)
|
10
|
+
else
|
11
|
+
@shift ||= 0
|
12
|
+
@shift += spaces
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def unshift(spaces: 2)
|
17
|
+
@shift ||= 0
|
18
|
+
@shift -= spaces
|
19
|
+
end
|
20
|
+
|
21
|
+
def with_shift(spaces: 2)
|
22
|
+
shift(spaces: spaces)
|
23
|
+
yield
|
24
|
+
ensure
|
25
|
+
unshift(spaces: spaces)
|
26
|
+
end
|
27
|
+
|
28
|
+
def format_message(severity, datetime, progname, msg)
|
29
|
+
super(severity, datetime, progname, "#{' ' * (@shift || 0)}#{msg}")
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Retag
|
2
|
+
class Service
|
3
|
+
|
4
|
+
include Retag::Utils
|
5
|
+
|
6
|
+
attr_reader :name, :config, :repo, :branch, :release
|
7
|
+
|
8
|
+
def initialize(name, config, release)
|
9
|
+
@name = name
|
10
|
+
@config = config
|
11
|
+
@repo = config['repo']
|
12
|
+
@branch = config['branch']
|
13
|
+
@release = release
|
14
|
+
end
|
15
|
+
|
16
|
+
def images
|
17
|
+
@images ||= config['images'].map{|img| Retag::Image.new(img, revision, suffix: 'stable') }
|
18
|
+
end
|
19
|
+
|
20
|
+
def pull
|
21
|
+
images.each(&:pull)
|
22
|
+
end
|
23
|
+
|
24
|
+
def push
|
25
|
+
images.each(&:push)
|
26
|
+
end
|
27
|
+
|
28
|
+
def rm
|
29
|
+
images.each(&:rm)
|
30
|
+
end
|
31
|
+
|
32
|
+
def release!(tag = release)
|
33
|
+
images.each do |image|
|
34
|
+
image.retag!(tag)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def revision
|
39
|
+
@revision ||= begin
|
40
|
+
rev, _name = cmd!("git ls-remote #{repo} #{branch}", capture: true).split("\n").select{|line| line["heads/#{branch}"] }.first.split
|
41
|
+
rev[0..7]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/lib/retag/utils.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
module Retag
|
5
|
+
module Utils
|
6
|
+
|
7
|
+
def cmd!(cmd, capture: false, logger: $logger)
|
8
|
+
$cmdnum ||= 0
|
9
|
+
$cmdnum += 1
|
10
|
+
tag = $cmdnum.to_s.rjust(3, '0')
|
11
|
+
output = ''
|
12
|
+
|
13
|
+
logger.tagged("CMD#{tag}") { logger.debug cmd }
|
14
|
+
|
15
|
+
code = Open3.popen3(cmd) do |stdin, stdout, stderr, thr|
|
16
|
+
stdin.close_write
|
17
|
+
files = [stdout, stderr]
|
18
|
+
|
19
|
+
until files.empty?
|
20
|
+
ready = IO.select(files)
|
21
|
+
readable = ready[0]
|
22
|
+
|
23
|
+
readable.each do |f|
|
24
|
+
begin
|
25
|
+
line = f.readline
|
26
|
+
if f == stderr
|
27
|
+
logger.tagged("ERR#{tag}") { logger.error(line.strip) }
|
28
|
+
else
|
29
|
+
output += line
|
30
|
+
logger.tagged("OUT#{tag}") { logger.info(line.strip) } unless capture
|
31
|
+
end
|
32
|
+
rescue EOFError => e
|
33
|
+
files.delete f
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
thr.value
|
39
|
+
end
|
40
|
+
|
41
|
+
raise "Execution failed #{code}: #{cmd}" unless code.success?
|
42
|
+
|
43
|
+
output
|
44
|
+
end
|
45
|
+
|
46
|
+
def dockerauth(hostname)
|
47
|
+
json = ENV['DOCKER_AUTH_CONFIG'].presence || File.read(File.expand_path('~/.docker/config.json'))
|
48
|
+
auth = JSON.parse(json).dig('auths', hostname, 'auth')
|
49
|
+
|
50
|
+
Base64.decode64(auth) if auth
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
data/lib/retag.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require_relative 'retag/version'
|
5
|
+
require_relative 'retag/logger'
|
6
|
+
require_relative 'retag/utils'
|
7
|
+
require_relative 'retag/image'
|
8
|
+
require_relative 'retag/service'
|
9
|
+
|
10
|
+
module Retag
|
11
|
+
class Error < StandardError; end
|
12
|
+
end
|
13
|
+
|
metadata
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: retag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.73710
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samoilenko Yuri
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.2.1
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.2.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec_junit_formatter
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rubocop
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: simplecov
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: simplecov-console
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: webmock
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: activesupport
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '6.0'
|
138
|
+
type: :runtime
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '6.0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: json
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :runtime
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: thor
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: uri
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
type: :runtime
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
- !ruby/object:Gem::Dependency
|
188
|
+
name: yaml
|
189
|
+
requirement: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
type: :runtime
|
195
|
+
prerelease: false
|
196
|
+
version_requirements: !ruby/object:Gem::Requirement
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: '0'
|
201
|
+
description: Retag is cli to manipulate docker images in handy way
|
202
|
+
email:
|
203
|
+
- kinnalru@gmail.com
|
204
|
+
executables: []
|
205
|
+
extensions: []
|
206
|
+
extra_rdoc_files: []
|
207
|
+
files:
|
208
|
+
- LICENSE
|
209
|
+
- README.md
|
210
|
+
- lib/retag.rb
|
211
|
+
- lib/retag/image.rb
|
212
|
+
- lib/retag/logger.rb
|
213
|
+
- lib/retag/service.rb
|
214
|
+
- lib/retag/utils.rb
|
215
|
+
- lib/retag/version.rb
|
216
|
+
homepage: https://github.com/RnD-Soft/retag
|
217
|
+
licenses:
|
218
|
+
- MIT
|
219
|
+
metadata:
|
220
|
+
homepage_uri: https://github.com/RnD-Soft/retag
|
221
|
+
source_code_uri: https://github.com/RnD-Soft/retag
|
222
|
+
post_install_message:
|
223
|
+
rdoc_options: []
|
224
|
+
require_paths:
|
225
|
+
- lib
|
226
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: 2.5.0
|
231
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - ">="
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: '0'
|
236
|
+
requirements: []
|
237
|
+
rubygems_version: 3.0.3
|
238
|
+
signing_key:
|
239
|
+
specification_version: 4
|
240
|
+
summary: Retag is cli to manipulate docker images in handy way
|
241
|
+
test_files: []
|