dapp 0.6.15 → 0.6.16

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: 3f0884efd0541d21fd325805dc5ba6d7535f201a
4
- data.tar.gz: 914ac50dbc5187261ecd478dbdb482341fd8af67
3
+ metadata.gz: 876026d4b44e0e133226070491379a862830e00e
4
+ data.tar.gz: e2b22a947be59dcef0b43f76f1d603172b51d95a
5
5
  SHA512:
6
- metadata.gz: 3c651d89a94ba32ffbf960ff8e71b9642148e9b6c848e843ebc29772c1ef7b90207d1ad083ad0c184952ce6f054ac2e02dd4508f3ee847a9ca682b508bad2231
7
- data.tar.gz: 20089b576bb1130822602048a2ab5d763f7e58ed2059db135b2fbae6f6245269f034e0671469402358d50129e2f8524b7d3149975eb21f477eea8dcb879f9e2c
6
+ metadata.gz: 53ddd82966ead8876733adcef218708576845ee385d80e0f4aae84ee6a80822bc72317a1193b2260bdeb94133118164ee8e22d0c2f5bf83029e5598750512872
7
+ data.tar.gz: 297cf30895ee5f6e9cfaf542cc3b583f07e8f92490763b7962e2fc796f4aba2ebcf3b3257971d72c17dea797058e84cd22c251d03793850ab30bd747d3eb7aef
@@ -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
  excess_builder_instruction: "WARNING: Excessive use of the 'builder' instruction. Builder type will be automatically determined by the first use of any builder."
45
47
  excess_name_instruction: "WARNING: Excessive use of the 'name' instruction. Given name corresponds to default name."
@@ -19,6 +19,9 @@ en:
19
19
  from_image_not_found: 'Image `%{name}` not found!'
20
20
  project:
21
21
  spush_command_unexpected_apps_number: "Command 'spush' can process only one application!"
22
+ tag_command_unexpected_apps_number: "Command 'tag' can process only one application!"
23
+ tag_command_incorrect_tag: "Incorrect tag ('%{name}') given!"
24
+ repo_name_incorrect: "Incorrect repo ('%{name}') given!"
22
25
  command_unexpected_apps_number: "Command can process only one application!"
23
26
  no_such_app: "No such app: '%{apps_patterns}'!"
24
27
  dappfile_not_found: "Dappfile not found!"
@@ -39,6 +42,7 @@ en:
39
42
  stage_artifact_not_supported_associated_stage: "Artifact not supported associated stage '%{stage}'!"
40
43
  git_artifact_unexpected_attribute: "'%{type}' git artifact doesn't has attribute '%{attr}'!"
41
44
  docker_from_incorrect: "`docker.from` has incorrect value `%{name}`: expected format `image_name:tag`!"
45
+ docker_from_without_tag: "`docker.from` has incorrect value `%{name}`: expected format `image_name:tag`!"
42
46
  app_name_incorrect: "Application has incorrect name '%{name}': doesn't match regex '%{reg}'!"
43
47
  chef:
44
48
  stage_path_overlap: "Cannot install '%{cookbook}' cookbook's path %{from} into %{to}: already exists"
@@ -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'
@@ -119,6 +120,7 @@ require 'dapp/project/command/list'
119
120
  require 'dapp/project/command/push'
120
121
  require 'dapp/project/command/run'
121
122
  require 'dapp/project/command/spush'
123
+ require 'dapp/project/command/tag'
122
124
  require 'dapp/project/command/stages/common'
123
125
  require 'dapp/project/command/stages/cleanup_local'
124
126
  require 'dapp/project/command/stages/cleanup_repo'
@@ -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
+ applicaion_name = config._name
45
+ if project.dry_run?
46
+ project.log_state(applicaion_name, state: project.t(code: 'state.tag'), styles: { status: :success })
47
+ else
48
+ project.log_process(applicaion_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("#{config._basename}.images", readonly: true) do
44
57
  tags.each do |tag|
@@ -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
@@ -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 application.project.dry_run?
63
+ image.save_in_cache! unless application.project.dry_run?
64
64
  end
65
65
 
66
66
  def image
@@ -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] [APPS PATTERN ...]
16
16
  dapp bp [options] [APPS PATTERN ...] REPO
17
17
  dapp push [options] [APP PATTERN] REPO
18
18
  dapp spush [options] [APPS PATTERN ...] REPO
19
+ dapp tag [options] [APP PATTERN ...] TAG
19
20
  dapp list [options] [APPS PATTERN ...]
20
21
  dapp run [options] [APP PATTERN] [DOCKER ARGS]
21
22
  dapp cleanup [options] [APPS 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] [APP PATTERN ...] TAG
10
+
11
+ APP PATTERN Application 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, apps_patterns: cli_arguments).public_send(class_to_lowercase, tag)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -18,7 +18,9 @@ module Dapp
18
18
  end
19
19
 
20
20
  def from(image, cache_version: nil)
21
- raise(Error::Config, code: :docker_from_incorrect, data: { name: image }) unless image =~ /^[[^ ].]+:[[^ ].]+$/
21
+ image = image.to_s
22
+ raise(Error::Config, code: :docker_from_incorrect, data: { name: image }) unless image =~ Image::Docker.image_regex
23
+ raise(Error::Config, code: :docker_from_without_tag, data: { name: image }) unless image.include?(':')
22
24
  @_from = image
23
25
  @_from_cache_version = cache_version
24
26
  end
@@ -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
@@ -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
@@ -63,6 +63,10 @@ module Dapp
63
63
  basename
64
64
  end
65
65
 
66
+ def validate_repo_name(repo)
67
+ raise(Error::Project, code: :repo_name_incorrect, data: { name: repo }) unless repo =~ DockerRegistry.repo_regex
68
+ end
69
+
66
70
  def proper_cache_version?
67
71
  !!cli_options[:proper_cache_version]
68
72
  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_step_with_indent(config._name) 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_apps_number unless build_configs.one?
10
11
  Application.new(config: build_configs.first, project: self, ignore_git_fetch: true, should_be_built: true).tap do |app|
11
12
  app.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_step_with_indent(config._name) do
12
13
  Application.new(config: config, project: self, ignore_git_fetch: true).tap do |app|
@@ -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_step_with_indent(config._name) do
12
13
  Application.new(config: config, project: self, ignore_git_fetch: true, should_be_built: true).tap do |app|
@@ -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_apps_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
@@ -1,5 +1,5 @@
1
1
  # Version
2
2
  module Dapp
3
- VERSION = '0.6.15'.freeze
3
+ VERSION = '0.6.16'.freeze
4
4
  BUILD_CACHE_VERSION = 5
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.6.15
4
+ version: 0.6.16
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
@@ -408,6 +408,7 @@ files:
408
408
  - lib/dapp/cli/stages/flush_repo.rb
409
409
  - lib/dapp/cli/stages/pull.rb
410
410
  - lib/dapp/cli/stages/push.rb
411
+ - lib/dapp/cli/tag.rb
411
412
  - lib/dapp/config/application.rb
412
413
  - lib/dapp/config/artifact.rb
413
414
  - lib/dapp/config/directive/artifact.rb
@@ -473,6 +474,7 @@ files:
473
474
  - lib/dapp/project/command/stages/flush_repo.rb
474
475
  - lib/dapp/project/command/stages/pull.rb
475
476
  - lib/dapp/project/command/stages/push.rb
477
+ - lib/dapp/project/command/tag.rb
476
478
  - lib/dapp/project/dappfile.rb
477
479
  - lib/dapp/project/deps/base.rb
478
480
  - lib/dapp/project/deps/gitartifact.rb