Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ Fetching an artifact:
filename => 'myproject-1.2.3-war'
}
</pre>
<pre>
artifactory::fetch_artifact { 'mywar':
install_path => '/data/tomcat/site',
base_path => 'http://myhost/myartifactory',
repo => 'mysimplerepo',
filename => 'myproject-1.2.3.war',
source_file => 'myproject.war',
layout => 'myteam/myproject/1.2.3/foo'
}
</pre>
This will fetch a war of version 1.2.3 of myproject and store it as
/data/tomcat/site/myproject-1.2.3-war.

Expand Down
42 changes: 19 additions & 23 deletions manifests/fetch_artifact.pp
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,34 @@
$version,
$install_path,
$format,
$path = undef,
$path = '',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puppet 4 is unhappy with assigning strings to an empty value - why the change on these?

$server = 'http://artifactory',
$repo = 'libs-release-local',
$filename = undef,
$source_file = undef,
$filename = '',
$source_file = ''
){

if $source_file {
$sourcefile_real = $source_file
} else {
$sourcefile_real = "${project}-${version}.${format}"
if ( $source_file == '' and $format == '' ) {
fail('source_file or format is required')
}

if $filename {
$filename_real = $filename
} else {
$filename_real = "${project}-${version}.${format}"
$sourcefile_real = $source_file ? {
'' => "${project}-${version}.${format}",
default => $source_file
}

if ( $path ) {
$fetch_url = "${server}/artifactory/${repo}/${path}/${project}/${version}/${sourcefile_real}"
} else {
$fetch_url = "${server}/artifactory/${repo}/${project}/${version}/${sourcefile_real}"
$filename_real = $filename ? {
'' => "${project}-${version}.${format}",
default => $filename
}

$full_path = "${install_path}/${filename_real}"

exec { "artifactory_fetch_${name}":
command => "curl -o ${full_path} ${fetch_url}",
cwd => $install_path,
creates => $full_path,
path => '/usr/bin:/bin',
logoutput => on_failure;
artifactory::fetch_artifact_generic {"fetch_artifact_generic_${name}":
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is fetch_artifact_generic intended to be used as a standalone in some cases? Trying to understand why you broke it out into it's own directive.

install_path => $install_path,
base_path => "${server}/artifactory",
repo => $repo,
filename => $filename_real,
source_file => $sourcefile_real,
layout => "${path}/${project}/${version}"
}

}
90 changes: 90 additions & 0 deletions manifests/fetch_artifact_generic.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# == Definition: artifactory::fetch_artifact_generic
#
# This define fetches a specific artifact from artifactory
#
# === Parameters
#
# [*install_path*]
# String. Where should the fetched file be installed at
#
# [*base_path*]
# String. Full path to artifactory repository
# Default: 'http://artifactory/artifactory'
#
# [*repo*]
# String. Name of the repository that holds this artifact
# Default: libs-release-local
#
# [*filename*]
# String. Filename that should be used for the fetched file
# Default: $project-$version.$format
#
# [*source_file*]
# String. Source file name in project
# Default: ''
#
# [*layout]
# Path to fetch file inside arifactory
#
# === Examples
#
# artifactory::fetch_artifact { 'mywar':
# install_path => '/data/tomcat/site',
# base_path => 'http://myhost/myartifactory',
# repo => 'mysimplerepo',
# filename => 'myproject-1.2.3.war',
# source_file => 'myproject.war',
# layout => 'myteam/myproject/1.2.3/foo'
# }
#
#
# === Authors
#
# * Artem Popenkov <mailto:artem.popenkov@concur.com>
#
define artifactory::fetch_artifact_generic(
$install_path,
$base_path = 'http://artifactory/artifactory',
$repo = 'libs-release-local',
$filename = '',
$source_file,
$layout,
){

if ( $source_file == '') {
fail('source_file is required')
}

# Use source file if filename is not specified
$filename_real = $filename ? {
'' => $source_file,
default => $filename
}

$fetch_url = "${base_path}/${repo}/${layout}/${source_file}"
$full_path = "${install_path}/${filename_real}"

$logoutput = on_failure

case $osfamily {
windows: {
$command = "Import-Module BitsTransfer; Start-BitsTransfer -Source ${fetch_url} -Destination ${install_path}"
$provider = powershell
$path = ''
}
default:{
$command = "curl -o ${full_path} ${fetch_url}"
$provider = shell
$path = '/usr/bin:/bin'
}
}

exec{"artifactory_fetch_${name}":
command => $command,
cwd => $install_path,
creates => $full_path,
provider => $provider,
path => $path,
logoutput => $logoutput,
}
}
3 changes: 2 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"tags": ["artifactory"],
"operatingsystem_support": [
{ "operatingsystem": "RedHat", "operatingsystemmajrelease": [ "6", "7" ] },
{ "operatingsystem": "CentOS", "operatingsystemmajrelease": [ "6", "7" ] }
{ "operatingsystem": "CentOS", "operatingsystemmajrelease": [ "6", "7" ] },
{ "operatingsystem": "Windows", "operatingsystemmajrelease": [ "7", "2012" ] }
],
"dependencies": [
{ "name": "puppetlabs/stdlib", "version_requirement": ">=3.2.0 <5.0.0" }
Expand Down
88 changes: 88 additions & 0 deletions spec/defines/artifactory_fetch_artifact_generic_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
require 'spec_helper'

describe 'artifactory::fetch_artifact_generic', :type => :define do
let(:title) { 'myproject' }

context "Linux: install_path, source_file, layout provided, no filename, base_path or repo" do
let(:params) { {
:install_path => '/somewhere',
:source_file => 'test.jar',
:layout => 'myapp',
} }

it { should contain_exec('artifactory_fetch_myproject').with(
'creates' => '/somewhere/test.jar',
'command' => "curl -o /somewhere/test.jar http://artifactory/artifactory/libs-release-local/myapp/test.jar"
) }
end

context "Windows OS: install_path, source_file, layout provided, no filename, base_path or repo" do
let :facts do{
:osfamily => 'windows'
}end
let(:params) { {
:install_path => '/somewhere',
:source_file => 'test.jar',
:layout => 'myapp',
} }

it { should contain_exec('artifactory_fetch_myproject').with(
'creates' => '/somewhere/test.jar',
'command' => "Import-Module BitsTransfer; Start-BitsTransfer -Source http://artifactory/artifactory/libs-release-local/myapp/test.jar -Destination /somewhere"
) }
end

context "Windows OS: install_path, source_file, layout provided, filename no base_path or repo" do
let :facts do{
:osfamily => 'windows'
}end
let(:params) { {
:install_path => '/somewhere',
:source_file => 'test.jar',
:layout => 'myapp',
:filename => 'downloaded.jar',
} }

it { should contain_exec('artifactory_fetch_myproject').with(
'creates' => '/somewhere/downloaded.jar',
'command' => "Import-Module BitsTransfer; Start-BitsTransfer -Source http://artifactory/artifactory/libs-release-local/myapp/test.jar -Destination /somewhere"
) }
end

context "Windows OS: install_path, source_file, layout provided, filename, base_path no repo" do
let :facts do{
:osfamily => 'windows'
}end
let(:params) { {
:install_path => '/somewhere',
:source_file => 'test.jar',
:layout => 'myapp',
:filename => 'downloaded.jar',
:base_path => 'http://myhost/myrepository',
} }

it { should contain_exec('artifactory_fetch_myproject').with(
'creates' => '/somewhere/downloaded.jar',
'command' => "Import-Module BitsTransfer; Start-BitsTransfer -Source http://myhost/myrepository/libs-release-local/myapp/test.jar -Destination /somewhere"
) }
end

context "Windows OS: all parameters" do
let :facts do{
:osfamily => 'windows'
}end
let(:params) { {
:install_path => '/somewhere',
:source_file => 'test.jar',
:layout => 'myapp',
:filename => 'downloaded.jar',
:base_path => 'http://myhost/myrepository',
:repo => 'mysimple',
} }

it { should contain_exec('artifactory_fetch_myproject').with(
'creates' => '/somewhere/downloaded.jar',
'command' => "Import-Module BitsTransfer; Start-BitsTransfer -Source http://myhost/myrepository/mysimple/myapp/test.jar -Destination /somewhere"
) }
end
end
109 changes: 62 additions & 47 deletions spec/defines/artifactory_fetch_artifact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,83 @@

context "project, version, format, path provided, no filename, repo or server" do
let(:params) { {
:project => 'foo',
:version => '1.2.3',
:format => 'war',
:server => 'http://server1',
:repo => 'test',
:path => 'usr',
:install_path => '/somewhere',
} }
:project => 'foo',
:version => '1.2.3',
:format => 'war',
:path => 'usr',
:install_path => '/somewhere',
} }

it { should contain_exec('artifactory_fetch_myproject').with(
'creates' => '/somewhere/foo-1.2.3.war',
'command' => "curl -o /somewhere/foo-1.2.3.war http://server1/artifactory/test/usr/foo/1.2.3/foo-1.2.3.war"
) }
it { should contain_artifactory__fetch_artifact_generic('fetch_artifact_generic_myproject').with(
'install_path' => '/somewhere',
'base_path' => 'http://artifactory/artifactory',
'repo' => 'libs-release-local',
'filename' => 'foo-1.2.3.war',
'source_file' => 'foo-1.2.3.war',
'layout' => "usr/foo/1.2.3"
) }
end

context "project, version, format, path, filename provided, no repo or server" do
context "project, version, format, path, filename, repo, server provided" do
let(:params) { {
:project => 'foo',
:version => '1.2.3',
:format => 'war',
:server => 'http://server1',
:repo => 'test',
:filename => 'monkeys.test',
:install_path => '/somewhere'
} }
:project => 'foo',
:version => '1.2.3',
:format => 'war',
:server => 'http://server1',
:repo => 'test',
:filename => 'monkeys.test',
:install_path => '/somewhere'
} }

it { should contain_exec('artifactory_fetch_myproject').with(
'creates' => '/somewhere/monkeys.test'
) }
it { should contain_artifactory__fetch_artifact_generic('fetch_artifact_generic_myproject').with(
'install_path' => '/somewhere',
'base_path' => 'http://server1/artifactory',
'repo' => 'test',
'filename' => 'monkeys.test',
'source_file' => 'foo-1.2.3.war',
'layout' => '/foo/1.2.3'
) }
end

context "project, version, format, server, repo provided, no filename" do
let(:params) { {
:project => 'foo',
:version => '1.2.3',
:format => 'war',
:server => 'http://server1',
:repo => 'test',
:install_path => '/somewhere'
} }
:project => 'foo',
:version => '1.2.3',
:format => 'war',
:server => 'http://server1',
:repo => 'test',
:install_path => '/somewhere'
} }

it { should contain_exec('artifactory_fetch_myproject').with(
'creates' => '/somewhere/foo-1.2.3.war',
'command' => "curl -o /somewhere/foo-1.2.3.war http://server1/artifactory/test/foo/1.2.3/foo-1.2.3.war"
) }
it { should contain_artifactory__fetch_artifact_generic('fetch_artifact_generic_myproject').with(
'install_path' => '/somewhere',
'base_path' => 'http://server1/artifactory',
'repo' => 'test',
'filename' => 'foo-1.2.3.war',
'source_file' => 'foo-1.2.3.war',
'layout' => '/foo/1.2.3'
) }
end

context "project, version , source_file" do
let(:params) { {
:project => 'foo',
:version => '1.2.3',
:format => 'war',
:server => 'http://server1',
:repo => 'test',
:install_path => '/somewhere',
:source_file => 'bar-2.3.4-all.war'
} }
:project => 'foo',
:version => '1.2.3',
:format => 'war',
:server => 'http://server1',
:repo => 'test',
:install_path => '/somewhere',
:source_file => 'bar-2.3.4-all.war'
} }

it { should contain_exec('artifactory_fetch_myproject').with(
'creates' => '/somewhere/foo-1.2.3.war',
'command' => "curl -o /somewhere/foo-1.2.3.war http://server1/artifactory/test/foo/1.2.3/bar-2.3.4-all.war"
) }
it { should contain_artifactory__fetch_artifact_generic('fetch_artifact_generic_myproject').with(
'install_path' => '/somewhere',
'base_path' => 'http://server1/artifactory',
'repo' => 'test',
'filename' => 'foo-1.2.3.war',
'source_file' => 'bar-2.3.4-all.war',
'layout' => '/foo/1.2.3'
) }

end

Expand Down