dapp 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d611af62545ae4ad1322d6534e2ecb72f8e9ff5
4
- data.tar.gz: 2df141836542876fb905510294f9ccdc1349f5c0
3
+ metadata.gz: 272df4bf11a8835a28a24c7c07d6267b1621ed69
4
+ data.tar.gz: 8b938f63edb0d4c2ccceffc8e901ab23432ad46f
5
5
  SHA512:
6
- metadata.gz: 268e5c5c069fb04af95505e33c835cc7c305a55756944444ee5964b34407e1a5b05b8c4bff0e3d7f3f0bca8d26e70ddba99e995e659935a740074d38adcd76d6
7
- data.tar.gz: 406cadcaa4493ed0b6654651281ee0a31b71a9281bfb061239fc8731805cbf0e8ada7a99008e4026b827dc9a3e3523b307c84cf8197930ca2a3b929f75546a50
6
+ metadata.gz: 263b8f2dae547e2d70b6bae8b3ae4977f030df3436208237e5b2eb55814d2795d021b73606ad5e7696827173930eb5fcd1fdc4e03efc4623baa4f513331c1c9b
7
+ data.tar.gz: 1f24ef716042766765497256794bafd8b3d99f17d546852bce63e430ac84cbba1e78e18fc04269c4a48590e28e6278e8bbbd6b0938923c05b7209b0d1732d2d3
data/config/en/common.yml CHANGED
@@ -28,6 +28,7 @@ en:
28
28
  pulling: '[PULLING]'
29
29
  building: '[BUILDING]'
30
30
  default: '[RUNNING]'
31
+ tagging: '[TAGGING]'
31
32
  success:
32
33
  default: '[OK]'
33
34
  failed:
@@ -40,6 +41,7 @@ en:
40
41
  empty: '[EMPTY]'
41
42
  push: '[PUSH]'
42
43
  pull: '[PULL]'
44
+ tag: '[TAG]'
43
45
  warning:
44
46
  wrong_using_base_directive: "WARNING: Directive '%{directive}' has declared after dimg_group|dimg|artifact!"
45
47
  wrong_using_directive: "WARNING: Directive '%{directive}' has declared after dimg_group|dimg!"
@@ -21,6 +21,9 @@ en:
21
21
  spush_command_unexpected_dimgs_number: "Command 'spush' can process only one dimg!"
22
22
  command_unexpected_dimgs_number: "Command can process only one dimg!"
23
23
  no_such_dimg: "No such dimg: '%{dimgs_patterns}'!"
24
+ tag_command_unexpected_dimgs_number: "Command 'tag' can process only one dimg!"
25
+ tag_command_incorrect_tag: "Incorrect tag ('%{name}') given!"
26
+ repo_name_incorrect: "Incorrect repo ('%{name}') given!"
24
27
  dappfile_not_found: "Dappfile not found!"
25
28
  cannot_run_ssh_agent: "Cannot run ssh-agent"
26
29
  ssh_key_not_found: "Ssh key '%{path}' not exist!"
data/lib/dapp.rb CHANGED
@@ -42,6 +42,7 @@ require 'dapp/cli/base'
42
42
  require 'dapp/cli/build'
43
43
  require 'dapp/cli/push'
44
44
  require 'dapp/cli/spush'
45
+ require 'dapp/cli/tag'
45
46
  require 'dapp/cli/list'
46
47
  require 'dapp/cli/stages'
47
48
  require 'dapp/cli/stages/flush_local'
@@ -129,6 +130,7 @@ require 'dapp/project/command/list'
129
130
  require 'dapp/project/command/push'
130
131
  require 'dapp/project/command/run'
131
132
  require 'dapp/project/command/spush'
133
+ require 'dapp/project/command/tag'
132
134
  require 'dapp/project/command/stages/common'
133
135
  require 'dapp/project/command/stages/cleanup_local'
134
136
  require 'dapp/project/command/stages/cleanup_repo'
@@ -60,7 +60,7 @@ module Dapp
60
60
  def save_in_cache!
61
61
  prev_stage.save_in_cache! if prev_stage
62
62
  return unless should_be_tagged?
63
- image.tag! unless dimg.project.dry_run?
63
+ image.save_in_cache! unless dimg.project.dry_run?
64
64
  end
65
65
 
66
66
  def image
@@ -101,10 +101,10 @@ module Dapp
101
101
  end
102
102
 
103
103
  def image_add_default_volumes(type)
104
- (dimg.config.public_send("_#{type}_mount").map(&:to) +
104
+ (dimg.config.public_send("_#{type}_mount").map(&:_to) +
105
105
  from_image.labels.select { |l, _| l == "dapp-#{type}-dir" }.map { |_, value| value.split(';') }.flatten).each do |path|
106
106
  absolute_path = File.expand_path(File.join('/', path))
107
- tmp_path = dimg.send("#{type}_path", 'mount', absolute_path[1..-1]).tap(&:mkpath)
107
+ tmp_path = dimg.send(type, 'mount', absolute_path[1..-1]).tap(&:mkpath)
108
108
  image.add_volume "#{tmp_path}:#{absolute_path}"
109
109
  end
110
110
  end
data/lib/dapp/cli.rb CHANGED
@@ -5,7 +5,7 @@ module Dapp
5
5
  include Mixlib::CLI
6
6
  include Helper::Trivia
7
7
 
8
- SUBCOMMANDS = ['build', 'push', 'spush', 'list', 'run', 'stages', 'cleanup', 'bp', 'mrproper', 'stage image'].freeze
8
+ SUBCOMMANDS = ['build', 'push', 'spush', 'list', 'run', 'stages', 'cleanup', 'bp', 'mrproper', 'stage image', 'tag'].freeze
9
9
 
10
10
  banner <<BANNER.freeze
11
11
  Usage: dapp [options] sub-command [sub-command options]
@@ -16,6 +16,7 @@ dapp build [options] [DIMGS PATTERN ...]
16
16
  dapp bp [options] [DIMGS PATTERN ...] REPO
17
17
  dapp push [options] [DIMGS PATTERN] REPO
18
18
  dapp spush [options] [DIMG PATTERN ...] REPO
19
+ dapp tag [options] [DIMG PATTERN ...] TAG
19
20
  dapp list [options] [DIMGS PATTERN ...]
20
21
  dapp run [options] [DIMG PATTERN] [DOCKER ARGS]
21
22
  dapp cleanup [options] [DIMGS PATTERN ...]
@@ -0,0 +1,24 @@
1
+ module Dapp
2
+ class CLI
3
+ # CLI tag subcommand
4
+ class Tag < Base
5
+ banner <<BANNER.freeze
6
+ Version: #{Dapp::VERSION}
7
+
8
+ Usage:
9
+ dapp tag [options] [DIMG PATTERN ...] TAG
10
+
11
+ DIMG PATTERN Dapp image to process [default: *].
12
+ REPO Pushed image name.
13
+
14
+ Options:
15
+ BANNER
16
+
17
+ def run(argv = ARGV)
18
+ self.class.parse_options(self, argv)
19
+ tag = self.class.required_argument(self)
20
+ Project.new(cli_options: config, dimgs_patterns: cli_arguments).public_send(class_to_lowercase, tag)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -7,7 +7,9 @@ module Dapp
7
7
  attr_reader :_from, :_from_cache_version
8
8
 
9
9
  def from(image, cache_version: nil)
10
- raise(Error::Config, code: :docker_from_incorrect, data: { name: image }) unless image =~ /^[[^ ].]+:[[^ ].]+$/
10
+ image = image.to_s
11
+ raise(Error::Config, code: :docker_from_incorrect, data: { name: image }) unless image =~ Image::Docker.image_regex
12
+ raise(Error::Config, code: :docker_from_without_tag, data: { name: image }) unless image.include?(':')
11
13
  @_from = image
12
14
  @_from_cache_version = cache_version
13
15
  end
data/lib/dapp/dimg.rb CHANGED
@@ -39,6 +39,19 @@ module Dapp
39
39
  FileUtils.rm_rf(tmp_path)
40
40
  end
41
41
 
42
+ def tag!(tag)
43
+ project.lock("#{config._basename}.images", readonly: true) do
44
+ dimg_name = config._name
45
+ if project.dry_run?
46
+ project.log_state(dimg_name, state: project.t(code: 'state.tag'), styles: { status: :success })
47
+ else
48
+ project.log_process(dimg_name, process: project.t(code: 'status.process.tagging')) do
49
+ last_stage.image.tag!(tag)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
42
55
  def export!(repo, format:)
43
56
  project.lock("#{project.name}.images", readonly: true) do
44
57
  tags.each do |tag|
@@ -28,6 +28,9 @@ module Dapp
28
28
  container_dapp_path('tmp', *path)
29
29
  end
30
30
 
31
+ alias_method :build_dir, :build_path
32
+ alias_method :tmp_dir, :tmp_path
33
+
31
34
  private
32
35
 
33
36
  def make_path(base, *path)
@@ -17,14 +17,14 @@ module Dapp
17
17
 
18
18
  def images
19
19
  (@images ||= []).tap do |images|
20
- stages.map do |stage|
20
+ stages.each do |stage|
21
21
  if stage.respond_to?(:images)
22
22
  images.concat(stage.images)
23
23
  else
24
24
  images << stage.image
25
25
  end
26
- end.uniq(&:name)
27
- end
26
+ end
27
+ end.uniq!(&:name)
28
28
  end
29
29
 
30
30
  protected
@@ -3,8 +3,8 @@ module Dapp
3
3
  module DockerRegistry
4
4
  def self.new(repo)
5
5
  repo_regex =~ repo
6
- expected_hostname = Regexp.last_match(1)
7
- expected_repo_suffix = Regexp.last_match(2)
6
+ expected_hostname = Regexp.last_match(:hostname)
7
+ expected_repo_suffix = Regexp.last_match(:repo_suffix)
8
8
  expected_hostname_url = expected_hostname ? "http://#{expected_hostname}" : nil
9
9
 
10
10
  if hostname_exist?(expected_hostname_url)
@@ -15,13 +15,13 @@ module Dapp
15
15
  end
16
16
 
17
17
  def self.repo_regex
18
- separator = /[_.]|__|[-]*/
19
- alpha_numeric = /[[:alnum:]]*/
20
- component = /#{alpha_numeric}[#{separator}#{alpha_numeric}]*/
21
- port_number = /[0-9]+/
22
- hostcomponent = /[[:alnum:]-]*[[:alnum:]]/
23
- hostname = /#{hostcomponent}[\.#{hostcomponent}]*[:#{port_number}]?/
24
- %r{^(#{hostname}/)?(#{component}[/#{component}]*)$}
18
+ separator = '[_.]|__|[-]*'
19
+ alpha_numeric = '[[:alnum:]]*'
20
+ component = "#{alpha_numeric}[#{separator}#{alpha_numeric}]*"
21
+ port_number = '[[:digit:]]+'
22
+ hostcomponent = '[[:alnum:]-]*[[:alnum:]]'
23
+ hostname = "#{hostcomponent}[\.#{hostcomponent}]*(?<port>:#{port_number})?"
24
+ %r{^(?<hostname>#{hostname}/)?(?<repo_suffix>#{component}[/#{component}]*)$}
25
25
  end
26
26
 
27
27
  def self.hostname_exist?(url)
@@ -68,6 +68,15 @@ module Dapp
68
68
  end
69
69
 
70
70
  class << self
71
+ def image_regex
72
+ /^[a-z0-9]+(?:[._-][a-z0-9]+)*(:[\w][\w.-]{0,127})?$/
73
+ end
74
+
75
+ def tag!(id:, tag:)
76
+ Project.shellout!("docker tag #{id} #{tag}")
77
+ cache_reset
78
+ end
79
+
71
80
  def cache
72
81
  @cache ||= (@cache = {}).tap { cache_reset }
73
82
  end
@@ -33,24 +33,30 @@ module Dapp
33
33
  end
34
34
 
35
35
  def export!(name)
36
- image = self.class.new(name: name, project: project, built_id: built_id)
37
- image.tag!
38
- image.push!
39
- image.untag!
36
+ tag!(name).tap do |image|
37
+ image.push!
38
+ image.untag!
39
+ end
40
+ end
41
+
42
+ def tag!(name)
43
+ clone!(name).tap do |image|
44
+ self.class.tag!(id: image.built_id, tag: image.name)
45
+ end
40
46
  end
41
47
 
42
48
  def import!(name)
43
- image = self.class.new(name: name, project: project)
44
- image.pull!
45
- @built_id = image.built_id
46
- tag!
47
- image.untag!
49
+ clone!(name).tap do |image|
50
+ image.pull!
51
+ @built_id = image.built_id
52
+ save_in_cache!
53
+ image.untag!
54
+ end
48
55
  end
49
56
 
50
- def tag!
57
+ def save_in_cache!
51
58
  project.log_warning(desc: { code: :another_image_already_tagged }) if !(existed_id = id).nil? && built_id != existed_id
52
- project.shellout!("docker tag #{built_id} #{name}")
53
- cache_reset
59
+ self.class.tag!(id: built_id, tag: name)
54
60
  end
55
61
 
56
62
  def labels
@@ -77,6 +83,10 @@ module Dapp
77
83
  def commit!
78
84
  project.shellout!("docker commit #{prepared_change} #{container_name}").stdout.strip
79
85
  end
86
+
87
+ def clone!(name)
88
+ self.class.new(name: name, project: project, built_id: built_id)
89
+ end
80
90
  end # Stage
81
91
  end # Image
82
92
  end # Dapp
data/lib/dapp/project.rb CHANGED
@@ -10,6 +10,7 @@ module Dapp
10
10
  include Command::Bp
11
11
  include Command::Push
12
12
  include Command::Spush
13
+ include Command::Tag
13
14
  include Command::List
14
15
  include Command::Stages::CleanupLocal
15
16
  include Command::Stages::CleanupRepo
@@ -55,6 +55,10 @@ module Dapp
55
55
  name
56
56
  end
57
57
 
58
+ def validate_repo_name(repo)
59
+ raise(Error::Project, code: :repo_name_incorrect, data: { name: repo }) unless repo =~ DockerRegistry.repo_regex
60
+ end
61
+
58
62
  def proper_cache_version?
59
63
  !!cli_options[:proper_cache_version]
60
64
  end
@@ -6,6 +6,7 @@ module Dapp
6
6
  # Push
7
7
  module Push
8
8
  def push(repo)
9
+ validate_repo_name(repo)
9
10
  log_step_with_indent(:stages) { stages_push(repo) } if with_stages?
10
11
  build_configs.each do |config|
11
12
  log_dimg_name_with_indent(config) do
@@ -6,6 +6,7 @@ module Dapp
6
6
  # Spush
7
7
  module Spush
8
8
  def spush(repo)
9
+ validate_repo_name(repo)
9
10
  raise Error::Project, code: :spush_command_unexpected_dimgs_number unless build_configs.one?
10
11
  Dimg.new(config: build_configs.first, project: self, ignore_git_fetch: true, should_be_built: true).tap do |dimg|
11
12
  dimg.export!(repo, format: '%{repo}:%{tag}')
@@ -9,6 +9,7 @@ module Dapp
9
9
  protected
10
10
 
11
11
  def registry(repo)
12
+ validate_repo_name(repo)
12
13
  DockerRegistry.new(repo)
13
14
  end
14
15
 
@@ -7,6 +7,7 @@ module Dapp
7
7
  # Pull
8
8
  module Pull
9
9
  def stages_pull(repo)
10
+ validate_repo_name(repo)
10
11
  build_configs.each do |config|
11
12
  log_dimg_name_with_indent(config) do
12
13
  Dimg.new(config: config, project: self, ignore_git_fetch: true).tap do |dimg|
@@ -7,6 +7,7 @@ module Dapp
7
7
  # Push
8
8
  module Push
9
9
  def stages_push(repo)
10
+ validate_repo_name(repo)
10
11
  build_configs.each do |config|
11
12
  log_dimg_name_with_indent(config) do
12
13
  Dimg.new(config: config, project: self, ignore_git_fetch: true, should_be_built: true).tap do |dimg|
@@ -0,0 +1,18 @@
1
+ module Dapp
2
+ # Project
3
+ class Project
4
+ # Command
5
+ module Command
6
+ # Tag
7
+ module Tag
8
+ def tag(tag)
9
+ raise Error::Project, code: :tag_command_unexpected_dimgs_number unless build_configs.one?
10
+ raise Error::Project, code: :tag_command_incorrect_tag, data: { name: tag } unless tag =~ Image::Docker.image_regex
11
+ Application.new(config: build_configs.first, project: self, ignore_git_fetch: true, should_be_built: true).tap do |app|
12
+ app.tag!(tag)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end # Project
18
+ end # Dapp
@@ -48,7 +48,7 @@ module Dapp
48
48
  # rubocop:enable Metrics/ParameterLists
49
49
 
50
50
  def log_secondary_process(message, **kwargs, &blk)
51
- log_process(message, **kwargs.merge(style: { message: :secondary, success: :secondary }), &blk)
51
+ log_process(message, **kwargs.merge(style: { message: :secondary, success: :secondary }, quiet: !log_verbose?), &blk)
52
52
  end
53
53
 
54
54
  protected
data/lib/dapp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # Version
2
2
  module Dapp
3
- VERSION = '0.7.2'.freeze
3
+ VERSION = '0.7.3'.freeze
4
4
  BUILD_CACHE_VERSION = 6
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-11 00:00:00.000000000 Z
11
+ date: 2016-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -404,6 +404,7 @@ files:
404
404
  - lib/dapp/cli/stages/flush_repo.rb
405
405
  - lib/dapp/cli/stages/pull.rb
406
406
  - lib/dapp/cli/stages/push.rb
407
+ - lib/dapp/cli/tag.rb
407
408
  - lib/dapp/config/artifact_dimg.rb
408
409
  - lib/dapp/config/artifact_group.rb
409
410
  - lib/dapp/config/base.rb
@@ -483,6 +484,7 @@ files:
483
484
  - lib/dapp/project/command/stages/flush_repo.rb
484
485
  - lib/dapp/project/command/stages/pull.rb
485
486
  - lib/dapp/project/command/stages/push.rb
487
+ - lib/dapp/project/command/tag.rb
486
488
  - lib/dapp/project/dappfile.rb
487
489
  - lib/dapp/project/deps/base.rb
488
490
  - lib/dapp/project/deps/gitartifact.rb