dockdev 0.1.0 → 0.3.0
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 +4 -4
- data/exe/dockdev-destroy +29 -0
- data/lib/dockdev/container.rb +18 -0
- data/lib/dockdev/context/rubygems.rb +54 -0
- data/lib/dockdev/context.rb +37 -0
- data/lib/dockdev/image.rb +9 -4
- data/lib/dockdev/version.rb +1 -1
- data/lib/dockdev.rb +65 -5
- metadata +33 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 59b687af53fcbe3924457ab142e49de01af262be7f25d797935ee049075dcb51
         | 
| 4 | 
            +
              data.tar.gz: 1fb3d76c0e2c66098c8d43099ed66d3afdfbf02d5916f603ccd5afca385b6cf3
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 026c92a29234726a235cc23d0f38586c9dc16a74368fdb90899e6c2ee7406ef7540e1dedce2783d2bcad1c5f120e5808cbabddef220fa13baac6131b7b01d644
         | 
| 7 | 
            +
              data.tar.gz: a1c8e52a6a0c9b4bf94619897a1b346b047b3798341e8214eba8c39e94ad8bf886106616ce5bc2de026fba32c0a0d36a4e85620fea832860c0e35993835cbaca
         | 
    
        data/exe/dockdev-destroy
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # end result is there is one container created and
         | 
| 4 | 
            +
            # start will always go into that container until it is
         | 
| 5 | 
            +
            # destroy
         | 
| 6 | 
            +
            # Taking the vagrant model
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            require 'tty/prompt'
         | 
| 9 | 
            +
            require 'colorize'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            require_relative '../lib/dockdev'
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            contName = ARGV.first || File.basename(Dir.getwd)
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            begin
         | 
| 16 | 
            +
              tty = TTY::Prompt.new
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              skip = tty.no? "Destroy development env '#{contName}'?"
         | 
| 19 | 
            +
              if not skip
         | 
| 20 | 
            +
                Dockdev.destroy(contName, root: Dir.getwd)
         | 
| 21 | 
            +
                STDOUT.puts "\n Docker development environment destroy successfully\n\n".green
         | 
| 22 | 
            +
              else
         | 
| 23 | 
            +
                STDOUT.puts "\n Docker development environment destroy aborted\n\n".yellow
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            rescue StandardError => ex
         | 
| 26 | 
            +
              STDERR.puts ex.message.red
         | 
| 27 | 
            +
            end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
             | 
    
        data/lib/dockdev/container.rb
    CHANGED
    
    | @@ -51,5 +51,23 @@ module Dockdev | |
| 51 51 |  | 
| 52 52 | 
             
                end
         | 
| 53 53 |  | 
| 54 | 
            +
                def stop
         | 
| 55 | 
            +
                  res = @cmd_fact.stop_container(@cont_name).run
         | 
| 56 | 
            +
                  if res.success?
         | 
| 57 | 
            +
                    not res.is_out_stream_empty?
         | 
| 58 | 
            +
                  else
         | 
| 59 | 
            +
                    raise Error, "Command stop container failed with error : #{res.err_stream}"
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                def destroy
         | 
| 64 | 
            +
                  res = @cmd_fact.delete_container(@cont_name).run
         | 
| 65 | 
            +
                  if res.success?
         | 
| 66 | 
            +
                    not res.is_out_stream_empty?
         | 
| 67 | 
            +
                  else
         | 
| 68 | 
            +
                    raise Error, "Command delete container failed with error : #{res.err_stream}"
         | 
| 69 | 
            +
                  end
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 54 72 | 
             
              end
         | 
| 55 73 | 
             
            end
         | 
| @@ -0,0 +1,54 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            require 'bundler'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Dockdev
         | 
| 5 | 
            +
              module Context
         | 
| 6 | 
            +
                class Rubygems
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def self.init_path(path)
         | 
| 9 | 
            +
                    Rubygems.new(path)
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def initialize(path)
         | 
| 13 | 
            +
                    @path = path
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  def is_context?
         | 
| 17 | 
            +
                    find_gemfile.length > 0
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  def find_gemfile
         | 
| 21 | 
            +
                    Dir.glob(File.join(@path,"Gemfile"))
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def process_mount(mount_hash)
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                    if not mount_hash.nil? and mount_hash.is_a?(Hash)
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                      # 
         | 
| 29 | 
            +
                      # looking at source code 
         | 
| 30 | 
            +
                      # https://github.com/rubygems/rubygems/blob/master/bundler/lib/bundler/shared_helpers.rb#L246
         | 
| 31 | 
            +
                      # seems this is the way to set root for Bundler
         | 
| 32 | 
            +
                      #
         | 
| 33 | 
            +
                      ENV['BUNDLE_GEMFILE'] = find_gemfile.first
         | 
| 34 | 
            +
                      Bundler.load.dependencies.each do |d|
         | 
| 35 | 
            +
                        if not d.source.nil?
         | 
| 36 | 
            +
                          src = d.source
         | 
| 37 | 
            +
                          if src.path.to_s != "."
         | 
| 38 | 
            +
                            mount_hash[d.name] = src.path.expand_path.to_s
         | 
| 39 | 
            +
                            #res[d.name] = src.path.expand_path.to_s
         | 
| 40 | 
            +
                          end
         | 
| 41 | 
            +
                        end
         | 
| 42 | 
            +
                      end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    mount_hash
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            Dockdev::Context::ContextManager.instance.register(:rubygems, Dockdev::Context::Rubygems)
         | 
| 54 | 
            +
             | 
| @@ -0,0 +1,37 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            require 'singleton'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Dockdev
         | 
| 5 | 
            +
              module Context
         | 
| 6 | 
            +
                class ContextManager
         | 
| 7 | 
            +
                  include Singleton 
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def initialize
         | 
| 10 | 
            +
                    @ctx = {}  
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def register(name, cls)
         | 
| 14 | 
            +
                    @ctx[name] = cls
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def get_context(path)
         | 
| 18 | 
            +
                    ctx = nil
         | 
| 19 | 
            +
                    @ctx.values.each do |v|
         | 
| 20 | 
            +
                      vv = v.init_path(path)
         | 
| 21 | 
            +
                      if vv.is_context?
         | 
| 22 | 
            +
                        ctx = vv
         | 
| 23 | 
            +
                        break
         | 
| 24 | 
            +
                      end
         | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
                    ctx
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            Dockdev.logger.debug File.join(File.dirname(__FILE__),"context","*.rb")
         | 
| 34 | 
            +
            Dir.glob(File.join(File.dirname(__FILE__),"context","*.rb")).each do |f|
         | 
| 35 | 
            +
              require f
         | 
| 36 | 
            +
            end
         | 
| 37 | 
            +
             | 
    
        data/lib/dockdev/image.rb
    CHANGED
    
    | @@ -34,11 +34,16 @@ module Dockdev | |
| 34 34 | 
             
                    context_root: opts[:root],
         | 
| 35 35 | 
             
                    dockerfile: dockerfile
         | 
| 36 36 | 
             
                  }
         | 
| 37 | 
            -
                   | 
| 38 | 
            -
                   | 
| 39 | 
            -
             | 
| 37 | 
            +
                  optss.merge!(opts)
         | 
| 38 | 
            +
                  @cmd_fact.build_image(@image_name, optss).run
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                def destroy
         | 
| 42 | 
            +
                  res = @cmd_fact.delete_image(@image_name).run
         | 
| 43 | 
            +
                  if res.success?
         | 
| 44 | 
            +
                    not res.is_out_stream_empty?
         | 
| 40 45 | 
             
                  else
         | 
| 41 | 
            -
                    raise Error, "Error triggered during  | 
| 46 | 
            +
                    raise Error, "Error triggered during deleting image : #{res.err_stream}"
         | 
| 42 47 | 
             
                  end
         | 
| 43 48 | 
             
                end
         | 
| 44 49 |  | 
    
        data/lib/dockdev/version.rb
    CHANGED
    
    
    
        data/lib/dockdev.rb
    CHANGED
    
    | @@ -3,6 +3,7 @@ | |
| 3 3 | 
             
            require 'teLogger'
         | 
| 4 4 | 
             
            require 'toolrack'
         | 
| 5 5 | 
             
            require 'docker/cli'
         | 
| 6 | 
            +
            require 'colorize'
         | 
| 6 7 |  | 
| 7 8 | 
             
            require_relative "dockdev/version"
         | 
| 8 9 |  | 
| @@ -10,8 +11,9 @@ require_relative 'dockdev/workspace' | |
| 10 11 | 
             
            require_relative 'dockdev/image'
         | 
| 11 12 | 
             
            require_relative 'dockdev/container'
         | 
| 12 13 |  | 
| 13 | 
            -
             | 
| 14 14 | 
             
            module Dockdev
         | 
| 15 | 
            +
              include TR::CondUtils
         | 
| 16 | 
            +
             | 
| 15 17 | 
             
              class Error < StandardError; end
         | 
| 16 18 | 
             
              # Your code goes here...
         | 
| 17 19 |  | 
| @@ -19,6 +21,10 @@ module Dockdev | |
| 19 21 |  | 
| 20 22 | 
             
                root = opts[:root]
         | 
| 21 23 | 
             
                cmd = opts[:command]
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                ctx = Dockdev::Context::ContextManager.instance.get_context(root)
         | 
| 26 | 
            +
                logger.debug("Found context : #{ctx}")
         | 
| 27 | 
            +
             | 
| 22 28 | 
             
                cont = Container.new(contName)
         | 
| 23 29 | 
             
                if cont.has_container?
         | 
| 24 30 | 
             
                  if cont.running?
         | 
| @@ -28,16 +34,70 @@ module Dockdev | |
| 28 34 | 
             
                  end
         | 
| 29 35 | 
             
                else
         | 
| 30 36 | 
             
                  img = Image.new(contName)
         | 
| 31 | 
            -
                  ws = opts[:workspace] ||  | 
| 37 | 
            +
                  ws = opts[:workspace] || root
         | 
| 32 38 | 
             
                  wss = Workspace.new(ws)
         | 
| 33 39 | 
             
                  if img.has_image?
         | 
| 34 | 
            -
                     | 
| 40 | 
            +
                    mount = { root => File.join("/opt",File.basename(root)) }
         | 
| 41 | 
            +
                    if not ctx.nil?
         | 
| 42 | 
            +
                      mount = ctx.process_mount(mount)
         | 
| 43 | 
            +
                      logger.debug "Mount points by context : #{mount}"
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    img.new_container(cont.name, command: cmd, mounts: mount)
         | 
| 35 47 | 
             
                  elsif wss.has_dockerfile?
         | 
| 36 48 | 
             
                    img.build(wss.dockerfile)
         | 
| 37 | 
            -
                     | 
| 49 | 
            +
                    
         | 
| 50 | 
            +
                    mount = { root => File.join("/opt",File.basename(root)) }
         | 
| 51 | 
            +
                    if not ctx.nil?
         | 
| 52 | 
            +
                      mount = ctx.process_mount(mount)
         | 
| 53 | 
            +
                      logger.debug "Mount points by context : #{mount}"
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    img.new_container(cont.name, command: cmd) #, mounts: mount)
         | 
| 38 57 | 
             
                  else
         | 
| 39 | 
            -
                    raise Error, "\n No image and no Dockerfile found to build the image found. Operation aborted. \n\n"
         | 
| 58 | 
            +
                    raise Error, "\n No image and no Dockerfile found to build the image found. Operation aborted. \n\n".red
         | 
| 40 59 | 
             
                  end
         | 
| 41 60 | 
             
                end
         | 
| 42 61 | 
             
              end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              def self.destroy(contName, opts = {})
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                cont = Container.new(contName)
         | 
| 66 | 
            +
                if cont.has_container?
         | 
| 67 | 
            +
                  cont.stop if cont.running?
         | 
| 68 | 
            +
                  cont.destroy
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                img = Image.new(contName)
         | 
| 72 | 
            +
                if img.has_image?
         | 
| 73 | 
            +
                  img.destroy
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
              def self.logger(tag = nil, &block)
         | 
| 79 | 
            +
                if @_logger.nil?
         | 
| 80 | 
            +
                  @_logger = TeLogger::Tlogger.new(STDOUT)
         | 
| 81 | 
            +
                end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                if block
         | 
| 84 | 
            +
                  if not_empty?(tag)
         | 
| 85 | 
            +
                    @_logger.with_tag(tag, &block)
         | 
| 86 | 
            +
                  else
         | 
| 87 | 
            +
                    @_logger.with_tag(@_logger.tag, &block)
         | 
| 88 | 
            +
                  end
         | 
| 89 | 
            +
                else
         | 
| 90 | 
            +
                  if is_empty?(tag)
         | 
| 91 | 
            +
                    @_logger.tag = :dockdev
         | 
| 92 | 
            +
                    @_logger
         | 
| 93 | 
            +
                  else
         | 
| 94 | 
            +
                    # no block but tag is given? hmm
         | 
| 95 | 
            +
                    @_logger.tag = tag
         | 
| 96 | 
            +
                    @_logger
         | 
| 97 | 
            +
                  end
         | 
| 98 | 
            +
                end
         | 
| 99 | 
            +
              end
         | 
| 100 | 
            +
             | 
| 43 101 | 
             
            end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
            require_relative 'dockdev/context'
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: dockdev
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Chris
         | 
| @@ -52,6 +52,34 @@ dependencies: | |
| 52 52 | 
             
                - - "~>"
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 54 | 
             
                    version: 0.5.1
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: tty-prompt
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - "~>"
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0.23'
         | 
| 62 | 
            +
              type: :runtime
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - "~>"
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0.23'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: colorize
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - "~>"
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '1.1'
         | 
| 76 | 
            +
              type: :runtime
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - "~>"
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '1.1'
         | 
| 55 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 84 | 
             
              name: release-gem
         | 
| 57 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -71,6 +99,7 @@ email: | |
| 71 99 | 
             
            - chris@antrapol.com
         | 
| 72 100 | 
             
            executables:
         | 
| 73 101 | 
             
            - dockdev
         | 
| 102 | 
            +
            - dockdev-destroy
         | 
| 74 103 | 
             
            extensions: []
         | 
| 75 104 | 
             
            extra_rdoc_files: []
         | 
| 76 105 | 
             
            files:
         | 
| @@ -79,8 +108,11 @@ files: | |
| 79 108 | 
             
            - README.md
         | 
| 80 109 | 
             
            - Rakefile
         | 
| 81 110 | 
             
            - exe/dockdev
         | 
| 111 | 
            +
            - exe/dockdev-destroy
         | 
| 82 112 | 
             
            - lib/dockdev.rb
         | 
| 83 113 | 
             
            - lib/dockdev/container.rb
         | 
| 114 | 
            +
            - lib/dockdev/context.rb
         | 
| 115 | 
            +
            - lib/dockdev/context/rubygems.rb
         | 
| 84 116 | 
             
            - lib/dockdev/image.rb
         | 
| 85 117 | 
             
            - lib/dockdev/version.rb
         | 
| 86 118 | 
             
            - lib/dockdev/workspace.rb
         |