Class: Omnibus::Publisher

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/omnibus/publisher.rb

Direct Known Subclasses

ArtifactoryPublisher, NullPublisher, S3Publisher

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included

Constructor Details

#initialize(pattern, options = {}) ⇒ Publisher

Create a new publisher from the given pattern.

Examples:

{
  'ubuntu-10.04' => [
    'ubuntu-10.04',
    'ubuntu-12.04',
    'ubuntu-14.04',
  ],
}

Options Hash (options):

  • :platform_mappings (Hash)

    A simple mapping of build to publish platform(s)



52
53
54
55
56
57
58
59
60
61
# File 'lib/omnibus/publisher.rb', line 52

def initialize(pattern, options = {})
  @pattern = pattern
  @options = options.dup

  if @options[:platform_mappings]
    log.info(log_key) do
      "Publishing will be performed using provided platform mappings."
    end
  end
end

Class Method Details

.publish(pattern, options = {}, &block) ⇒ Object

Shortcut class method for creating a new instance of this class and executing the publishing sequence.



26
27
28
# File 'lib/omnibus/publisher.rb', line 26

def publish(pattern, options = {}, &block)
  new(pattern, options).publish(&block)
end

Instance Method Details

#packagesArray<String>

The list of packages that match the pattern in the initializer.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/omnibus/publisher.rb', line 68

def packages
  @packages ||= begin
    publish_packages = Array.new
    build_packages   = FileSyncer.glob(@pattern).map { |path| Package.new(path) }

    if @options[:platform_mappings]
      # the platform map is a simple hash with publish to build platform mappings
      @options[:platform_mappings].each_pair do |build_platform, publish_platforms|
        # Splits `ubuntu-12.04` into `ubuntu` and `12.04`
        build_platform, build_platform_version = build_platform.rpartition('-') - %w( - )

        # locate the package for the build platform
        packages = build_packages.select do |p|
          p.[:platform] == build_platform &&
            p.[:platform_version] == build_platform_version
        end

        if packages.empty?
          log.warn(log_key) do
            "Could not locate a package for build platform #{build_platform}-#{build_platform_version}. " \
            "Publishing will be skipped for: #{publish_platforms.join(', ')}"
          end
        end

        publish_platforms.each do |publish_platform|
          publish_platform, publish_platform_version = publish_platform.rpartition('-') - %w( - )

          packages.each do |p|
            # create a copy of our package before mucking with its metadata
            publish_package  = p.dup
             = p..dup.to_hash

            # override the platform and platform version in the metadata
            [:platform]         = publish_platform
            [:platform_version] = publish_platform_version

            # Set the updated metadata on the package object
            publish_package. = .new(publish_package, )

            publish_packages << publish_package
          end
        end
      end
    else
      publish_packages.concat(build_packages)
    end

    if publish_packages.empty?
      log.info(log_key) { 'No packages found, skipping publish' }
    end

    publish_packages
  end
end

#publish(&_block) ⇒ Array<String>

This method is abstract.

Returns the list of uploaded packages

Raises:

  • (NotImplementedError)


132
133
134
# File 'lib/omnibus/publisher.rb', line 132

def publish(&_block)
  raise NotImplementedError
end