pi_build_modifier 0.3.0.pre.alpha → 0.3.1.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +24 -12
  3. data/.travis.yml +26 -4
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/LICENSE +21 -0
  6. data/README.md +208 -2
  7. data/Rakefile +134 -6
  8. data/Vagrantfile +27 -0
  9. data/docs/concept.md +27 -0
  10. data/docs/incubation.md +38 -0
  11. data/pi_build_modifier/.gitignore +12 -0
  12. data/{.rspec → pi_build_modifier/.rspec} +0 -0
  13. data/{Gemfile → pi_build_modifier/Gemfile} +0 -0
  14. data/{LICENSE.txt → pi_build_modifier/LICENSE.txt} +1 -1
  15. data/pi_build_modifier/README.md +3 -0
  16. data/pi_build_modifier/Rakefile +13 -0
  17. data/{bin → pi_build_modifier/bin}/pi_build_modifier +1 -1
  18. data/{lib → pi_build_modifier/lib}/pi_build_modifier/boot-files/boot.rb +1 -1
  19. data/{lib → pi_build_modifier/lib}/pi_build_modifier/boot-files/templates/07-resize-init.diff.erb +0 -0
  20. data/{lib → pi_build_modifier/lib}/pi_build_modifier/config/logex.rb +1 -1
  21. data/{lib → pi_build_modifier/lib}/pi_build_modifier/locale/locale_debconf.rb +1 -1
  22. data/{lib → pi_build_modifier/lib}/pi_build_modifier/locale/templates/00-debconf.erb +1 -1
  23. data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier/erb_mapper.rb +1 -1
  24. data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier/mapper.rb +1 -1
  25. data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier/pi_modifier.rb +1 -1
  26. data/{lib → pi_build_modifier/lib}/pi_build_modifier/modifier_task.rb +10 -3
  27. data/{lib → pi_build_modifier/lib}/pi_build_modifier/net-tweaks/templates/wpa_supplicant.conf.erb +0 -0
  28. data/{lib → pi_build_modifier/lib}/pi_build_modifier/net-tweaks/wifi_network.rb +1 -1
  29. data/{lib → pi_build_modifier/lib}/pi_build_modifier/sys_tweaks/run_modifier.rb +1 -1
  30. data/{lib → pi_build_modifier/lib}/pi_build_modifier/sys_tweaks/ssh.rb +1 -1
  31. data/{lib → pi_build_modifier/lib}/pi_build_modifier/sys_tweaks/templates/ssh.sh.erb +0 -0
  32. data/{lib → pi_build_modifier/lib}/pi_build_modifier/system/system_type.rb +1 -1
  33. data/{lib → pi_build_modifier/lib}/pi_build_modifier/version.rb +2 -2
  34. data/{lib → pi_build_modifier/lib}/pi_build_modifier.rb +4 -1
  35. data/{pi_build_modifier.gemspec → pi_build_modifier/pi_build_modifier.gemspec} +7 -7
  36. data/pi_build_modifier/spec/fixtures/config.json +26 -0
  37. data/pi_build_modifier/spec/pi_build_modifier/boot/boot_spec.rb +103 -0
  38. data/pi_build_modifier/spec/pi_build_modifier/locale/locale_spec.rb +87 -0
  39. data/pi_build_modifier/spec/pi_build_modifier/modifier/mapper_spec.rb +105 -0
  40. data/pi_build_modifier/spec/pi_build_modifier/modifier/modifier_spec.rb +83 -0
  41. data/pi_build_modifier/spec/pi_build_modifier/modifier_task_spec.rb +63 -0
  42. data/pi_build_modifier/spec/pi_build_modifier/net-tweaks/wifi_network_spec.rb +91 -0
  43. data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/run_modifier_spec.rb +74 -0
  44. data/pi_build_modifier/spec/pi_build_modifier/sys_tweaks/ssh_spec.rb +73 -0
  45. data/pi_build_modifier/spec/pi_build_modifier/system/system_spec.rb +66 -0
  46. data/pi_build_modifier/spec/pi_build_modifier_spec.rb +73 -0
  47. data/pi_build_modifier/spec/spec_helper.rb +10 -0
  48. data/pi_customizer/.rspec +2 -0
  49. data/pi_customizer/Gemfile +3 -0
  50. data/pi_customizer/LICENSE +21 -0
  51. data/pi_customizer/README.md +3 -0
  52. data/pi_customizer/Rakefile +13 -0
  53. data/pi_customizer/Vagrantfile +16 -0
  54. data/pi_customizer/bin/pi_customizer +25 -0
  55. data/pi_customizer/envs/aws/outputs.tf +3 -0
  56. data/pi_customizer/envs/aws/pi-build-env.tf +160 -0
  57. data/pi_customizer/envs/aws/variables.tf +55 -0
  58. data/pi_customizer/envs/docker/Dockerfile +6 -0
  59. data/pi_customizer/envs/sh/build-pi-img.sh +28 -0
  60. data/pi_customizer/lib/pi_customizer/build/builder/build_executor.rb +149 -0
  61. data/pi_customizer/lib/pi_customizer/build/builder/builder.rb +59 -0
  62. data/pi_customizer/lib/pi_customizer/build/builder/prepare_start_execute_builder.rb +43 -0
  63. data/pi_customizer/lib/pi_customizer/build/builder/start_prepare_execute_builder.rb +43 -0
  64. data/pi_customizer/lib/pi_customizer/build/environment/aws/aws.rb +76 -0
  65. data/pi_customizer/lib/pi_customizer/build/environment/docker/docker.rb +94 -0
  66. data/pi_customizer/lib/pi_customizer/build/environment/environment.rb +73 -0
  67. data/pi_customizer/lib/pi_customizer/build/environment/environment_builder_factory.rb +81 -0
  68. data/pi_customizer/lib/pi_customizer/build/environment/vagrant/templates/Vagrantfile.erb +61 -0
  69. data/pi_customizer/lib/pi_customizer/build/environment/vagrant/vagrant.rb +77 -0
  70. data/pi_customizer/lib/pi_customizer/build/environment/vagrant/vagrant_file.rb +95 -0
  71. data/pi_customizer/lib/pi_customizer/build/workspace/local_workspace.rb +92 -0
  72. data/pi_customizer/lib/pi_customizer/build/workspace/remote_workspace.rb +79 -0
  73. data/pi_customizer/lib/pi_customizer/utils/logex.rb +25 -0
  74. data/pi_customizer/lib/pi_customizer/version.rb +27 -0
  75. data/pi_customizer/lib/pi_customizer/write/image_writer.rb +67 -0
  76. data/pi_customizer/lib/pi_customizer.rb +84 -0
  77. data/pi_customizer/pi_customizer.gemspec +30 -0
  78. data/pi_customizer/spec/fixtures/TestVagrantfile +61 -0
  79. data/pi_customizer/spec/fixtures/image.img +1 -0
  80. data/pi_customizer/spec/fixtures/image.zip +0 -0
  81. data/pi_customizer/spec/pi_customizer/builder/build_executor_spec.rb +64 -0
  82. data/pi_customizer/spec/pi_customizer/environment/aws_spec.rb +57 -0
  83. data/pi_customizer/spec/pi_customizer/environment/environment_builder_factory_spec.rb +48 -0
  84. data/pi_customizer/spec/pi_customizer/environment/environment_spec.rb +75 -0
  85. data/pi_customizer/spec/pi_customizer/environment/vagrant/vagrant_file_spec.rb +63 -0
  86. data/pi_customizer/spec/pi_customizer/environment/vagrant/vagrant_spec.rb +41 -0
  87. data/pi_customizer/spec/pi_customizer/version_spec.rb +29 -0
  88. data/pi_customizer/spec/pi_customizer/workspace/local_workspace_spec.rb +74 -0
  89. data/pi_customizer/spec/pi_customizer/workspace/remote_workspace_spec.rb +51 -0
  90. data/pi_customizer/spec/pi_customizer/write/image_writer_spec.rb +59 -0
  91. data/pi_customizer/spec/pi_customizer_spec.rb +93 -0
  92. data/pi_customizer/spec/spec_helper.rb +10 -0
  93. data/version.rb +21 -0
  94. metadata +106 -41
@@ -0,0 +1,91 @@
1
+ # Copyright (c) 2017-2019 Beate Ottenwälder
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative '../../spec_helper'
22
+ require 'rspec'
23
+ require 'fileutils'
24
+ require 'pi_build_modifier/net-tweaks/wifi_network'
25
+ require 'pi_build_modifier/modifier/erb_mapper'
26
+ require 'pi_build_modifier/modifier/pi_modifier'
27
+
28
+
29
+ RSpec.describe PiBuildModifier::WPASupplicant do
30
+
31
+ let(:empty_json_config) {'config_empty.json'}
32
+ let(:json_config) {'config_full.json'}
33
+ let(:workspace) {File.dirname(__FILE__) + '/workspace'}
34
+
35
+ before do
36
+ FileUtils.mkdir_p workspace
37
+ File.open(empty_json_config, 'w') {|file| file.write('{}')}
38
+ File.open(json_config, 'w') {|file| file.write(' {"wifi" : {
39
+ "wpa_country" : "DE_test",
40
+ "networks": [
41
+ {
42
+ "ssid": "test_wpsk",
43
+ "wpsk": "test_wpsk"
44
+ }
45
+ ]
46
+ }
47
+ }
48
+ ')}
49
+ end
50
+
51
+ after do
52
+ FileUtils.rm(empty_json_config)
53
+ FileUtils.rm(json_config)
54
+ FileUtils.rm_rf workspace
55
+ end
56
+
57
+ it 'should create a default wpa_supplicant.config when no change is specified in the json configuration file' do
58
+
59
+ #Given
60
+ modifier = PiBuildModifier::PiModifier.new
61
+ wpa_supplicant = PiBuildModifier::WPASupplicant.new
62
+ mapper = PiBuildModifier::ERBMapper.new(wpa_supplicant, workspace)
63
+
64
+ #When
65
+ modifier.with_json_configuration(empty_json_config)
66
+ modifier.with_mapper(mapper)
67
+ modifier.modify
68
+
69
+ #Then
70
+ expect(Pathname.new(workspace + '/' + wpa_supplicant.relative_output_path)).to be_file
71
+ end
72
+
73
+ it 'should create a wpa_supplicant.config with all changes that are specified in the json configuration file' do
74
+
75
+ #Given
76
+ modifier = PiBuildModifier::PiModifier.new
77
+ wpa_supplicant = PiBuildModifier::WPASupplicant.new
78
+ mapper = wpa_supplicant.mapper(workspace)
79
+
80
+ #When
81
+ modifier.with_json_configuration(json_config)
82
+ modifier.with_mapper(mapper)
83
+ modifier.modify
84
+
85
+ #Then
86
+ wpa_supplicant_file = File.read(workspace + '/' + wpa_supplicant.relative_output_path)
87
+ expect(wpa_supplicant_file).to match(/network/)
88
+ end
89
+
90
+ end
91
+
@@ -0,0 +1,74 @@
1
+ # Copyright (c) 2017-2019 Beate Ottenwälder
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative '../../spec_helper'
22
+ require 'rspec'
23
+ require 'fileutils'
24
+ require 'pi_build_modifier/sys_tweaks/run_modifier'
25
+ require 'pi_build_modifier/modifier/pi_modifier'
26
+ require 'pi_build_modifier/modifier/mapper'
27
+
28
+ RSpec.describe PiBuildModifier::RunModifier do
29
+
30
+ let(:workspace) {File.dirname(__FILE__) + '/workspace'}
31
+
32
+ before do
33
+ FileUtils.mkdir_p workspace
34
+ end
35
+
36
+ after do
37
+ FileUtils.rm_rf workspace
38
+ end
39
+
40
+ it 'should be of type Mapper' do
41
+ expect(PiBuildModifier::RunModifier.new).to be_a PiBuildModifier::Mapper
42
+ end
43
+
44
+ it 'should append lines to the 01-run.sh file' do
45
+
46
+ #Given
47
+ modifier = PiBuildModifier::RunModifier.new.mapper(workspace)
48
+ FileUtils.mkdir_p File.dirname(workspace + '/' + modifier.relative_output_path)
49
+ FileUtils.touch(workspace + '/' + modifier.relative_output_path)
50
+ modifier.append(Class.new do
51
+ def append_line
52
+ '1'
53
+ end
54
+ end.new
55
+ )
56
+ modifier.append(Class.new do
57
+ def append_line
58
+ '2'
59
+ end
60
+ end.new
61
+ )
62
+
63
+
64
+ #When
65
+ modifier.modify
66
+
67
+ #Then
68
+ expect(Pathname.new(workspace + '/' + modifier.relative_output_path)).to be_file
69
+ expect(IO.read(Pathname.new(workspace + '/' + modifier.relative_output_path))).to match(/\nsource #{workspace}\/1\nsource #{workspace}\/2\n/)
70
+
71
+ end
72
+
73
+ end
74
+
@@ -0,0 +1,73 @@
1
+ # Copyright (c) 2017-2019 Beate Ottenwälder
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative '../../spec_helper'
22
+ require 'rspec'
23
+ require 'fileutils'
24
+ require 'pi_build_modifier/sys_tweaks/ssh'
25
+ require 'pi_build_modifier/sys_tweaks/run_modifier'
26
+ require 'pi_build_modifier/modifier/erb_mapper'
27
+ require 'pi_build_modifier/modifier/pi_modifier'
28
+
29
+
30
+ RSpec.describe PiBuildModifier::Ssh do
31
+
32
+ let(:empty_json_config) {'config_empty.json'}
33
+ let(:workspace) {File.dirname(__FILE__) + '/workspace'}
34
+
35
+ before do
36
+ File.open(empty_json_config, 'w') {|file| file.write('{}')}
37
+ FileUtils.mkdir_p workspace
38
+ end
39
+
40
+ after do
41
+ FileUtils.rm(empty_json_config)
42
+ FileUtils.rm_rf workspace
43
+ end
44
+
45
+ it 'does not accept an invalid config' do
46
+ #Given
47
+ modifier = PiBuildModifier::PiModifier.new
48
+ ssh = PiBuildModifier::Ssh.new
49
+ mapper = ssh.mapper(workspace)
50
+
51
+ #When
52
+ modifier.with_json_configuration('cfg')
53
+ modifier.with_mapper(mapper)
54
+
55
+ expect{ modifier.modify }.to raise_error()
56
+ end
57
+
58
+ it 'should create a default ssh.sh file' do
59
+ #Given
60
+ modifier = PiBuildModifier::PiModifier.new
61
+ ssh = PiBuildModifier::Ssh.new
62
+ mapper = ssh.mapper(workspace)
63
+
64
+ #When
65
+ modifier.with_json_configuration(empty_json_config)
66
+ modifier.with_mapper(mapper)
67
+ modifier.modify
68
+
69
+ #Then
70
+ expect(Pathname.new(workspace + '/' + ssh.relative_output_path)).to be_file
71
+ end
72
+ end
73
+
@@ -0,0 +1,66 @@
1
+ # Copyright (c) 2017-2019 Beate Ottenwälder
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative '../../spec_helper'
22
+ require 'rspec'
23
+ require 'fileutils'
24
+ require 'pi_build_modifier/system/system_type'
25
+ require 'pi_build_modifier/modifier/mapper'
26
+
27
+ RSpec.describe PiBuildModifier::System do
28
+
29
+ EXPECTED_SYSTEM_NAME = 'chiipi_test'
30
+ EXPECTED_SYSTEM_TYPE = 'lite'
31
+ let(:config) {{'system' => {'name' => EXPECTED_SYSTEM_NAME, 'type' => EXPECTED_SYSTEM_TYPE}}}
32
+ let(:workspace) {"#{File.dirname(__FILE__)}/workspace"}
33
+
34
+
35
+ after(:each) do
36
+ FileUtils.rm_rf(workspace) if Dir.exist?(workspace)
37
+ end
38
+
39
+
40
+ it 'should map the name and type given in a hash to corresponding members' do
41
+ #Given
42
+ system = PiBuildModifier::System.new.mapper(workspace)
43
+
44
+ #When
45
+ system.map(config)
46
+
47
+ #Then
48
+ expect(system.name).to eq(EXPECTED_SYSTEM_NAME)
49
+ expect(system.type).to eq(EXPECTED_SYSTEM_TYPE)
50
+ end
51
+
52
+ it 'should map the name and type to variables' do
53
+ #Given
54
+ system = PiBuildModifier::System.new.mapper(workspace)
55
+
56
+ #When
57
+ system.map(config)
58
+ system.modify
59
+
60
+ #Then
61
+ %w(/config /stage3/SKIP /stage4/SKIP /stage5/SKIP).each do |file|
62
+ expect(Pathname.new(workspace + file)).to be_file
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,73 @@
1
+ # Copyright (c) 2017-2019 Beate Ottenwälder
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative 'spec_helper'
22
+ require 'pi_build_modifier'
23
+ require 'pi_build_modifier/version'
24
+ require 'pi_build_modifier/modifier_task'
25
+
26
+ RSpec.describe PiBuildModifier do
27
+ it 'has a version number' do
28
+ expect(PiBuildModifier::VERSION).not_to be nil
29
+ end
30
+ end
31
+
32
+ RSpec.describe PiBuildModifier::PiBuildModifier do
33
+
34
+ it 'informs about valid commands when called with no arguments' do
35
+ expect {PiBuildModifier::PiBuildModifier.start([])}.to output(/Commands/).to_stdout
36
+ end
37
+
38
+ context '#version' do
39
+ it 'informs about the current version' do
40
+ expect {PiBuildModifier::PiBuildModifier.start(%w(version))}.to output(/#{PiBuildModifier::VERSION}/).to_stdout
41
+ end
42
+ end
43
+
44
+ context '#modify' do
45
+
46
+ let(:tmp_json_config) {'tmp_config.json'}
47
+ let(:tmp_workspace) {'tmp_space'}
48
+
49
+ before do
50
+ File.open(tmp_json_config, 'w') {|file| file.write('{}')}
51
+ FileUtils.mkdir_p tmp_workspace
52
+ end
53
+
54
+ after do
55
+ FileUtils.rm(tmp_json_config)
56
+ FileUtils.rm_rf tmp_workspace
57
+ end
58
+
59
+ it 'is called by thor, when "pi_build_modifier modify" is called' do
60
+ expect_any_instance_of(PiBuildModifier::PiBuildModifier).to receive(:modify).with(tmp_json_config, tmp_workspace)
61
+ PiBuildModifier::PiBuildModifier.start(['modify', tmp_json_config, tmp_workspace])
62
+ end
63
+
64
+ it 'triggers the modifier task' do
65
+ expect(PiBuildModifier::Task::Modifier).to receive(:new).with(tmp_json_config, tmp_workspace).and_return(PiBuildModifier::Task::Modifier.new(tmp_json_config, tmp_workspace))
66
+ expect_any_instance_of(PiBuildModifier::Task::Modifier).to receive(:execute)
67
+ PiBuildModifier::PiBuildModifier.start(['modify', tmp_json_config, tmp_workspace])
68
+ end
69
+ end
70
+ end
71
+
72
+
73
+
@@ -0,0 +1,10 @@
1
+ require 'simplecov'
2
+ #require 'codecov'
3
+
4
+ SimpleCov.start do
5
+ add_filter %r{/spec/}
6
+ end
7
+ # SimpleCov.formatter = SimpleCov::Formatter::Codecov
8
+
9
+ lib = File.expand_path('../../lib', __FILE__)
10
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ # Specify your gem's dependencies in pi_build_modifier.gemspec
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-2019 Beate Ottenwälder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # pi_customizer
2
+
3
+ see https://github.com/ottenwbe/pi-gen-environment
@@ -0,0 +1,13 @@
1
+ lib = File.join(File.dirname(__FILE__), '/lib')
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ begin
5
+ require 'bundler/gem_tasks'
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ task :default => :spec
10
+
11
+ rescue LoadError
12
+ puts 'RSpec or Bundler is not installed. This means rake is not able to execute tests!'
13
+ end
@@ -0,0 +1,16 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure('2') do |config|
5
+
6
+ config.vm.box = "ubuntu/xenial64"
7
+
8
+ config.vm.provision 'shell', inline: <<-SHELL
9
+ sudo apt update
10
+ sudo apt -y install build-essential ruby-full
11
+ gem install bundler
12
+ cd /vagrant
13
+ bundle install
14
+ rake spec
15
+ SHELL
16
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (c) 2017-2019 Beate Ottenwälder
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'pi_customizer'
24
+
25
+ PiCustomizer::PiCustomizer.start(ARGV)
@@ -0,0 +1,3 @@
1
+ output "pi-builder-ip" {
2
+ value = "${aws_instance.pi_builder_vm.public_ip}"
3
+ }
@@ -0,0 +1,160 @@
1
+ /* Setup the aws provider */
2
+ provider "aws" {
3
+ access_key = "${var.access_key}"
4
+ secret_key = "${var.secret_key}"
5
+ region = "${var.region}"
6
+ }
7
+
8
+ /* Define the vpc */
9
+ resource "aws_vpc" "pi_builder_vpc" {
10
+ cidr_block = "${var.vpc_cidr}"
11
+ enable_dns_hostnames = true
12
+
13
+ tags {
14
+ name = "pi-builder vpc"
15
+ }
16
+ }
17
+
18
+ /** key for deployment of jumpbox and nat */
19
+ resource "aws_key_pair" "pi_builder_key" {
20
+ key_name = "pi-builder"
21
+ public_key = "${file("${var.ssh_path}/pi-builder.pub")}"
22
+ }
23
+
24
+
25
+ /** pi-build-vm instance */
26
+ resource "aws_instance" "pi_builder_vm" {
27
+ ami = "${lookup(var.amis, var.region)}"
28
+ availability_zone = "${var.default_az}"
29
+ instance_type = "t2.micro"
30
+ subnet_id = "${aws_subnet.pi_builder_subnet.id}"
31
+
32
+ root_block_device {
33
+ delete_on_termination = true
34
+ iops = 0
35
+ volume_size = 50
36
+ volume_type = "gp2"
37
+ }
38
+
39
+ vpc_security_group_ids = [
40
+ "${aws_security_group.ssh.id}",
41
+ "${aws_security_group.http.id}"]
42
+ key_name = "${aws_key_pair.pi_builder_key.key_name}"
43
+
44
+ provisioner "file" {
45
+ connection {
46
+ user = "ubuntu"
47
+ host = "${aws_instance.pi_builder_vm.public_dns}"
48
+ timeout = "25m"
49
+ private_key = "${file("${var.ssh_path}/pi-builder.pem")}"
50
+ }
51
+ source = "../sh/build-pi-img.sh"
52
+ destination = "/home/ubuntu/build-pi-img.sh"
53
+ }
54
+
55
+ provisioner "remote-exec" {
56
+ connection {
57
+ user = "ubuntu"
58
+ host = "${aws_instance.pi_builder_vm.public_dns}"
59
+ timeout = "25m"
60
+ private_key = "${file("${var.ssh_path}/pi-builder.pem")}"
61
+ }
62
+ inline = [
63
+ "sh build-pi-img.sh"
64
+ ]
65
+ }
66
+
67
+ tags = {
68
+ name = "pi-builder vm"
69
+ }
70
+ }
71
+
72
+ resource "aws_eip" "lb" {
73
+ instance = "${aws_instance.pi_builder_vm.id}"
74
+ vpc = true
75
+ }
76
+
77
+ resource "aws_security_group" "ssh" {
78
+ name = "ssh"
79
+ description = "SSH access to instances from the internet"
80
+ vpc_id = "${aws_vpc.pi_builder_vpc.id}"
81
+
82
+ ingress {
83
+ from_port = 22
84
+ to_port = 22
85
+ protocol = "tcp"
86
+
87
+ cidr_blocks = [
88
+ "0.0.0.0/0",
89
+ ]
90
+ }
91
+
92
+ tags {
93
+ name = "ssh sg"
94
+ }
95
+ }
96
+
97
+ resource "aws_security_group" "http" {
98
+
99
+ name = "http"
100
+ description = "Outbound http(s) connections."
101
+ vpc_id = "${aws_vpc.pi_builder_vpc.id}"
102
+
103
+ egress {
104
+ from_port = 80
105
+ to_port = 80
106
+ protocol = "tcp"
107
+ cidr_blocks = [
108
+ "0.0.0.0/0"]
109
+ }
110
+
111
+ egress {
112
+ from_port = 443
113
+ to_port = 443
114
+ protocol = "tcp"
115
+ cidr_blocks = [
116
+ "0.0.0.0/0"]
117
+ }
118
+
119
+ tags {
120
+ name = "http sg"
121
+ }
122
+ }
123
+
124
+ /** internet access */
125
+ resource "aws_internet_gateway" "pi_builder_gateway" {
126
+ vpc_id = "${aws_vpc.pi_builder_vpc.id}"
127
+ }
128
+
129
+
130
+ /** public subnet for the nat instance and the jumpbox */
131
+ resource "aws_subnet" "pi_builder_subnet" {
132
+ vpc_id = "${aws_vpc.pi_builder_vpc.id}"
133
+ cidr_block = "${var.public_subnet_cidr}"
134
+ availability_zone = "${var.default_az}"
135
+ map_public_ip_on_launch = true
136
+ depends_on = [
137
+ "aws_internet_gateway.pi_builder_gateway"]
138
+
139
+ tags {
140
+ name = "pi-builder subnet"
141
+ }
142
+ }
143
+
144
+ resource "aws_route_table" "pi_builder_rt" {
145
+ vpc_id = "${aws_vpc.pi_builder_vpc.id}"
146
+
147
+ route {
148
+ cidr_block = "0.0.0.0/0"
149
+ gateway_id = "${aws_internet_gateway.pi_builder_gateway.id}"
150
+ }
151
+
152
+ tags {
153
+ name = "pi-builder rt"
154
+ }
155
+ }
156
+
157
+ resource "aws_route_table_association" "pi_builder_rta" {
158
+ subnet_id = "${aws_subnet.pi_builder_subnet.id}"
159
+ route_table_id = "${aws_route_table.pi_builder_rt.id}"
160
+ }