Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from poliva83/master
Browse files Browse the repository at this point in the history
Version 0.1.0 - 03/23/2016
  • Loading branch information
poliva83 authored Jul 25, 2016
2 parents dc73287 + 8cc27ed commit b674c22
Show file tree
Hide file tree
Showing 32 changed files with 1,482 additions and 203 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## 0.1.0 (03/23/2016)
- Implemented actions :upload, :download, :delete, :delete_url
- Created rspec tests
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in chef-nexus.gemspec
gemspec
402 changes: 201 additions & 201 deletions LICENSE

Large diffs are not rendered by default.

215 changes: 213 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,213 @@
# chef-nexus
chef-nexus is a Ruby gem that provides the `nexus` Chef resource for managing artifacts on Nexus by Sonatype.
# Chef::Nexus

chef-nexus is a Chef resource for managing artifacts on Nexus by Sonatype.

## Usage

Simply install the gem and `require 'chef/nexus'` in your recipes, then you can use the `nexus` resource.

There is an optional Nexus config file that you can create and it will be read in the following order:
1. `File.read(ENV['NEXUS_CONFIG'])`
2. `File.read("#{ENV['HOME']}/.nexus/config")`
3. `File.read('/etc/.nexus/config')`

**Note:** only the first one found will be loaded

Example config file:
```json
{
"default": {
"url": "http://mynexus.net/nexus/content/",
"repo": "name_of_repo",
"auth": "gary:secr3t"
},
"gary": {
"url": "http://mynexus.net/nexus/content/",
"repo": "disk_images",
"auth": "gary:p@ssw0rd"
}
}
```

**NOTE:**

* You can pick different profiles with attribute `nexus_profile`
* You can set you default profile with environment variable `export NEXUS_PROFILE=gary`
* If you don't set the env variable or use the attributes below - `"default"` profile must be present, or you will need to specify the `nexus_profile` attribute every time.
* Attribute `nexus_profile` has precedence over environment variable

You can also specify these as attributes:
```ruby
nexus_url 'http://mynexus.net/nexus/content/'
nexus_repo 'name_of_repo'
nexus_auth 'gary:secr3t'
```

And as environment variables:
```shell
export NEXUS_URL=http://mynexus.net/nexus/content/
export NEXUS_REPO=name_of_repo
export NEXUS_AUTH=gary:secr3t
```

Order of precedence:
1. `attribute`
2. `environment`
3. `config`

### Attributes

```ruby
:nexus_profile => String of the profile you want to use
:nexus_url => String url of Nexus
:nexus_repo => String name of your repository
:nexus_auth => String of your Nexus credentials
:use_auth => Boolean specifing whether to authenticate against the Nexus server, fix for 403 Forbidden

:upload_pom => Boolean indicating whether to generate and upload a pom file, default true
:update_if_exists => Boolean specifying whether to overwrite existing artifacts during upload action (deletes artifact folder first)

:local_file => String absolute path to the file to upload from, or download to
:remote_url => String of the URL to be upload to / download from, if used, all attributes below are ignored. SEE NOTES

:coordinates => String Maven coordinates, see: https://maven.apache.org/pom.html#Maven_Coordinates
:groupId => String name of group
:artifactId => String name of artifact
:packaging => String of packaging type
:classifier => String name of the files classifier
:version => [String, Fixnum, Float] of the version
```
**NOTES**:

* `:remote_url` will be parsed for pom information if it is syntactically correct according to Maven & Nexus standards, as in:
`<NEXUS_URL>/repositories/<NEXUS_REPO>/<groupId>/<artifactId>/<version>/<artifactId>-<version>-<classifier>.<packaging>`
* `:remote_url` takes precedence over coordinates as the upload / download endpoint.
* Usage of `:remote_url` is **NOT RECOMMENDED**
* Order of precedence during generation of pom file:
(groupId & artifactId & packaging & classifier & version) > coordinates > remote_url

### Actions

```ruby
actions :upload, :download, :delete, :delete_url
default_action :upload
```

### Examples

#### 1. Upload a file to Nexus without authentication and without the pom file

```ruby
nexus 'some description' do
use_auth false
upload_pom false

coordinates 'com.gary.image:cloud-img:jar:1.2.0'
local_file '/home/gary/cloud-img-1.2.0.jar'

action :upload
end
```

#### 2. Upload a file to Nexus without using coordinates and overriding Nexus endpoint config

```ruby
nexus 'some description' do
local_file '/home/gary/cloud-img-1.2.0.jar'

nexus_url 'http://mynexus.net/nexus/content/repositories/'
nexus_auth 'gary:secr3t'
nexus_repo 'name_of_repo'

groupId 'com.gary.image'
artifactId 'cloud-img'
packaging 'jar'
classifier 'some_classifier'
version '1.2.0'

action :upload
end
```

#### 3. Upload a file to an exact location on Nexus using remote_url (not recommended)

```ruby
nexus 'some description' do
remote_url 'http://mynexus.net/nexus/content/repositories/com/gary/image/cloud-img/some_folder/bad_practice.jar'
local_file '/home/gary/cloud-img-1.2.0.jar'

action :upload
end
```

#### 4. Download a file from Nexus using coordinates, with another profile

```ruby
nexus 'some description' do
nexus_profile 'gary'
coordinates 'com.gary.image:cloud-img:jar:1.2.0'
local_file '/home/gary/cloud-img-1.2.0.jar'

action :download
end
```

#### 5. Download a file from Nexus using remote_url

```ruby
nexus 'some description' do
remote_url 'http://mynexus.net/nexus/content/repositories/com/gary/image/cloud-img/1.2.0/cloud-img-1.2.0.jar'
local_file '/home/gary/cloud-img-1.2.0.jar'

action :download
end
```

#### 6. Delete an artifact from Nexus

```ruby
nexus 'some description' do
coordinates 'com.gary.image:cloud-img:jar:1.2.0'

action :delete
end
```
**NOTE:** This action does not accept attribute `:remote_url` as it is dangerous to do so. **Ex.** you might delete *ALL* artifacts by accident
**WARNING:** This action will delete the version folder (folder that holds the file), so everything inside it will be deleted as well

#### 7. Delete a file or folder from Nexus (delete folder 1.2.0 in this case)

```ruby
nexus 'some description' do
remote_url 'http://mynexus.net/nexus/content/repositories/com/gary/image/cloud-img/1.2.0/'

action :delete_url
end
```
**NOTE:** This action requires attribute `:remote_url`

## Development

* Source hosted at [GitHub](https://github.com/blackberry/chef-nexus)
* Report issues/questions/feature requests on [GitHub Issues](https://github.com/blackberry/chef-nexus/issues)

Pull requests are very welcome! Make sure your patches are well tested. Ideally create a topic branch for every separate change you make. For example:

1. Fork the repo
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

### Testing

Please test your changes! Here's how:

1. Create and configure `spec/config.rb` from `spec/config_sample.rb`
2. Run `rspec spec/chef/nexus_spec.rb` from your `chef-nexus` folder

If you add new functionality, please create new tests accordingly.

## Authors

Created by [Dongyu 'Gary' Zheng](https://github.com/dongyuzheng) (<[email protected]>)
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
45 changes: 45 additions & 0 deletions chef-nexus.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2016, BlackBerry, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'chef/nexus/version'

Gem::Specification.new do |spec|
spec.name = 'chef-nexus'
spec.version = Chef::Nexus::VERSION
spec.license = 'Apache 2.0'
spec.platform = Gem::Platform::RUBY
spec.extra_rdoc_files = ['README.md', 'LICENSE']

spec.authors = ['Dongyu \'Gary\' Zheng']
spec.email = ['[email protected]']

spec.summary = 'Chef resource for managing artifacts on Nexus by Sonatype'
spec.description = spec.summary
spec.homepage = 'https://github.com/blackberry/chef-nexus'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'chef'
spec.add_dependency 'compat_resource'

spec.add_development_dependency 'bundler', '~> 1.11'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
end
Loading

0 comments on commit b674c22

Please sign in to comment.