Skip to content

Commit

Permalink
Merge pull request #32 from ZeroPointEnergy/feature/task_configuration
Browse files Browse the repository at this point in the history
Make it possible to configure the tasks in the rakefile
  • Loading branch information
bastelfreak authored May 29, 2019
2 parents b3955a7 + 3980243 commit 4e29992
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 210 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,34 @@ Add the following line to your `Gemfile`:
gem 'ra10ke'
```

Add the following line in your `Rakefile`:
Add the following lines in your `Rakefile`:

```ruby
require 'ra10ke'
Ra10ke::RakeTask.new
```

## Configuration

You can configure the tasks in a block:

```ruby
Ra10ke::RakeTask.new do |t|
t.basedir = File.join(Dir.pwd, 'some_dir')
t.moduledir = File.join(Dir.pwd, 'some_dir/strange_module_dir')
end
```

Available settings are:

| Setting | Documentation |
|-----------------|-----------------------------------------------------------------------------------------------|
| basedir | Base directory with the Puppetfile and modules directory (Default: Same directory as Rakefile)|
| moduledir | Directory to install the modules in (Default: 'modules' in basedir) |
| puppetfile_path | Directroy where the Puppetfile is (Default: basedir) |
| puppetfile_name | The Puppetfile name (Default: basedir/Puppetfile) |
| force | Overwrite locally changed files on install (Default: false) |

## Rake tasks

### r10k:syntax
Expand Down
44 changes: 24 additions & 20 deletions lib/ra10ke.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,29 @@

module Ra10ke
class RakeTask < ::Rake::TaskLib
include Ra10ke::Solve

attr_accessor :basedir, :moduledir, :puppetfile_path, :puppetfile_name, :force

def initialize(*args)
@basedir = Dir.pwd
@moduledir = nil
@puppetfile_path = nil
@puppetfile_name = nil
@force = nil

yield(self) if block_given?

namespace :r10k do
define_task_solve_dependencies(*args)

desc "Print outdated forge modules"
task :dependencies do
require 'r10k/puppetfile'
require 'puppet_forge'

PuppetForge.user_agent = "ra10ke/#{Ra10ke::VERSION}"
puppetfile = R10K::Puppetfile.new(Dir.pwd)
puppetfile = get_puppetfile
puppetfile.load!
PuppetForge.host = puppetfile.forge if puppetfile.forge =~ /^http/

Expand Down Expand Up @@ -81,9 +95,9 @@ def initialize(*args)
require 'r10k/action/puppetfile/check'

puppetfile = R10K::Action::Puppetfile::Check.new({
:root => Dir.pwd,
:moduledir => nil,
:puppetfile => nil
:root => @basedir,
:moduledir => @moduledir,
:puppetfile => @puppetfile_path
}, '')

unless puppetfile.call
Expand All @@ -92,22 +106,10 @@ def initialize(*args)
end

desc "Install modules specified in Puppetfile"
task :install, [:path] do |_, args|
task :install do
require 'r10k/puppetfile'
require 'pathname'

if !args.has_key?(:path)
raise "task requires 'path' argument"
end
modpath = Pathname.new args[:path]

if !modpath.absolute?
modpath = Pathname.new(Dir.pwd) + modpath
end

puppetfile_dir = Pathname.new Dir.pwd
modules_dir = File.join(puppetfile_dir, modpath.relative_path_from(puppetfile_dir))
puppetfile = R10K::Puppetfile.new(puppetfile_dir, modules_dir)
puppetfile = get_puppetfile
puppetfile.load!

puts "Processing Puppetfile for fixtures"
Expand All @@ -132,7 +134,9 @@ def initialize(*args)

end
end

def get_puppetfile
R10K::Puppetfile.new(@basedir, @moduledir, @puppetfile_path, @puppetfile_name, @force)
end
end
end

Ra10ke::RakeTask.new
Loading

0 comments on commit 4e29992

Please sign in to comment.