cloudspin-stack 0.1.24 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 586fc640e354ca3c09ebc11b5035c9584594e5d0
4
- data.tar.gz: af64f4b5d2b8a427e3f896ce4e507d23527b17c1
2
+ SHA256:
3
+ metadata.gz: 4f264c24f8c189e2911364446d2e52424b858f7f652894accc71d9793cb3786c
4
+ data.tar.gz: 6e18307aaf5df5233599443d14eccc1f7a05d1f91735a95b6ba2494cc2bc741a
5
5
  SHA512:
6
- metadata.gz: 72a5152109bc76d62c1e3b020f0c4be3f4d1257ffcae629ceafd4868e48dc6bfbf786e03fac7bd917d0c7f02cc4f96f3bf2d68664fe5a886a1d5d3cc8d8cf3b0
7
- data.tar.gz: d4181f71d9ad923c32a268b15ad9da4fbee110946fbe9dd851a9a84afc7fe99c774b764320ab1320c687c82d5e54fb8e57f69d0dd4d5a18a799283a7094be6b3
6
+ metadata.gz: 61bb3efbd60147ca0017cb37a514d3e5c4669ec2b5790c48c9b9448a96d749ccb002ada8adef9cf6156867cd5b451e75174fefcd52f4eca93dd2d91c8455449e
7
+ data.tar.gz: f5c0104a653960c391a8580134a9d22f2cc98de89b27e16c67a886258fa1e01c598120837cb5c157461973fce7cbf228f34d83abc65273865a915e4d57e42a1f
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/.travis.yml CHANGED
@@ -1,5 +1,12 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.3
5
- before_install: gem install bundler -v 1.16.2
4
+ - 2.5.1
5
+ before_install:
6
+ - curl -sLo /tmp/terraform.zip https://releases.hashicorp.com/terraform/0.11.10/terraform_0.11.10_linux_amd64.zip
7
+ - unzip /tmp/terraform.zip -d /tmp
8
+ - mkdir -p ~/bin
9
+ - mv /tmp/terraform ~/bin
10
+ - chmod 0755 ~/bin/terraform
11
+ - export PATH="~/bin:$PATH"
12
+ - gem install bundler -v 1.17.1
@@ -25,8 +25,10 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_dependency 'ruby-terraform'
27
27
  spec.add_dependency 'thor'
28
+ spec.add_dependency 'rubyzip'
28
29
 
29
30
  spec.add_development_dependency 'bundler'
30
31
  spec.add_development_dependency 'rake'
31
32
  spec.add_development_dependency 'rspec'
33
+ spec.add_development_dependency 'webmock'
32
34
  end
@@ -15,7 +15,7 @@ module Cloudspin
15
15
  end
16
16
 
17
17
  def self.from_file(specfile)
18
- raise NoStackDefinitionConfigurationFileError, specfile unless File.exists?(specfile)
18
+ raise NoStackDefinitionConfigurationFileError, "Did not find file '#{specfile}'" unless File.exists?(specfile)
19
19
  source_path = File.dirname(specfile)
20
20
  spec_hash = YAML.load_file(specfile)
21
21
  self.new(
@@ -25,13 +25,18 @@ module Cloudspin
25
25
  )
26
26
  end
27
27
 
28
- def self.from_folder(definition_folder)
29
- from_file("#{definition_folder}/stack-definition.yaml")
28
+ def self.from_location(definition_location, definition_cache_folder: '.cloudspin/definitions')
29
+ if RemoteDefinition.is_remote?(definition_location)
30
+ # puts "INFO: Downloading remote stack definition"
31
+ from_file(RemoteDefinition.new(definition_location).fetch(definition_cache_folder))
32
+ else
33
+ # puts "INFO: Using local stack definition source"
34
+ from_file(definition_location)
35
+ end
30
36
  end
31
37
 
32
38
  end
33
39
 
34
-
35
40
  class NoStackDefinitionConfigurationFileError < StandardError; end
36
41
 
37
42
  end
@@ -27,14 +27,14 @@ module Cloudspin
27
27
  def self.from_folder(
28
28
  *instance_configuration_files,
29
29
  stack_name: nil,
30
- definition_folder:,
30
+ definition_location:,
31
31
  base_folder: '.',
32
32
  base_working_folder:
33
33
  )
34
34
  self.from_files(
35
35
  instance_configuration_files,
36
36
  stack_name: stack_name,
37
- stack_definition: Definition.from_folder(definition_folder),
37
+ stack_definition: Definition.from_location(definition_location),
38
38
  base_folder: base_folder,
39
39
  base_working_folder: base_working_folder
40
40
  )
@@ -140,6 +140,18 @@ module Cloudspin
140
140
  "cd #{working_folder} && #{built_command.to_s}"
141
141
  end
142
142
 
143
+ def refresh
144
+ RubyTerraform.clean(directory: working_folder)
145
+ mkdir_p File.dirname(working_folder)
146
+ cp_r @stack_definition.source_path, working_folder
147
+ ensure_state_folder
148
+ Dir.chdir(working_folder) do
149
+ terraform_init
150
+ RubyTerraform.refresh(terraform_command_parameters(force: true))
151
+ end
152
+ end
153
+
154
+
143
155
  def terraform_init
144
156
  RubyTerraform.init(terraform_init_params)
145
157
  end
@@ -24,7 +24,6 @@ module Cloudspin
24
24
  @stack_definition = stack_definition
25
25
  @stack_name = stack_name || stack_definition.name
26
26
  @base_folder = base_folder
27
-
28
27
  @instance_values = configuration_values['instance'] || {}
29
28
  @parameter_values = configuration_values['parameters'] || {}
30
29
  @resource_values = configuration_values['resources'] || {}
@@ -45,6 +44,7 @@ module Cloudspin
45
44
  )
46
45
  configuration_values = {}
47
46
  configuration_files.flatten.each { |config_file|
47
+ # puts "DEBUG: Reading configuration file: #{config_file}"
48
48
  configuration_values = configuration_values.deep_merge(yaml_file_to_hash(config_file))
49
49
  }
50
50
  self.new(
@@ -59,6 +59,7 @@ module Cloudspin
59
59
  if File.exists?(yaml_file)
60
60
  YAML.load_file(yaml_file) || {}
61
61
  else
62
+ puts "No configuration file: #{yaml_file}"
62
63
  {}
63
64
  end
64
65
  end
@@ -0,0 +1,79 @@
1
+ require 'net/http'
2
+ require 'zip'
3
+
4
+ module Cloudspin
5
+ module Stack
6
+ class RemoteDefinition
7
+
8
+ def initialize(definition_location)
9
+ @definition_location = definition_location
10
+ end
11
+
12
+ def self.is_remote?(definition_location)
13
+ /^http.*\.zip$/.match definition_location
14
+ end
15
+
16
+ def fetch(local_folder)
17
+ unpack(download_artefact(@definition_location), local_folder)
18
+ end
19
+
20
+ def download_artefact(artefact_url)
21
+ download_dir = Dir.mktmpdir(['cloudspin-', '-download'])
22
+ zipfile = "#{download_dir}/undetermined-spin-stack-artefact.zip"
23
+ download_file(artefact_url, zipfile)
24
+ end
25
+
26
+ def download_file(remote_file, local_file)
27
+ remote_file_uri = URI(remote_file)
28
+ Net::HTTP.start(remote_file_uri.host, remote_file_uri.port) do |remote|
29
+ response = remote.get(remote_file_uri)
30
+ open(local_file, 'wb') do |local|
31
+ local.write(response.body)
32
+ end
33
+ end
34
+ local_file
35
+ end
36
+
37
+ def unpack(zipfile, where_to_put_it)
38
+ folder_name = path_of_source_in(zipfile)
39
+ # puts "DEBUG: Unzipping #{zipfile} to #{where_to_put_it}"
40
+ clear_folder(where_to_put_it)
41
+ Zip::File.open(zipfile) { |zip_file|
42
+ zip_file.each { |f|
43
+ # puts "-> #{f.name}"
44
+ f_path = File.join(where_to_put_it, f.name)
45
+ FileUtils.mkdir_p(File.dirname(f_path))
46
+ # puts "DEBUG: Extracting #{f} to #{f_path}"
47
+ zip_file.extract(f, f_path) unless File.exist?(f_path)
48
+ }
49
+ }
50
+ raise MissingStackDefinitionConfigurationFileError unless File.exists? "#{where_to_put_it}/#{folder_name}/stack-definition.yaml"
51
+ "#{where_to_put_it}/#{folder_name}/stack-definition.yaml"
52
+ end
53
+
54
+ def clear_folder(folder_to_clear)
55
+ FileUtils.remove_entry_secure(folder_to_clear)
56
+ end
57
+
58
+ def path_of_source_in(zipfile_path)
59
+ File.dirname(path_of_configuration_file_in(zipfile_path))
60
+ end
61
+
62
+ def path_of_configuration_file_in(zipfile_path)
63
+ zipfile = Zip::File.open(zipfile_path)
64
+ begin
65
+ zipfile.entries.select { |entry|
66
+ /^stack-definition.yaml$/.match entry.name
67
+ }.first.name
68
+ ensure
69
+ zipfile.close
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ class MissingStackDefinitionConfigurationFileError < StandardError; end
76
+
77
+ end
78
+ end
79
+
@@ -1,5 +1,5 @@
1
1
  module Cloudspin
2
2
  module Stack
3
- VERSION = '0.1.24'
3
+ VERSION = '0.1.25'
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require 'cloudspin/stack/version'
2
+ require 'cloudspin/stack/remote_definition'
2
3
  require 'cloudspin/stack/definition'
3
4
  require 'cloudspin/stack/instance_configuration'
4
5
  require 'cloudspin/stack/instance'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudspin-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.24
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - 'kief '
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-28 00:00:00.000000000 Z
11
+ date: 2018-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-terraform
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubyzip
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description:
84
112
  email:
85
113
  - cloudspin@kief.com
@@ -90,6 +118,7 @@ extra_rdoc_files: []
90
118
  files:
91
119
  - ".gitignore"
92
120
  - ".rspec"
121
+ - ".ruby-version"
93
122
  - ".travis.yml"
94
123
  - CODE_OF_CONDUCT.md
95
124
  - Gemfile
@@ -105,6 +134,7 @@ files:
105
134
  - lib/cloudspin/stack/definition.rb
106
135
  - lib/cloudspin/stack/instance.rb
107
136
  - lib/cloudspin/stack/instance_configuration.rb
137
+ - lib/cloudspin/stack/remote_definition.rb
108
138
  - lib/cloudspin/stack/version.rb
109
139
  homepage: https://github.com/cloudspinners
110
140
  licenses:
@@ -126,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
156
  version: '0'
127
157
  requirements: []
128
158
  rubyforge_project:
129
- rubygems_version: 2.6.14
159
+ rubygems_version: 2.7.6
130
160
  signing_key:
131
161
  specification_version: 4
132
162
  summary: Classes to manage instances of an infrastructure stack using Terraform