Commit 305419dd authored by Seth Chisamore's avatar Seth Chisamore Committed by GitHub
Browse files

Merge pull request #790 from legal90/publish-dir-pattern

Allow setting a custom directory pattern for publishers
parents 2215d10c 562bb99a
......@@ -371,6 +371,14 @@ module Omnibus
raise MissingRequiredAttribute.new(self, :artifactory_base_path, "'com/mycompany'")
end
# Directory pattern for the Artifactory publisher.
# Interpolation of metadata keys is supported.
#
# @example '%{platform}/%{platform_version}/%{arch}/%{basename}'
#
# @return [String]
default(:artifactory_publish_pattern, "%{name}/%{version}/%{platform}/%{platform_version}/%{basename}")
# The path on disk to an SSL pem file to sign requests with.
#
# @return [String, nil]
......@@ -436,6 +444,14 @@ module Omnibus
# @return [String, nil]
default(:publish_s3_profile, nil)
# Directory pattern for the S3 publisher.
# Interpolation of metadata keys is supported.
#
# @example '%{platform}/%{platform_version}/%{arch}/%{basename}'
#
# @return [String]
default(:s3_publish_pattern, "%{platform}/%{platform_version}/%{arch}/%{basename}")
# --------------------------------------------------
# @!endgroup
#
......
......@@ -260,7 +260,7 @@ module Omnibus
# and the package metadata.
#
# @example
# chef/11.6.0/chef-11.6.0-1.el6.x86_64.rpm
# com/getchef/chef/11.6.0/ubuntu/14.04/chef-11.6.0-1.el6.x86_64.rpm
#
# @param [Package] package
# the package to generate the remote path for
......@@ -270,11 +270,7 @@ module Omnibus
def remote_path_for(package)
File.join(
Config.artifactory_base_path,
package.metadata[:name],
package.metadata[:version],
package.metadata[:platform],
package.metadata[:platform_version],
package.metadata[:basename]
Config.artifactory_publish_pattern % package.metadata
)
end
end
......
......@@ -65,19 +65,19 @@ module Omnibus
# The unique upload key for this package. The additional "stuff" is
# postfixed to the end of the path.
#
# @example
# 'el/6/x86_64/chef-11.6.0-1.el6.x86_64.rpm/chef-11.6.0-1.el6.x86_64.rpm'
#
# @param [Package] package
# the package this key is for
# @param [Array<String>] stuff
# the additional things to prepend
# the additional things to append
#
# @return [String]
#
def key_for(package, *stuff)
File.join(
package.metadata[:platform],
package.metadata[:platform_version],
package.metadata[:arch],
package.name,
Config.s3_publish_pattern % package.metadata,
*stuff
)
end
......
......@@ -248,6 +248,22 @@ module Omnibus
subject.publish
end
end
context "custom artifactory_publish_pattern is set" do
before do
Config.artifactory_publish_pattern("%{platform}/%{platform_version}/%{arch}/%{basename}")
end
it "uploads the package to the provided path" do
expect(artifact).to receive(:upload).with(
repository,
"com/getchef/ubuntu/14.04/x86_64/chef.deb",
hash_including(metadata_json_properites)
).once
subject.publish
end
end
end
describe "#metadata_properties_for" do
......
......@@ -100,6 +100,23 @@ module Omnibus
end
end
context "when the custom s3_publish_pattern is set" do
before do
Config.s3_publish_pattern("custom_prefix/%{name}/%{version}/%{platform}/%{platform_version}")
end
it "uploads the package to the provided path" do
expect(subject).to receive(:store_object).with(
"custom_prefix/chef/11.0.6/ubuntu/14.04/chef.deb.metadata.json",
FFI_Yajl::Encoder.encode(package.metadata.to_hash, pretty: true),
nil,
"private"
).once
subject.publish
end
end
context "when a block is given" do
it "yields the package to the block" do
block = ->(package) { package.do_something! }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment