terraspace-bundler 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +72 -24
  4. data/lib/terraspace_bundler.rb +1 -0
  5. data/lib/terraspace_bundler/cli/base.rb +9 -1
  6. data/lib/terraspace_bundler/cli/bundle.rb +26 -12
  7. data/lib/terraspace_bundler/cli/help/bundle/info.md +8 -0
  8. data/lib/terraspace_bundler/cli/help/bundle/install.md +1 -1
  9. data/lib/terraspace_bundler/cli/help/bundle/list.md +9 -0
  10. data/lib/terraspace_bundler/cli/help/bundle/update.md +6 -0
  11. data/lib/terraspace_bundler/cli/{clean.rb → purge_cache.rb} +3 -3
  12. data/lib/terraspace_bundler/cli/{install.rb → runner.rb} +1 -1
  13. data/lib/terraspace_bundler/config.rb +15 -2
  14. data/lib/terraspace_bundler/core.rb +9 -4
  15. data/lib/terraspace_bundler/dsl.rb +6 -3
  16. data/lib/terraspace_bundler/dsl/concern.rb +7 -0
  17. data/lib/terraspace_bundler/dsl/syntax.rb +8 -0
  18. data/lib/terraspace_bundler/exporter.rb +47 -0
  19. data/lib/terraspace_bundler/info.rb +25 -0
  20. data/lib/terraspace_bundler/installer.rb +15 -33
  21. data/lib/terraspace_bundler/list.rb +22 -0
  22. data/lib/terraspace_bundler/lockfile.rb +70 -0
  23. data/lib/terraspace_bundler/lockfile/version_comparer.rb +43 -0
  24. data/lib/terraspace_bundler/lockfile/yamler.rb +37 -0
  25. data/lib/terraspace_bundler/logger.rb +0 -20
  26. data/lib/terraspace_bundler/logger/formatter.rb +7 -0
  27. data/lib/terraspace_bundler/mod.rb +31 -63
  28. data/lib/terraspace_bundler/mod/downloader.rb +55 -0
  29. data/lib/terraspace_bundler/mod/{tmp_paths.rb → path_concern.rb} +1 -1
  30. data/lib/terraspace_bundler/mod/props_builder.rb +57 -0
  31. data/lib/terraspace_bundler/mod/props_extension.rb +15 -0
  32. data/lib/terraspace_bundler/mod/registry.rb +8 -6
  33. data/lib/terraspace_bundler/syncer.rb +62 -4
  34. data/lib/terraspace_bundler/terrafile.rb +39 -0
  35. data/lib/terraspace_bundler/util/git.rb +31 -0
  36. data/lib/terraspace_bundler/{logging.rb → util/logging.rb} +1 -1
  37. data/lib/terraspace_bundler/version.rb +1 -1
  38. data/spec/fixtures/Terrafile +2 -2
  39. data/spec/terraform_bundler/runner_spec.rb +17 -0
  40. metadata +24 -17
  41. data/lib/terraspace_bundler/cli/update.rb +0 -7
  42. data/lib/terraspace_bundler/helper/git.rb +0 -21
  43. data/lib/terraspace_bundler/mod/export.rb +0 -23
  44. data/lib/terraspace_bundler/mod/locked.rb +0 -48
  45. data/lib/terraspace_bundler/mod/sync.rb +0 -53
  46. data/lib/terraspace_bundler/setup.rb +0 -20
  47. data/lib/terraspace_bundler/updater.rb +0 -49
  48. data/lib/terraspace_bundler/updater/lockfile.rb +0 -48
  49. data/lib/terraspace_bundler/util/registry.rb +0 -24
  50. data/spec/terraform_bundler/installer_spec.rb +0 -16
@@ -1,48 +0,0 @@
1
- class TerraspaceBundler::Mod
2
- class Locked
3
- include TB::Util::Registry
4
-
5
- attr_reader :name, :path, :source, :version
6
- def initialize(name, info)
7
- @name, @info = name.to_s, info
8
-
9
- @path = @info[:path]
10
- @version = @info[:version]
11
- end
12
-
13
- def source
14
- @info[:source]
15
- end
16
-
17
- def org
18
- obtain_org(source)
19
- end
20
-
21
- def repo
22
- s = registry?(source) ? registry_github : source
23
- File.basename(s)
24
- end
25
-
26
- def full_repo
27
- "#{org}/#{repo}"
28
- end
29
-
30
- def to_mod
31
- # copy all props in Terrafile.lock
32
- options = @info.clone
33
- # add org
34
- options.merge!(org: @org)
35
-
36
- data = {
37
- args: @name,
38
- options: options,
39
- }
40
- TB::Mod.new(data) # no need for global, info in the lockfile is enough
41
- end
42
-
43
- def export
44
- export = Export.new(self)
45
- export.run
46
- end
47
- end
48
- end
@@ -1,53 +0,0 @@
1
- class TerraspaceBundler::Mod
2
- class Sync
3
- extend Memoist
4
- include TB::Helper::Git
5
- include TB::Logging
6
- include TB::Mod::TmpPaths
7
-
8
- attr_reader :sha
9
- def initialize(mod, url)
10
- @mod, @url = mod, url
11
- end
12
-
13
- def run
14
- setup_tmp
15
- org_path = "#{cache_root}/#{@mod.org}"
16
- FileUtils.mkdir_p(org_path)
17
- Dir.chdir(org_path) do
18
- name = File.basename(@url).sub('.git','')
19
- unless File.exist?(name)
20
- sh "git clone #{@url}"
21
- end
22
-
23
- Dir.chdir(name) do
24
- git "pull"
25
- git "submodule update --init"
26
- stage(name)
27
- end
28
- end
29
- end
30
-
31
- def stage(name)
32
- copy_to_stage(name)
33
- switch_to_specific_version(name)
34
- end
35
-
36
- def switch_to_specific_version(name)
37
- stage_path = stage_path("#{@mod.org}/#{name}")
38
- logger.debug "Within: #{stage_path}"
39
- Dir.chdir(stage_path) do
40
- git "checkout #{@mod.checkout_version}" if @mod.checkout_version
41
- @sha = git("rev-parse HEAD").strip
42
- end
43
- end
44
-
45
- def copy_to_stage(name)
46
- cache_path = cache_path("#{@mod.org}/#{name}")
47
- stage_path = stage_path("#{@mod.org}/#{name}")
48
- FileUtils.rm_rf(stage_path)
49
- FileUtils.mkdir_p(File.dirname(stage_path))
50
- FileUtils.cp_r(cache_path, stage_path)
51
- end
52
- end
53
- end
@@ -1,20 +0,0 @@
1
- module TerraspaceBundler
2
- class Setup
3
- def initialize(options={})
4
- @options = options
5
- end
6
-
7
- def setup!
8
- # Run the DSL to possibly override the config defaults
9
- meta = Dsl.new.run
10
- export_path = meta[:global][:export_path]
11
- TB.config.export_path = export_path if export_path
12
-
13
- # cli --terrafile option
14
- if @options[:terrafile]
15
- TB.config.terrafile = @options[:terrafile]
16
- TB.config.lockfile = "#{@options[:terrafile]}.lock"
17
- end
18
- end
19
- end
20
- end
@@ -1,49 +0,0 @@
1
- module TerraspaceBundler
2
- class Updater
3
- include Logging
4
-
5
- def initialize(options={})
6
- @options = options
7
- @mod_name = @options[:mod]
8
- end
9
-
10
- def run(without_install: false)
11
- Setup.new(@options).setup!
12
- puts "Bundling modules from #{TB.config.terrafile}..."
13
-
14
- if update_one?
15
- update_one
16
- else
17
- update_all
18
- end
19
- unless without_install
20
- Installer.new(@options.merge(download: false)).run
21
- end
22
- end
23
-
24
- def update_one?
25
- @mod_name && File.exist?(TB.config.lockfile)
26
- end
27
-
28
- def update_one
29
- meta = Dsl.new.run
30
- mods = meta[:mods].map { |data| Mod.new(data, meta[:global]) }
31
- mod = mods.find { |m| m.name == @mod_name }
32
- unless mod
33
- logger.error "No module #{@mod_name} found in your Terrafile"
34
- exit 1
35
- end
36
- mod.sync
37
- Lockfile.new.update_one(mod)
38
- end
39
-
40
- def update_all
41
- meta = Dsl.new.run
42
- mods = meta[:mods].map { |data| Mod.new(data, meta[:global]) }
43
- mods.each do |mod|
44
- mod.sync
45
- end
46
- Lockfile.new(mods).create
47
- end
48
- end
49
- end
@@ -1,48 +0,0 @@
1
- require "yaml"
2
-
3
- class TerraspaceBundler::Updater
4
- class Lockfile
5
- include TB::Logging
6
-
7
- def initialize(mods=[])
8
- @mods = mods
9
- end
10
-
11
- def create
12
- data = {}
13
- @mods.each do |mod|
14
- data.merge!(item(mod))
15
- end
16
- write(data)
17
- end
18
-
19
- def item(mod)
20
- props = {
21
- path: mod.path,
22
- sha: mod.sha,
23
- source: mod.source,
24
- url: mod.url,
25
- version: mod.version,
26
- }
27
- props.delete_if { |k,v| v.nil? }
28
- { mod.name => props }
29
- end
30
-
31
- def update_one(mod)
32
- data = YAML.load_file(lockfile)
33
- data.merge!(item(mod))
34
- write(data, ": #{mod.name}")
35
- end
36
-
37
- def write(data, message="")
38
- content = YAML.dump(data.deep_stringify_keys)
39
- action = File.exist?(lockfile) ? "Updated" : "Created"
40
- IO.write(lockfile, content)
41
- logger.info "#{action} #{lockfile}#{message}"
42
- end
43
-
44
- def lockfile
45
- TB.config.lockfile
46
- end
47
- end
48
- end
@@ -1,24 +0,0 @@
1
- module TerraspaceBundler::Util
2
- module Registry
3
- extend Memoist
4
-
5
- def registry?(url)
6
- !url.nil? && url.split('/').size == 3
7
- end
8
-
9
- def registry_github
10
- TB::Mod::Registry.new(self).to_github
11
- end
12
- memoize :registry_github
13
-
14
- def obtain_org(source_option, global_org=nil)
15
- source = registry?(source_option) ? registry_github : source_option
16
- parts = source.split('/') # IE: git@github.com:boltopspro/terraform-google-vm
17
- if parts.size == 1
18
- global_org
19
- else
20
- parts[-2..-2].first
21
- end
22
- end
23
- end
24
- end
@@ -1,16 +0,0 @@
1
- describe TB::Installer do
2
- let(:installer) { described_class.new }
3
-
4
- context "installer" do
5
- # hacky sanity check
6
- it "run" do
7
- FileUtils.rm_f("tmp/Terrafile.lock")
8
- FileUtils.mkdir_p("tmp")
9
- Dir.chdir("tmp")
10
- TB.config.terrafile = "spec/fixtures/Terrafile"
11
- installer.run
12
- file_exist = File.exist?("Terrafile.lock")
13
- expect(file_exist).to be true
14
- end
15
- end
16
- end