Sha256: 82554ea4166e3e227621cbd97678573ad2e10bf16aa569abf05847ae36661f0f

Contents?: true

Size: 1.96 KB

Versions: 5

Compression:

Stored size: 1.96 KB

Contents

require_relative 'rbld_log'
require_relative 'rbld_utils'
require_relative 'rbld_fileops'

module Rebuild
  module Registry
  module FS
    extend Rebuild::Utils::Errors

    rebuild_error FSLookupError: 'Failed to access registry at %s'

    class API
      FILE_SFX = '.rbe'
      private_constant :FILE_SFX

      def initialize(path)
        @path = path
        @path.gsub!( '\\', '/' ) if OS.windows?
        rbld_log.info( "Connecting to registry #{@path}" )
        raise FSLookupError, @path unless Dir.exists?( @path )
      end

      def search(name = nil, tag = nil)
        wildcard = File.join( tag.to_s.empty? ? ["#{name}*", '*' ] : [name, tag] ) + FILE_SFX

        rbld_log.info( "Searching for #{wildcard}" )

        Dir.glob( File.join( @path, wildcard ) ).map do |n|

          rbld_log.debug( "Found entry: #{n}" )

          pfx = File.join( @path,'' )
          sfx = FILE_SFX
          s = File::SEPARATOR
          nametag = match_fs_path( n, "^#{pfx}([^#{s}]+)#{s}([^#{s}]+)#{sfx}$" ).captures
          Rebuild::Utils::FullImageName.new( *nametag )
        end
      end

      def publish(name, tag, img)
        reg_dir = File.join( @path, name )
        reg_file = File.join( reg_dir, tag ) + FILE_SFX

        rbld_log.info( "Pushing to #{@path}" )

        FileUtils.mkdir_p( File.join( reg_dir ) )

        begin
          ef = Rebuild::Engine::EnvironmentFile.new(reg_file)
          ef.save!( Rebuild::Utils::FullImageName.new( name, tag ), img.identity )
        rescue
          FileUtils.rm_rf( reg_file )
          raise
        end
      end

      def deploy(name, tag, api_class = ::Docker::Image)
        reg_file = File.join( @path, name, tag ) + FILE_SFX
        rbld_log.info( "Pulling from #{@path}" )
        Rebuild::Engine::EnvironmentFile.new(reg_file).load!
      end

      private

      def match_fs_path(path, rule)
        regex = ( OS.windows? || OS.mac? ) ? /#{rule}/i : /#{rule}/
        path.match( regex )
      end
    end
  end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rbld-1.3.8 cli/lib/rbld_reg_fs.rb
rbld-1.3.7 cli/lib/rbld_reg_fs.rb
rbld-1.3.6 cli/lib/rbld_reg_fs.rb
rbld-1.3.5 cli/lib/rbld_reg_fs.rb
rbld-1.3.4 cli/lib/rbld_reg_fs.rb