avm-tools 0.21.0 → 0.22.0

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
  SHA256:
3
- metadata.gz: 8706b02e9000a68816108236851b8d1d80f23c4e4459e080512465c5380bdd75
4
- data.tar.gz: 663eb3ef35a98308fcecb64f6a1158165b83f69ffcfeea8a37d15d1710b27bae
3
+ metadata.gz: 15042971f9c97791f18e9e663ddc0bc3294280e1efba45d7f14ac3c6af60e63e
4
+ data.tar.gz: 06ff3ac5fa18b309c36372c52cf551c7e2da7059c716087ab6b82739c7ecc48b
5
5
  SHA512:
6
- metadata.gz: 0ea0def902b2667c4dcb99be2221c917d12ac0acbe534035fe1d296afd4ad4f90ba1a722a1a1e2759b34a2b69791c54615623279813fe410acf2f748fb806b46
7
- data.tar.gz: dac7b5102c6624d928f18003e3b745b7fbd89aad73e8b721eedbb08470486f0b4724479cc2d74eaa46e507ee6cd0c17da32c0a38df6afeeb21dcc11667347a8b
6
+ metadata.gz: 753715c0040270d6fc3e1cf4cc212bca06397e4dd21312e3d148d1575071272ad7b489cbef53872df3919d29b11220ea82a829e54bf315e4257022ccd639576a
7
+ data.tar.gz: 59a989fe98205a556e301b8dbe7d5a90f00d075809cd9db6e6a7511b789a256126e43b606431b3344ff632c8a2d61d24cdddd12c380c6822d503c2c9e0ca32f0
data/lib/avm.rb CHANGED
@@ -1,14 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/require_sub'
4
+
3
5
  module Avm
4
- require 'avm/configs'
5
- require 'avm/data'
6
- require 'avm/executables'
7
- require 'avm/git'
8
- require 'avm/instances'
9
- require 'avm/patches'
10
- require 'avm/result'
11
- require 'avm/stereotypes'
12
- require 'avm/templates'
13
- require 'avm/tools'
6
+ ::EacRubyUtils.require_sub(__FILE__)
14
7
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+
5
+ module Avm
6
+ module Docker
7
+ ::EacRubyUtils.require_sub(__FILE__)
8
+ end
9
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/executables'
5
+
6
+ module Avm
7
+ module Docker
8
+ class Container
9
+ enable_console_speaker
10
+ common_constructor :instance
11
+
12
+ def remove
13
+ ::Avm::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
26
+ end
27
+ end
28
+
29
+ def run_run
30
+ infom "\"docker run #{instance.docker_container_name}...\""
31
+ ::Avm::Executables.docker.command.append(run_run_arguments).system!
32
+ end
33
+
34
+ def run_start
35
+ infom "\"docker start #{instance.docker_container_name}...\""
36
+ ::Avm::Executables.docker.command.append(run_start_arguments).system!
37
+ end
38
+
39
+ def run_run_arguments
40
+ ['run', '-it', '--name', instance.docker_container_name] + instance.docker_run_arguments +
41
+ [instance.docker_image.tag]
42
+ end
43
+
44
+ def run_start_arguments
45
+ ['start', '-ai', instance.docker_container_name]
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/executables'
5
+ require 'avm/patches/object/template'
6
+
7
+ module Avm
8
+ module Docker
9
+ class Image
10
+ def build(extra_args = [])
11
+ on_build_dir do
12
+ template.apply(self, build_dir)
13
+ run_docker_build(extra_args)
14
+ end
15
+ end
16
+
17
+ def push
18
+ ::Avm::Executables.docker.command.append(['push', tag]).system!
19
+ end
20
+
21
+ def read_entry(path, _options = {})
22
+ method = path.gsub('.', '_')
23
+ return send(method) if respond_to?(path, true)
24
+
25
+ raise "Method \"#{method}\" not found for entry \"#{path}\""
26
+ end
27
+
28
+ def run(instance)
29
+ run_run(instance) if container_exist?(instance)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :build_dir
35
+
36
+ def run_docker_build(extra_args)
37
+ ::Avm::Executables.docker.command.append(
38
+ ['build', '-t', tag] + extra_args + [build_dir]
39
+ ).system!
40
+ end
41
+
42
+ def on_build_dir
43
+ @build_dir = ::Dir.mktmpdir
44
+ yield
45
+ ensure
46
+ ::FileUtils.rm_rf(@build_dir)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Docker
7
+ class Registry
8
+ class << self
9
+ def default
10
+ @default ||= new(::Avm.configs.read_entry('docker.registry.name'))
11
+ end
12
+ end
13
+
14
+ common_constructor :name
15
+
16
+ def to_s
17
+ name
18
+ end
19
+
20
+ def sub(suffix)
21
+ self.class.new("#{name}#{suffix}")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'avm/docker/registry'
6
+
7
+ module Avm
8
+ module Docker
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ enable_console_speaker
11
+ enable_simple_cache
12
+
13
+ DOC = <<~DOCOPT
14
+ Manipulate Docker images.
15
+
16
+ Usage:
17
+ __PROGRAM__ [options] [-B <build-arg>...]
18
+ __PROGRAM__ -h | --help
19
+
20
+ Options:
21
+ -h --help Show this help.
22
+ -n --registry-name=<registry-name> Docker registry's name.
23
+ -p --push Push the image to Docker registry.
24
+ -r --run Run or start a container with builded image.
25
+ -B --build-arg=<build-arg> Argument for "docker build".
26
+ -c --clear Remove container if exist before run.
27
+ DOCOPT
28
+
29
+ def run
30
+ setup
31
+ banner
32
+ build
33
+ push
34
+ container_run
35
+ end
36
+
37
+ private
38
+
39
+ def setup
40
+ instance.docker_registry = registry
41
+ end
42
+
43
+ def banner
44
+ infov 'Registry name', registry
45
+ infov 'Image name', instance.docker_image.tag
46
+ infov 'Build arguments', build_args
47
+ end
48
+
49
+ def build
50
+ instance.docker_image.build(build_args)
51
+ end
52
+
53
+ def build_args
54
+ options.fetch('--build-arg')
55
+ end
56
+
57
+ def push
58
+ instance.docker_image.push if options.fetch('--push')
59
+ end
60
+
61
+ def container_run
62
+ instance.docker_container.run(clear: options.fetch('--clear')) if options.fetch('--run')
63
+ end
64
+
65
+ def registry_uncached
66
+ options.fetch('--registry-name').if_present(::Avm::Docker::Registry.default) do |v|
67
+ ::Avm::Docker::Registry.new(v)
68
+ end
69
+ end
70
+
71
+ def instance
72
+ context(:instance)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -12,6 +12,10 @@ module Avm
12
12
  def git
13
13
  @git ||= env.executable('git', '--version')
14
14
  end
15
+
16
+ def docker
17
+ @docker ||= env.executable('docker', '--version')
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -11,11 +11,12 @@ module Avm
11
11
  include ::EacRubyUtils::Listable
12
12
  include ::EacRubyUtils::SimpleCache
13
13
  include ::Avm::Instances::Base::AutoValues
14
+ include ::Avm::Instances::Base::Dockerizable
14
15
  include ::Avm::Instances::Entries
15
16
 
16
17
  lists.add_string :access, :local, :ssh
17
18
 
18
- ID_PATTERN = /\A([a-z]+(?:\-[a-z]+)*)_(.+)\z/.freeze
19
+ ID_PATTERN = /\A([a-z0-9]+(?:\-[a-z0-9]+)*)_(.+)\z/.freeze
19
20
 
20
21
  class << self
21
22
  def by_id(id)
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/docker/container'
4
+
5
+ module Avm
6
+ module Instances
7
+ class Base
8
+ module Dockerizable
9
+ enable_simple_cache
10
+ attr_reader :docker_registry
11
+
12
+ def docker_registry=(new_value)
13
+ @docker_registry = new_value
14
+ reset_cache
15
+ end
16
+
17
+ def docker_container_exist?
18
+ ::Avm::Executables.docker.command.append(
19
+ ['ps', '-qaf', "name=#{docker_container_name}"]
20
+ ).execute!.present?
21
+ end
22
+
23
+ def docker_container_name
24
+ id
25
+ end
26
+
27
+ private
28
+
29
+ def docker_container_uncached
30
+ ::Avm::Docker::Container.new(self)
31
+ end
32
+
33
+ def docker_image_uncached
34
+ docker_image_class.new(docker_registry)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/require_sub'
4
+
5
+ module Avm
6
+ module Stereotypes
7
+ module EacRedmineBase0
8
+ ::EacRubyUtils.require_sub(__FILE__)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/instances/base'
4
+ require 'avm/stereotypes/eac_ubuntu_base0/docker_image'
5
+
6
+ module Avm
7
+ module Stereotypes
8
+ module EacRedmineBase0
9
+ class Instance < ::Avm::Instances::Base
10
+ def docker_image_class
11
+ ::Avm::Stereotypes::EacUbuntuBase0::DockerImage
12
+ end
13
+
14
+ def docker_run_arguments
15
+ [
16
+ '--volume', "#{read_entry(:fs_path)}:/home/myuser/eac_redmine_base0",
17
+ '--publish', "#{read_entry(:ssh_port)}:22",
18
+ '--publish', "#{read_entry(:http_port)}:80",
19
+ '--publish', "#{read_entry(:https_port)}:443"
20
+ ]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'avm/docker/image'
5
+
6
+ module Avm
7
+ module Stereotypes
8
+ module EacUbuntuBase0
9
+ class DockerImage < ::Avm::Docker::Image
10
+ enable_simple_cache
11
+ common_constructor :registry
12
+
13
+ def tag
14
+ "#{registry.name}:eac_ubuntu_base0"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/simple_cache'
5
+ require 'avm/stereotypes/eac_redmine_base0/instance'
6
+ require 'eac_ruby_utils/require_sub'
7
+ ::EacRubyUtils.require_sub(__FILE__)
8
+
9
+ module Avm
10
+ module Tools
11
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
12
+ class EacRedmineBase0 < ::EacRubyUtils::Console::DocoptRunner
13
+ include ::EacRubyUtils::SimpleCache
14
+
15
+ DOC = <<~DOCOPT
16
+ Utilities for EacRedmineBase0 instances.
17
+
18
+ Usage:
19
+ __PROGRAM__ [options] <instance_id> __SUBCOMMANDS__
20
+ __PROGRAM__ -h | --help
21
+
22
+ Options:
23
+ -h --help Show this screen.
24
+ DOCOPT
25
+
26
+ private
27
+
28
+ def instance_uncached
29
+ ::Avm::Stereotypes::EacRedmineBase0::Instance.by_id(options['<instance_id>'])
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/docker/runner'
4
+
5
+ module Avm
6
+ module Tools
7
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
8
+ class EacRedmineBase0 < ::EacRubyUtils::Console::DocoptRunner
9
+ class Docker < ::Avm::Docker::Runner
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.21.0'
5
+ VERSION = '0.22.0'
6
6
  end
7
7
  end
@@ -0,0 +1,11 @@
1
+ FROM ubuntu:bionic
2
+ RUN apt-get update -y
3
+ RUN apt-get install -y sudo tzdata
4
+ RUN /usr/sbin/useradd --shell /bin/bash --home-dir /home/myuser --create-home myuser
5
+ RUN /bin/echo 'myuser:myuser' | /usr/sbin/chpasswd
6
+ RUN /bin/chown myuser:myuser /home/myuser -R
7
+ RUN /bin/echo "myuser ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/myuser_all_nopasswd && chmod 0440 /etc/sudoers.d/myuser_all_nopasswd
8
+ USER myuser
9
+ WORKDIR /home/myuser
10
+ ENTRYPOINT /bin/bash
11
+ CMD apt-get update -y && apt-get dist-upgrade -y
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-12 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -180,6 +180,11 @@ files:
180
180
  - lib/avm/data/package/dump.rb
181
181
  - lib/avm/data/package/load.rb
182
182
  - lib/avm/data/unit.rb
183
+ - lib/avm/docker.rb
184
+ - lib/avm/docker/container.rb
185
+ - lib/avm/docker/image.rb
186
+ - lib/avm/docker/registry.rb
187
+ - lib/avm/docker/runner.rb
183
188
  - lib/avm/executables.rb
184
189
  - lib/avm/files.rb
185
190
  - lib/avm/files/rotate.rb
@@ -210,6 +215,7 @@ files:
210
215
  - lib/avm/instances/base/auto_values/source.rb
211
216
  - lib/avm/instances/base/auto_values/system.rb
212
217
  - lib/avm/instances/base/auto_values/web.rb
218
+ - lib/avm/instances/base/dockerizable.rb
213
219
  - lib/avm/instances/entries.rb
214
220
  - lib/avm/instances/entries/entry_reader.rb
215
221
  - lib/avm/patches.rb
@@ -221,9 +227,12 @@ files:
221
227
  - lib/avm/stereotypes/eac_rails_base0/apache_host.rb
222
228
  - lib/avm/stereotypes/eac_rails_base0/deploy.rb
223
229
  - lib/avm/stereotypes/eac_rails_base0/instance.rb
230
+ - lib/avm/stereotypes/eac_redmine_base0.rb
231
+ - lib/avm/stereotypes/eac_redmine_base0/instance.rb
224
232
  - lib/avm/stereotypes/eac_ubuntu_base0.rb
225
233
  - lib/avm/stereotypes/eac_ubuntu_base0/apache.rb
226
234
  - lib/avm/stereotypes/eac_ubuntu_base0/apache/site.rb
235
+ - lib/avm/stereotypes/eac_ubuntu_base0/docker_image.rb
227
236
  - lib/avm/stereotypes/eac_webapp_base0.rb
228
237
  - lib/avm/stereotypes/eac_webapp_base0/apache_host.rb
229
238
  - lib/avm/stereotypes/eac_webapp_base0/deploy.rb
@@ -244,6 +253,8 @@ files:
244
253
  - lib/avm/tools/runner/eac_rails_base0.rb
245
254
  - lib/avm/tools/runner/eac_rails_base0/apache_host.rb
246
255
  - lib/avm/tools/runner/eac_rails_base0/deploy.rb
256
+ - lib/avm/tools/runner/eac_redmine_base0.rb
257
+ - lib/avm/tools/runner/eac_redmine_base0/docker.rb
247
258
  - lib/avm/tools/runner/eac_wordpress_base0.rb
248
259
  - lib/avm/tools/runner/eac_wordpress_base0/apache_host.rb
249
260
  - lib/avm/tools/runner/eac_wordpress_base0/data.rb
@@ -261,6 +272,7 @@ files:
261
272
  - lib/avm/tools/runner/git/issue/complete.rb
262
273
  - lib/avm/tools/version.rb
263
274
  - template/avm/stereotypes/eac_rails_base0/deploy/config/database.yml.template
275
+ - template/avm/stereotypes/eac_ubuntu_base0/docker_image/Dockerfile
264
276
  - template/avm/stereotypes/eac_webapp_base0/apache_host/no_ssl.conf
265
277
  - template/avm/stereotypes/eac_wordpress_base0/deploy/wp-config.php.template
266
278
  homepage: