avm 0.0.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/docker/container.rb +50 -0
  3. data/lib/avm/docker/image.rb +71 -0
  4. data/lib/avm/docker/runner.rb +117 -0
  5. data/lib/avm/docker.rb +9 -0
  6. data/lib/avm/executables.rb +24 -0
  7. data/lib/avm/files/appendable/file_content.rb +24 -0
  8. data/lib/avm/files/appendable/plain_directory.rb +25 -0
  9. data/lib/avm/files/appendable/resource_base.rb +13 -0
  10. data/lib/avm/files/appendable/tar_output_command.rb +26 -0
  11. data/lib/avm/files/appendable/templatized_directory.rb +29 -0
  12. data/lib/avm/files/appendable.rb +55 -0
  13. data/lib/avm/files/appender.rb +11 -0
  14. data/lib/avm/files/deploy.rb +71 -0
  15. data/lib/avm/files/formatter/formats/base.rb +62 -0
  16. data/lib/avm/files/formatter/formats/generic_plain.rb +34 -0
  17. data/lib/avm/files/formatter/formats/html.rb +45 -0
  18. data/lib/avm/files/formatter/formats/javascript.rb +23 -0
  19. data/lib/avm/files/formatter/formats/json.rb +27 -0
  20. data/lib/avm/files/formatter/formats/php.rb +21 -0
  21. data/lib/avm/files/formatter/formats/python.rb +21 -0
  22. data/lib/avm/files/formatter/formats/ruby.rb +22 -0
  23. data/lib/avm/files/formatter/formats/xml.rb +27 -0
  24. data/lib/avm/files/formatter/formats.rb +13 -0
  25. data/lib/avm/files/formatter/utf8_assert.rb +72 -0
  26. data/lib/avm/files/formatter.rb +90 -0
  27. data/lib/avm/files/info.rb +24 -0
  28. data/lib/avm/files/rotate.rb +107 -0
  29. data/lib/avm/files.rb +9 -0
  30. data/lib/avm/git/auto_commit/commit_info.rb +23 -0
  31. data/lib/avm/git/auto_commit/rules/base.rb +39 -0
  32. data/lib/avm/git/auto_commit/rules/last.rb +19 -0
  33. data/lib/avm/git/auto_commit/rules/manual.rb +45 -0
  34. data/lib/avm/git/auto_commit/rules/new.rb +24 -0
  35. data/lib/avm/git/auto_commit/rules/nth.rb +31 -0
  36. data/lib/avm/git/auto_commit/rules/unique.rb +21 -0
  37. data/lib/avm/git/auto_commit/rules.rb +31 -0
  38. data/lib/avm/git/auto_commit_path/ruby.rb +20 -0
  39. data/lib/avm/git/auto_commit_path.rb +28 -0
  40. data/lib/avm/git/commit/class_methods.rb +31 -0
  41. data/lib/avm/git/commit/deploy.rb +38 -0
  42. data/lib/avm/git/commit/deploy_methods.rb +19 -0
  43. data/lib/avm/git/commit/diff_tree_line.rb +32 -0
  44. data/lib/avm/git/commit/file.rb +46 -0
  45. data/lib/avm/git/commit.rb +59 -0
  46. data/lib/avm/git/file_auto_fixup.rb +83 -0
  47. data/lib/avm/git/issue/complete/commits.rb +42 -0
  48. data/lib/avm/git/issue/complete/git_subrepos.rb +23 -0
  49. data/lib/avm/git/issue/complete/local_branch.rb +54 -0
  50. data/lib/avm/git/issue/complete/local_tag.rb +39 -0
  51. data/lib/avm/git/issue/complete/push.rb +54 -0
  52. data/lib/avm/git/issue/complete/remote.rb +33 -0
  53. data/lib/avm/git/issue/complete/test.rb +45 -0
  54. data/lib/avm/git/issue/complete/tracker.rb +28 -0
  55. data/lib/avm/git/issue/complete/validation.rb +31 -0
  56. data/lib/avm/git/issue/complete/validations.rb +53 -0
  57. data/lib/avm/git/issue/complete/working_tree.rb +19 -0
  58. data/lib/avm/git/issue/complete.rb +51 -0
  59. data/lib/avm/git/issue/deliver.rb +56 -0
  60. data/lib/avm/git/issue.rb +11 -0
  61. data/lib/avm/git/organize/reference_update.rb +34 -0
  62. data/lib/avm/git/organize/repository.rb +76 -0
  63. data/lib/avm/git/organize.rb +11 -0
  64. data/lib/avm/git/revision_test.rb +106 -0
  65. data/lib/avm/git/subrepo_check/parent.rb +51 -0
  66. data/lib/avm/git/subrepo_check/remote.rb +89 -0
  67. data/lib/avm/git/subrepo_check/show_result.rb +32 -0
  68. data/lib/avm/git/subrepo_check.rb +38 -0
  69. data/lib/avm/git/subrepo_checks.rb +59 -0
  70. data/lib/avm/git.rb +10 -0
  71. data/lib/avm/instances/docker_image.rb +15 -0
  72. data/lib/avm/result.rb +86 -0
  73. data/lib/avm/version.rb +1 -1
  74. data/lib/avm/version_number.rb +45 -0
  75. metadata +143 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdeb47dee18d0fbd23d5d424f89edbcde9903ef4c9502ae078a51897649f396f
4
- data.tar.gz: c7a7960a666cb29847623a4c63bcd4b90f941c64621ea103c665888e63e31b35
3
+ metadata.gz: 280fbe10e4f6675e6477b280f96ffb9bd5caf5df609ff08bec8cfe8600dada5a
4
+ data.tar.gz: a84ce459a88b027da9e777de1113a43d0606b5da74735e4201910cb8b24d492e
5
5
  SHA512:
6
- metadata.gz: c861922d12f002db6a91a29c058870be2c465d9215df378ba9f2cfe47e79c166756562c1ef60189ce9405e6600c6af68643dbd3d3363ac03d90204d93b87f039
7
- data.tar.gz: 6f1bb3ff1e35dd95721c802493f0695bc28d7ea313c8e856afb839b211298ba080b1d0e937c6cbc416ca2e989203eafce4cdbde5aaf9556d0c783e554a2e608b
6
+ metadata.gz: 1a331ef08d2d6323b65655c2dda06f43c6a2c28102c070ffa73c32b190b1bd257eddf1ff1ea5809c52d983fc4669e61dffd128a91345ac151948a6b79f5cafbe
7
+ data.tar.gz: a43e4b01aaa402821e241cdf1d95d184b165f9b4322bae204a99b627de28275e239c4ac45197b0c25e32d0903033461725cf57256cd7a7f79030ed48f28e1879
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/executables'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Docker
8
+ class Container
9
+ enable_speaker
10
+ common_constructor :instance
11
+
12
+ def remove
13
+ ::EacDocker::Executables.docker.command.append(
14
+ ['rm', '--force', instance.docker_container_name]
15
+ ).system!
16
+ end
17
+
18
+ def run(options = {})
19
+ infov 'Container name', instance.docker_container_name
20
+ infov 'Container exist?', instance.docker_container_exist?
21
+ remove if options[:clear] && instance.docker_container_exist?
22
+ if instance.docker_container_exist?
23
+ run_start
24
+ else
25
+ run_run(options)
26
+ end
27
+ end
28
+
29
+ def run_run(options)
30
+ infom "\"docker run #{instance.docker_container_name}...\""
31
+ ::EacDocker::Executables.docker.command.append(run_run_arguments(options)).system!
32
+ end
33
+
34
+ def run_start
35
+ infom "\"docker start #{instance.docker_container_name}...\""
36
+ ::EacDocker::Executables.docker.command.append(run_start_arguments).system!
37
+ end
38
+
39
+ def run_run_arguments(options)
40
+ entrypoint_args = options[:entrypoint_args].if_present([])
41
+ ['run', '-it', '--name', instance.docker_container_name] + instance.docker_run_arguments +
42
+ [instance.docker_image.tag] + entrypoint_args
43
+ end
44
+
45
+ def run_start_arguments
46
+ ['start', '-ai', instance.docker_container_name]
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/version'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_docker/images/templatized'
6
+
7
+ module Avm
8
+ module Docker
9
+ class Image < ::EacDocker::Images::Templatized
10
+ attr_reader :registry
11
+ attr_accessor :snapshot
12
+ attr_accessor :version
13
+
14
+ def initialize(registry)
15
+ @registry = registry
16
+ self.snapshot = true
17
+ self.version = true
18
+ end
19
+
20
+ def build(extra_args = [])
21
+ nyi "Extra args: #{extra_args}" if extra_args.any?
22
+
23
+ provide
24
+ end
25
+
26
+ def generator_version
27
+ ::Avm::VERSION
28
+ end
29
+
30
+ def push
31
+ ::EacDocker::Executables.docker.command.append(['push', tag]).system!
32
+ end
33
+
34
+ def read_entry(path, options = {})
35
+ method = path.gsub('.', '_')
36
+ return send(method) if respond_to?(path, true)
37
+ return instance.read_entry(path, options) if respond_to?(:instance)
38
+
39
+ raise "Method \"#{method}\" not found for entry \"#{path}\""
40
+ end
41
+
42
+ def run(instance)
43
+ run_run(instance) if container_exist?(instance)
44
+ end
45
+
46
+ def tag
47
+ r = tag_name
48
+ r += ":#{tag_version}" if tag_version.present?
49
+ r
50
+ end
51
+
52
+ def tag_name
53
+ return registry.name if registry.name.present?
54
+
55
+ raise 'Registry name is blank'
56
+ end
57
+
58
+ def tag_version
59
+ [tag_version_version, stereotype_tag].reject(&:blank?).join('_')
60
+ end
61
+
62
+ def tag_version_version
63
+ return nil unless version
64
+
65
+ r = generator_version
66
+ r += '-snapshot' if snapshot
67
+ r
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_docker/registry'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Docker
8
+ class Runner
9
+ DOCKER_DEFAULT_REGISTRY_METHOD = :docker_default_registry
10
+
11
+ enable_speaker
12
+ enable_simple_cache
13
+
14
+ runner_with :help do
15
+ desc 'Manipulate Docker images.'
16
+ arg_opt '-n', '--registry-name', 'Docker registry\'s name.'
17
+ bool_opt '-p', '--push', 'Push the image to Docker registry.'
18
+ bool_opt '-r', '--run', 'Run or start a container with builded image.'
19
+ arg_opt '-B', '--build-arg', 'Argument for "docker build".', repeat: true
20
+ arg_opt '-E', '--entrypoint-arg', 'Argument for entrypoint on "docker run"', repeat: true
21
+ bool_opt '-c', '--clear', 'Remove container if exist before run.'
22
+ bool_opt '-S', '--no-snapshot', 'Does not add "-snapshot" to image tag.'
23
+ bool_opt '-V', '--no-version', 'Does not add version to image tag.'
24
+ end
25
+
26
+ def run
27
+ setup
28
+ banner
29
+ build
30
+ push
31
+ container_run
32
+ end
33
+
34
+ private
35
+
36
+ def setup
37
+ instance.docker_image_options = {
38
+ registry: registry,
39
+ snapshot: snapshot?,
40
+ version: version?
41
+ }
42
+ end
43
+
44
+ def banner
45
+ infov 'Registry name', registry
46
+ infov 'Version?', version?
47
+ infov 'Snapshot?', snapshot?
48
+ infov 'Image name', docker_image.tag
49
+ infov 'Build arguments', build_args
50
+ infov 'Entrypoint arguments', entrypoint_args
51
+ end
52
+
53
+ def build
54
+ docker_image.build(build_args)
55
+ success 'Docker image builded'
56
+ end
57
+
58
+ def build_args
59
+ parsed.build_arg
60
+ end
61
+
62
+ def docker_container
63
+ instance.docker_container
64
+ end
65
+
66
+ def docker_image
67
+ instance.docker_image
68
+ end
69
+
70
+ def entrypoint_args
71
+ parsed.entrypoint_arg
72
+ end
73
+
74
+ def push
75
+ docker_image.push if parsed.push?
76
+ end
77
+
78
+ def container_run
79
+ return unless parsed.run?
80
+
81
+ docker_container.run(
82
+ entrypoint_args: entrypoint_args,
83
+ clear: parsed.clear?
84
+ )
85
+ end
86
+
87
+ def registry_uncached
88
+ registry_from_option || registry_from_instance || registry_from_default ||
89
+ fatal_error('No registry defined')
90
+ end
91
+
92
+ def registry_from_option
93
+ parsed.registry_name.if_present { |v| ::EacDocker::Registry.new(v) }
94
+ end
95
+
96
+ def registry_from_instance
97
+ instance.docker_registry_optional.if_present { |v| ::EacDocker::Registry.new(v) }
98
+ end
99
+
100
+ def registry_from_default
101
+ if_respond(DOCKER_DEFAULT_REGISTRY_METHOD, nil)
102
+ end
103
+
104
+ def snapshot?
105
+ !parsed.no_snapshot?
106
+ end
107
+
108
+ def version?
109
+ !parsed.no_version?
110
+ end
111
+
112
+ def instance
113
+ runner_context.call(:instance)
114
+ end
115
+ end
116
+ end
117
+ end
data/lib/avm/docker.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Docker
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/envs'
4
+ require 'eac_ruby_utils/simple_cache'
5
+
6
+ module Avm
7
+ module Executables
8
+ class << self
9
+ include ::EacRubyUtils::SimpleCache
10
+
11
+ def env
12
+ ::EacRubyUtils::Envs.local
13
+ end
14
+
15
+ private
16
+
17
+ %w[file git js-beautify latex php-cs-fixer tidy yapf xdg-open].each do |program|
18
+ define_method(program.underscore + '_uncached') do
19
+ env.executable(program, '--version')
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/files/appendable/resource_base'
5
+
6
+ module Avm
7
+ module Files
8
+ module Appendable
9
+ class FileContent < ::Avm::Files::Appendable::ResourceBase
10
+ attr_reader :target_path, :content
11
+
12
+ def initialize(deploy, target_path, content)
13
+ super(deploy)
14
+ @target_path = target_path
15
+ @content = content
16
+ end
17
+
18
+ def write_on(target_dir)
19
+ target_dir.join(target_path).write(content)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/files/appendable/resource_base'
5
+
6
+ module Avm
7
+ module Files
8
+ module Appendable
9
+ class PlainDirectory < ::Avm::Files::Appendable::ResourceBase
10
+ attr_reader :source_path
11
+
12
+ def initialize(appender, source_path)
13
+ super(appender)
14
+ @source_path = source_path.to_pathname
15
+ end
16
+
17
+ def write_on(target_dir)
18
+ raise "\"#{source_path}\" is not a directory" unless source_path.directory?
19
+
20
+ ::FileUtils.cp_r("#{source_path}/.", target_dir.to_path)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Files
7
+ module Appendable
8
+ class ResourceBase
9
+ common_constructor :appender
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/envs'
5
+ require 'avm/files/appendable/resource_base'
6
+
7
+ module Avm
8
+ module Files
9
+ module Appendable
10
+ class TarOutputCommand < ::Avm::Files::Appendable::ResourceBase
11
+ attr_reader :command
12
+
13
+ def initialize(appender, command)
14
+ super(appender)
15
+ @command = command
16
+ end
17
+
18
+ def write_on(target_dir)
19
+ command.pipe(
20
+ ::EacRubyUtils::Envs.local.command('tar', '-xf', '-', '-C', target_dir)
21
+ ).execute!
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/files/appendable/resource_base'
5
+ require 'eac_templates/directory'
6
+
7
+ module Avm
8
+ module Files
9
+ module Appendable
10
+ class TemplatizedDirectory < ::Avm::Files::Appendable::ResourceBase
11
+ attr_reader :source_path
12
+
13
+ def initialize(appender, source_path)
14
+ super(appender)
15
+ @source_path = source_path
16
+ end
17
+
18
+ def write_on(target_dir)
19
+ raise 'Variables source not set' if appender.variables_source.blank?
20
+
21
+ ::EacTemplates::Directory.new(source_path).apply(
22
+ appender.variables_source,
23
+ target_dir
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Files
7
+ module Appendable
8
+ require_sub __FILE__
9
+
10
+ attr_reader :variables_source
11
+
12
+ def appended
13
+ @appended ||= []
14
+ end
15
+
16
+ def append_templatized_directories(directories)
17
+ directories.each { |directory| append_templatized_directory(directory) }
18
+ self
19
+ end
20
+
21
+ def append_plain_directory(directory)
22
+ appended << ::Avm::Files::Appendable::PlainDirectory.new(self, directory)
23
+ self
24
+ end
25
+
26
+ def append_tar_output_command(tar_command)
27
+ appended << ::Avm::Files::Appendable::TarOutputCommand.new(self, tar_command)
28
+ self
29
+ end
30
+
31
+ def append_templatized_directory(directory)
32
+ appended << ::Avm::Files::Appendable::TemplatizedDirectory.new(self, directory)
33
+ self
34
+ end
35
+
36
+ def append_file_content(target_path, content)
37
+ appended << ::Avm::Files::Appendable::FileContent
38
+ .new(self, target_path, content)
39
+ self
40
+ end
41
+
42
+ def variables_source_set(source)
43
+ @variables_source = source
44
+ self
45
+ end
46
+
47
+ def write_appended_on(target_dir)
48
+ target_dir = target_dir.to_pathname
49
+ raise "\"#{target_dir}\" is not a directory" unless target_dir.directory?
50
+
51
+ appended.each { |append| append.write_on(target_dir) }
52
+ end
53
+ end
54
+ end
55
+ end