retag 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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2df15980e560df6495c0565d3b2eef9ea085c34ff1756dc53861e058c31833f
4
- data.tar.gz: 0db02684208f5b8e4b97a6230495025a9033d7b8dfc2ecb3df4294c03b79eec6
3
+ metadata.gz: ab2e731e32312b3a61a674ad910c1193b77130f6b7f72a93ec0675580bd5b078
4
+ data.tar.gz: 97835c0e4826a38949abd6de5882652705594eba0c24b501c8cec96a23f44151
5
5
  SHA512:
6
- metadata.gz: 1d71f1915637a2ca9b256094d49f615cc4f54413338467f82589853f172a4fb41992eb58db19b7bea0ae45743438c0ca80d3409994b2d1450e18ea30473ad762
7
- data.tar.gz: 87ad3d50a71c22574565437d3192333bfe47a006ecdc1d8f26d86f3eba1a5e2a884bf7699176b82f528bd91c07761f629169bd87067619f6e3b373514a061520
6
+ metadata.gz: d8bcbd2c1f5d286e9729b93179c6b03905533d2d71a06b07b361a55994a69ad9ccd981c94a37ea925f69caceb390591eee716cd4656a359c9a47e13a911d844c
7
+ data.tar.gz: 0352ce3e3aab8140a8e65cde805f5ca7846238a9725178a5c42dada297f90ca3c45bdcdc7a143c3ee34b8ce71204cdaaf7b455b29d8a1175fafc8da6b1cfef56
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retag (0.1.3)
4
+ retag (0.1.4)
5
5
  activesupport (~> 6.0)
6
6
  colorize
7
7
  gitlab
data/bin/retag CHANGED
@@ -10,36 +10,51 @@ ENV_PREFIX = 'RETAG'
10
10
  $logger = ActiveSupport::TaggedLogging.new(Retag::Logger.new(STDOUT))
11
11
  $logger.level = :info
12
12
 
13
- class Cli < Thor
14
13
 
15
- def self.exit_on_failure?
16
- true
17
- end
18
-
19
- package_name "Retag is cli to manipulate docker images in handy way.
20
14
 
21
- # Gitlab authorization
22
- Using GITLAB_API_ENDPOINT and GITLAB_API_PRIVATE_TOKEN environment variable used for authorization
15
+ class RepoCommand < Thor
16
+ desc "tag <project> <tag>", "Create tag in Gitlab project"
17
+ long_desc <<-LONGDESC
18
+ LONGDESC
19
+ option :force, default: false,
20
+ required: false,
21
+ type: :boolean,
22
+ desc: "Override Gitlab tag if exists"
23
23
 
24
- #{File.basename(__FILE__)}"
24
+ option :ref, default: ENV.fetch("#{ENV_PREFIX}_TAG_REF", 'master'),
25
+ required: true,
26
+ type: :string,
27
+ desc: "Gtilab refspec from which create tag"
25
28
 
26
- desc 'version', 'Display version'
27
- map %w[-v --version] => :version
29
+ option :message, default: nil,
30
+ type: :string,
31
+ desc: "Tag message"
28
32
 
29
- def version
30
- say Retag::VERSION
31
- end
33
+ def tag(project, tag)
34
+ $logger.level = :debug if opts['verbose']
35
+ opts = options.to_h.dup
32
36
 
33
- desc 'tag', "Tag Docker image without downloading"
34
- map %w[--tag] => :tag
37
+ begin
38
+ Gitlab.client.delete_tag(project, tag).inspect
39
+ rescue Gitlab::Error::NotFound
40
+ # Success: there is no such tag
41
+ end if opts['force']
42
+
43
+ puts Gitlab.client.create_tag(project, tag, options['ref'], options['message']).inspect
44
+ end
45
+ end
35
46
 
47
+ class DockerCommand < Thor
48
+ desc "tag", "Tag Docker image without downloading"
49
+ long_desc <<-LONGDESC
50
+ LONGDESC
36
51
  option :image, default: ENV.fetch("#{ENV_PREFIX}_TAG_IMAGE", nil),
37
52
  required: true,
38
53
  desc: "Env: #{ENV_PREFIX}_TAG_IMAGE. Full image to be tagged. Ex: docker.rnds.pro/aggredator/service-uprid3:latest"
39
54
 
40
55
  option :tag, default: ENV.fetch("#{ENV_PREFIX}_TAG_TAG", nil),
41
56
  required: true,
42
- desc: "Env: #{ENV_PREFIX}_TAG_TAG. New tag."
57
+ desc: "Env: #{ENV_PREFIX}_TAG_TAG. New tag"
43
58
 
44
59
  option :suffix, default: ENV.fetch("#{ENV_PREFIX}_TAG_SUFFIX", nil),
45
60
  required: false,
@@ -50,7 +65,9 @@ class Cli < Thor
50
65
  "
51
66
 
52
67
  def tag(*_args)
68
+ $logger.level = :debug if opts['verbose']
53
69
  opts = options.to_h.dup
70
+
54
71
  img, tag = opts['image'].split(':')
55
72
  tag ||= 'latest'
56
73
  tag = opts['suffix'].present? ? "#{tag}-#{opts['suffix']}" : tag
@@ -59,10 +76,14 @@ class Cli < Thor
59
76
  image.retag!(opts['tag'])
60
77
  end
61
78
 
79
+ end
62
80
 
63
- desc 'release', 'Release projects bundler from release.yml manifest'
64
- map %w[--release] => :release
81
+ class ReleaseCommand < Thor
82
+ default_command :release
65
83
 
84
+ desc "release", "Release projects bundler from release.yml manifest"
85
+ long_desc <<-LONGDESC
86
+ LONGDESC
66
87
  option :config, default: ENV.fetch("#{ENV_PREFIX}_RELEASE_CONFIG", './release.yml'),
67
88
  required: true,
68
89
  desc: "Env: #{ENV_PREFIX}_RELEASE_CONFIG. Path to release manifest"
@@ -73,14 +94,17 @@ class Cli < Thor
73
94
 
74
95
  def release(*_args)
75
96
  opts = options.to_h.dup
97
+ $logger.level = :debug if opts['verbose']
98
+
76
99
  config = YAML.load_file(File.expand_path(opts['config']))
77
100
  config['release'] = opts['name'] || config['release']
78
101
 
79
102
  release = config['release'].to_s
80
103
  suffix = config['suffix']
104
+ branch = config['branch']
81
105
 
82
106
  services = config['services'].map do|(name, cfg)|
83
- Retag::Service.new(name, cfg, release, suffix: cfg.fetch('suffix', suffix)) unless name.start_with?('.')
107
+ Retag::Service.new(name, cfg, release, suffix: cfg.fetch('suffix', suffix), branch: cfg.fetch('branch', branch)) unless name.start_with?('.')
84
108
  end.compact
85
109
 
86
110
  tag_message = "Release #{release} at #{DateTime.now.iso8601}"
@@ -120,4 +144,37 @@ class Cli < Thor
120
144
 
121
145
  end
122
146
 
147
+
148
+ class Cli < Thor
149
+
150
+ def self.exit_on_failure?
151
+ true
152
+ end
153
+
154
+ package_name "Retag is cli to manipulate docker images in handy way.
155
+
156
+ # Gitlab authorization
157
+ Using GITLAB_API_ENDPOINT and GITLAB_API_PRIVATE_TOKEN environment variable used for authorization
158
+
159
+ #{File.basename(__FILE__)}"
160
+
161
+ class_option :verbose, type: :boolean
162
+
163
+ desc 'version', 'Display version'
164
+ map %w[-v --version] => :version
165
+
166
+ def version
167
+ say Retag::VERSION
168
+ end
169
+
170
+ desc "repo SUBCOMMAND ...ARGS", "Manage git repository stuffs"
171
+ subcommand "repo", RepoCommand
172
+
173
+ desc "docker SUBCOMMAND ...ARGS", "Manage docker stuffs"
174
+ subcommand "docker", DockerCommand
175
+
176
+ desc "release SUBCOMMAND ...ARGS", "Manage releases"
177
+ subcommand "release", ReleaseCommand
178
+ end
179
+
123
180
  ::Cli.start
data/lib/retag/repo.rb CHANGED
@@ -31,7 +31,9 @@ module Retag
31
31
 
32
32
  def revision
33
33
  @revision ||= begin
34
- rev, _name = cmd!("git ls-remote #{repo} #{branch}", capture: true).split("\n").select{|line| line["heads/#{branch}"] }.first.split
34
+ rev_name_pair = cmd!("git ls-remote #{repo} #{branch}", capture: true).split("\n").select{|line| line[/\/#{branch}$/] }.first
35
+ raise "There is no #{branch} revision at #{repo}" if rev_name_pair.nil?
36
+ rev, _name = rev_name_pair.split
35
37
  rev[0..7]
36
38
  end
37
39
  end
@@ -39,29 +41,3 @@ module Retag
39
41
  end
40
42
  end
41
43
 
42
-
43
-
44
-
45
- # ==> /var/log/gitlab/gitlab-rails/api_json.log <==
46
- # {"time":"2022-01-21T10:48:07.308Z","severity":"INFO",
47
- # "duration_s":0.20214,"db_duration_s":0.00607,"view_duration_s":0.19607,"status":201,
48
- # "method":"POST","path":"/api/v4/projects/aggredator%2Fservices%2Fuprid3/repository/tags",
49
- # "params":[{"key":"tag_name","value":"testtag3"},{"key":"ref","value":"master"}],
50
- # "host":"br.rnds.pro","remote_ip":"213.138.65.74, 172.22.20.31, 213.138.65.74","ua":"curl/7.79.1",
51
- # "route":"/api/:version/projects/:id/repository/tags","user_id":38,"username":"bot",
52
- # "queue_duration_s":0.008366,"gitaly_calls":1,"gitaly_duration_s":0.16823,"redis_calls":6,
53
- # "redis_duration_s":0.004274,"redis_read_bytes":113,"redis_write_bytes":521,"redis_cache_calls":6,
54
- # "redis_cache_duration_s":0.004274,"redis_cache_read_bytes":113,"redis_cache_write_bytes":521,"db_count":10,
55
- # "db_write_count":0,"db_cached_count":0,"cpu_s":0.034309,"mem_objects":15111,"mem_bytes":920832,"mem_mallocs":3159,
56
- # "mem_total_bytes":1525272,"correlation_id":"01FSY40ANS3TD0CJJTDCQXGQ1N","meta.user":"bot","meta.project":"aggredator/services/uprid3",
57
- # "meta.root_namespace":"aggredator","meta.caller_id":"POST /api/:version/projects/:id/repository/tags",
58
- # "meta.remote_ip":"213.138.65.74","meta.feature_category":"source_code_management","meta.client_id":
59
- # "user/38","content_length":"0"}
60
-
61
- # ==> /var/log/gitlab/gitlab-rails/api_json.log <==
62
- # {"time":"2022-01-21T10:49:36.954Z","severity":"INFO",
63
- # "duration_s":0.01892,"db_duration_s":0.0036,"view_duration_s":0.01532,"status":400,
64
- # "method":"POST","path":"/api/v4/projects/aggredator%2Fservices%2Fuprid3/repository/tags",
65
- # "params":[{"key":"tag_name","value":"44444444"},{"key":"ref","value":"509a3719"},{"key":"message","value":{"message":"hello"}},{"key":"release_description","value":""}],"host":"br.rnds.pro","remote_ip":"213.138.65.74, 172.22.20.31, 213.138.65.74","ua":"Gitlab Ruby Gem 4.18.0","route":"/api/:version/projects/:id/repository/tags","user_id":38,"username":"bot","queue_duration_s":0.007279,"db_count":6,"db_write_count":0,"db_cached_count":0,"cpu_s":0.022143,"mem_objects":11483,"mem_bytes":783064,"mem_mallocs":2634,"mem_total_bytes":1242384,"correlation_id":"01FSY432CZMEFNDJQ88HMNW0E8","meta.user":"bot","meta.project":"aggredator/services/uprid3","meta.root_namespace":"aggredator","meta.caller_id":"POST /api/:version/projects/:id/repository/tags","meta.remote_ip":"213.138.65.74","meta.feature_category":"source_code_management","meta.client_id":"user/38","content_length":"78"}
66
-
67
-
data/lib/retag/service.rb CHANGED
@@ -9,10 +9,10 @@ module Retag
9
9
 
10
10
  delegate :revision, :branch, to: :repo
11
11
 
12
- def initialize(name, config, release, suffix: )
12
+ def initialize(name, config, release, branch:, suffix:)
13
13
  @name = name
14
14
  @config = config
15
- @repo = Retag::Repo.new(config['repo'], config.fetch('branch', 'master'))
15
+ @repo = Retag::Repo.new(config['repo'], branch)
16
16
  @release = release
17
17
  @suffix = suffix
18
18
  end
data/lib/retag/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Retag
4
4
 
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.4'
6
6
 
7
7
  end
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retag
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
  - Samoilenko Yuri