Skip to content

Commit c5fdef7

Browse files
committed
updates
1 parent 6eebbef commit c5fdef7

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

Gemfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
source 'https://gem.coop'
22

3-
gem 'rake'
4-
gem 'puppetfile-resolver'
5-
gem 'puppet_forge'
6-
gem 'pry'
7-
3+
gemspec

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
# puppetfile-source-dereference
2-
Replaces forge references with the git source in a Puppetfile
1+
# Puppetfile Source Dereference
2+
3+
This is a simple tool to replace forge references with the git source in a Puppetfile.
4+
The intent is to reduce your dependency on the Puppet Forge in cases of service interruptions.
5+
6+
The simplest use case is to simply run the tool in the root directory of a Puppet module.
7+
It will generate a `Puppetfile.out`, which you will need to inspect and clean up.
8+
9+
Comments and formatting will not be preserved, you'll need to reconcile that.
10+
11+
> ⚠️ There is not a standard mapping of Forge release versions to git ref (branch, tag, etc).
12+
> This tool will take a very simplistic guess at the ref, but many modules will be wrong.
13+
> You'll need to use your human brain and look at the module repo and decide which ref to use.
14+

lib/puppetfile-source-dereference.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require "puppetfile-resolver/puppetfile/parser/r10k_eval"
44
require 'puppet_forge'
55
require 'yaml'
6+
require 'open-uri'
67

78
class PuppetfileSourceDereference
89
attr_accessor :source, :output, :dryrun, :mapping
@@ -17,7 +18,7 @@ def initialize(options = {})
1718

1819
def resolve
1920
puppetfile = PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(File.read(@source))
20-
mapping = YAML.load(open(@mapping).read)
21+
mapping = YAML.load(URI.open(@mapping).read)
2122

2223
unless puppetfile.valid?
2324
logger.error("Puppetfile source is not valid")
@@ -40,7 +41,7 @@ def resolve
4041
output.write <<~EOF
4142
mod '#{mod.title}',
4243
:git => '#{source}',
43-
:ref => '#{mod.version.delete_prefix('=')}'
44+
:ref => '#{mod.version.delete_prefix('=')}' # check the source repo and fix this ref
4445
EOF
4546
else
4647
output.write <<~EOF
@@ -49,7 +50,7 @@ def resolve
4950
EOF
5051
end
5152
else
52-
output.write "mod '#{mod.title}', #{version}\n"
53+
output.write "mod '#{mod.title}', #{version} # unmapped entry!\n"
5354
end
5455
end
5556
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
$:.unshift File.expand_path("../lib", __FILE__)
2+
require 'date'
3+
require 'puppetfile-source-dereference/version'
4+
5+
Gem::Specification.new do |s|
6+
s.name = "puppetfile-source-dereference"
7+
s.version = PuppetfileSourceDereference::VERSION
8+
s.date = Date.today.to_s
9+
s.summary = "Replaces forge references in a Puppetfile with the git source."
10+
s.homepage = "https://github.com/overlookinfra/puppetfile-source-dereference/"
11+
s.email = "[email protected]"
12+
s.authors = ["Ben Ford"]
13+
s.license = "GPL-3.0"
14+
s.require_path = "lib"
15+
s.executables = %w( puppetfile-source-dereference )
16+
s.files = %w( README.md LICENSE )
17+
s.files += Dir.glob("lib/**/*")
18+
s.files += Dir.glob("bin/**/*")
19+
s.add_dependency 'puppetfile-resolver', '~> 0.5.0'
20+
21+
s.description = <<-desc
22+
This will replace all Forge entries in a Puppetfile with git sources if the
23+
pubished module has `source` defined.
24+
desc
25+
end

0 commit comments

Comments
 (0)