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,84 @@
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 'thor'
22
+ require 'fileutils'
23
+ require 'pi_customizer/version'
24
+ require 'pi_customizer/build/environment/environment_builder_factory'
25
+ require 'pi_customizer/build/workspace/remote_workspace'
26
+ require 'pi_customizer/build/workspace/local_workspace'
27
+ require 'pi_customizer/write/image_writer'
28
+ require 'pi_customizer/utils/logex'
29
+
30
+ module PiCustomizer
31
+
32
+ ##
33
+ # PiCustomizer defines all of pi_customizer's cli commands
34
+
35
+ class PiCustomizer < Thor
36
+
37
+ ##
38
+ # The build command can be called by a user to trigger a customized build of a pi image
39
+
40
+ desc 'build ENV', 'Build pi image on environment ENV (valid environments are: VAGRANT).'
41
+ method_option :build_sources_git_url, :default => Workspace::DEFAULT_GIT_PATH, :aliases => '-g'
42
+ method_option :build_sources_git_tag, :default => Workspace::DEFAULT_GIT_TAG, :aliases => '-t'
43
+ method_option :remote_workspace_dir, :default => Workspace::DEFAULT_REMOTE_WORKSPACE_DIRECTORY, :aliases => '-w'
44
+ method_option :config_file, :aliases => '-c', :required => true
45
+ method_option :local_workspace_dir, :default => Workspace::DEFAULT_LOCAL_WORKSPACE_DIRECTORY, :aliases => '-l'
46
+ method_option :modifier_gem, :default => '', :aliases => '-m', :desc => 'Path to the modifier_gem. If not specified, the most recent gem from rubygems.org is downloaded.'
47
+ method_option :deploy_dir, :default => Dir.getwd, :aliases => '-d'
48
+ method_option :skip_steps, :type => :array, :aliases => '-s'
49
+
50
+ def build(env)
51
+ begin
52
+ remote_workspace = Workspace::RemoteWorkspace.new("#{options[:remote_workspace_dir]}", "#{options[:build_sources_git_url]}", "#{options[:build_sources_git_tag]}")
53
+ local_workspace = Workspace::LocalWorkspace.new("#{options[:config_file]}", "#{options[:local_workspace_dir]}", "#{options[:modifier_gem]}")
54
+ builder = Environment::builder_factory(env, local_workspace, remote_workspace, options[:skip_steps])
55
+ builder.build
56
+ rescue Exception => e
57
+ $logger.error e.message
58
+ end
59
+ end
60
+
61
+ ##
62
+ # The version command allows users to query for the current version of the pi_customizer gem. It is printed on the command line.
63
+
64
+ desc 'v, version', 'Shows the version number.'
65
+
66
+ def version
67
+ puts VERSION
68
+ end
69
+
70
+ ##
71
+ # Allow uswers to write an image to a SD card
72
+
73
+ desc 'write IMAGE DEVICE', 'Write an image to a device.'
74
+
75
+ def write_image(image, device)
76
+ begin
77
+ ImageWriter.new().write(image, device)
78
+ rescue Exception => e
79
+ $logger.error e.message
80
+ end
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'pi_customizer/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'pi_customizer'
10
+ spec.version = PiCustomizer::VERSION
11
+ spec.license = 'MIT'
12
+ spec.author = 'Beate Ottenwälder'
13
+ spec.email = 'ottenwbe.public@gmail.com'
14
+ spec.homepage = 'https://github.com/ottenwbe/pi-gen-environment.git'
15
+ spec.summary = 'The pi_customizer gem!'
16
+ spec.description = 'The pi_customizer gem allows you to adapt Raspbian images to your needs!'
17
+
18
+ spec.files = Dir.glob('{envs}/**/*') + `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f)}
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 2.0'
25
+ spec.add_development_dependency 'rake', '~> 12.3'
26
+ spec.add_development_dependency 'rspec', '~> 3.8'
27
+ spec.add_development_dependency 'simplecov', '~> 0.16'
28
+ spec.add_development_dependency 'rdoc', '~> 6.1'
29
+ spec.add_runtime_dependency 'thor', '~> 0.20'
30
+ end
@@ -0,0 +1,61 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ $dependencies = <<SCRIPT
5
+ sudo apt update
6
+ sudo apt -y upgrade
7
+ sudo apt -y install quilt parted qemu-user-static debootstrap zerofree pxz zip dosfstools libcap2-bin bsdtar
8
+ sudo apt -y install git curl ruby-full build-essential
9
+ sudo apt -y install wpasupplicant openssl libssl-dev
10
+ SCRIPT
11
+
12
+ $install_modifier_gem = <<SCRIPT
13
+ # install gem
14
+ gem install /home/ubuntu/pi_build_modifier.gem
15
+ SCRIPT
16
+
17
+ $prepare = <<SCRIPT
18
+ rm -rf /build/pi-gen
19
+ mkdir -p /build/pi-gen
20
+ echo 'git clone to workspace'
21
+ git clone --branch master https://github.com/ottenwbe/pi-gen.git /build/pi-gen
22
+ SCRIPT
23
+
24
+ $modify = <<SCRIPT
25
+ # Execute gem with parameters
26
+ cd /build/pi-gen
27
+ pi_build_modifier modify /vagrant/config.json /build/pi-gen
28
+ sudo ./build.sh
29
+ mkdir -p /build/pi-gen/deploy
30
+ cp -r /build/pi-gen/deploy /vagrant
31
+ echo "Pi Image copied to your local workspace ~/workspace/pi-gen-environment/tmp_vagrant_file"
32
+ SCRIPT
33
+
34
+ Vagrant.configure('2') do |config|
35
+
36
+ config.vm.box = 'ubuntu/xenial64' #Note, that 'debian/stretch64' cannot be resized with the disksize plugin
37
+
38
+ unless Vagrant.has_plugin?("vagrant-disksize")
39
+ raise 'vagrant-disksize plugin is not installed! Use: vagrant plugin install vagrant-disksize'
40
+ end
41
+
42
+ config.disksize.size = '60GB'
43
+
44
+ # Prepare environment by updating the dependencies
45
+ config.vm.provision 'shell', inline: $dependencies
46
+
47
+ config.vm.provision 'file', source: '~/workspace/pi-gen-environment/my_gem.gem', destination: '/home/ubuntu/pi_build_modifier.gem'
48
+
49
+ # Modifier gem is installed
50
+ config.vm.provision 'shell', inline: $install_modifier_gem
51
+
52
+ # Copy config file
53
+ config.vm.provision 'file', source: '~/workspace/pi-gen-environment/pi_customizer/lib/pi_customizer/build/workspace/../../../../resources/config.json', destination: '/vagrant/config.json'
54
+
55
+ # Prepare the modification
56
+ config.vm.provision 'shell', inline: $prepare
57
+
58
+ # Actually modify the build sources and then build the environment
59
+ config.vm.provision 'shell', inline: $modify
60
+
61
+ end
@@ -0,0 +1 @@
1
+ test
@@ -0,0 +1,64 @@
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 'pi_customizer/build/builder/build_executor'
24
+ require 'pi_customizer/build/environment/environment'
25
+
26
+ describe PiCustomizer::Builder::BuildExecutor do
27
+
28
+ it 'internally converts keys of skip steps to symbols' do
29
+ build_exec = PiCustomizer::Builder::BuildExecutor.new(PiCustomizer::Environment::EnvironmentControl.new('',''), ['prepare'])
30
+ expect(build_exec.skip_build_steps).to include(:prepare)
31
+ expect(build_exec.skip_build_steps).not_to include('prepare')
32
+ end
33
+
34
+
35
+ it 'honors skipping the build step prepare' do
36
+ build_exec = PiCustomizer::Builder::BuildExecutor.new(PiCustomizer::Environment::EnvironmentControl.new('',''), [:prepare])
37
+ expect(build_exec.env).not_to receive(:prepare)
38
+ build_exec.prepare
39
+ end
40
+
41
+ it 'honors skipping the build step start' do
42
+ build_exec = PiCustomizer::Builder::BuildExecutor.new(PiCustomizer::Environment::EnvironmentControl.new('',''), [:start])
43
+ expect(build_exec.env).not_to receive(:start)
44
+ build_exec.start
45
+ end
46
+
47
+ it 'honors skipping the build step' do
48
+ build_exec = PiCustomizer::Builder::BuildExecutor.new(PiCustomizer::Environment::EnvironmentControl.new('',''), [:build_image])
49
+ expect(build_exec.env).not_to receive(:build_image)
50
+ build_exec.build_image
51
+ end
52
+
53
+ it 'honors skipping the build step clean' do
54
+ build_exec = PiCustomizer::Builder::BuildExecutor.new(PiCustomizer::Environment::EnvironmentControl.new('',''), [:clean_up])
55
+ expect(build_exec.env).not_to receive(:clean_up)
56
+ build_exec.clean_up
57
+ end
58
+
59
+ it 'honors skipping the build step stop' do
60
+ build_exec = PiCustomizer::Builder::BuildExecutor.new(PiCustomizer::Environment::EnvironmentControl.new('',''), [:stop])
61
+ expect(build_exec.env).not_to receive(:stop)
62
+ build_exec.stop
63
+ end
64
+ end
@@ -0,0 +1,57 @@
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_customizer/build/environment/aws/aws'
23
+ require 'fileutils'
24
+ require 'pathname'
25
+
26
+ module PiCustomizer
27
+ module Environment
28
+ RSpec.describe AWS do
29
+
30
+ let(:key_name) {'pi-test'}
31
+
32
+ it 'creates an ssh key' do
33
+ AWS.new(nil, '').create_keys(key_name)
34
+ expect(Pathname.new("ssh/#{key_name}.pem")).to be_file
35
+ expect(Pathname.new("ssh/#{key_name}.pub")).to be_file
36
+ end
37
+
38
+ it 'deletes an existing ssh key' do
39
+ aws = AWS.new(nil, '')
40
+ aws.create_keys(key_name)
41
+ aws.del_keys(key_name)
42
+
43
+ expect(Pathname.new("ssh/#{key_name}.pem")).to_not be_file
44
+ expect(Pathname.new("ssh/#{key_name}.pub")).to_not be_file
45
+ end
46
+
47
+ after(:each) do
48
+ if File.file?("ssh/#{key_name}.pub")
49
+ FileUtils.rm "ssh/#{key_name}.pem"
50
+ end
51
+ if File.file?("ssh/#{key_name}.pub")
52
+ FileUtils.rm "ssh/#{key_name}.pub"
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,48 @@
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 'pi_customizer/build/environment/environment_builder_factory'
24
+ require 'pi_customizer/build/environment/docker/docker'
25
+ require 'pi_customizer/build/environment/aws/aws'
26
+
27
+ module PiCustomizer
28
+ module Environment
29
+ RSpec.describe 'environment_factory' do
30
+
31
+ it 'creates a vagrant environment when ENV_VAGRANT is specified' do
32
+ env = Environment::environment_factory(ENV_VAGRANT, '', '')
33
+ expect(env).to be_a Vagrant
34
+ end
35
+
36
+ it 'creates a docker environment when ENV_DOCKER is specified' do
37
+ env = Environment::environment_factory(ENV_DOCKER, '', '')
38
+ expect(env).to be_a Docker
39
+ end
40
+
41
+ it 'creates an AWS environment when ENV_AWS is specified' do
42
+ env = Environment::environment_factory(ENV_AWS, '', '')
43
+ expect(env).to be_a AWS
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,75 @@
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 'pi_customizer/build/environment/environment'
24
+ require 'pi_customizer/utils/logex'
25
+
26
+ RSpec.describe PiCustomizer::Environment::EnvironmentControl do
27
+
28
+ let(:environment) {PiCustomizer::Environment::EnvironmentControl.new(nil,nil)}
29
+
30
+
31
+ it 'warns about skipped check steps' do
32
+ expect($logger).to receive(:warn).with(/skipped/)
33
+ environment.check
34
+ end
35
+
36
+ it 'warns about skipped prepare steps' do
37
+ expect($logger).to receive(:warn).with(/skipped/)
38
+ environment.prepare
39
+ end
40
+
41
+ it 'warns about skipped start steps' do
42
+ expect($logger).to receive(:warn).with(/skipped/)
43
+ environment.start
44
+ end
45
+
46
+ it 'warns about skipped build steps' do
47
+ expect($logger).to receive(:warn).with(/skipped/)
48
+ environment.build_image
49
+ end
50
+
51
+ it 'warns about skipped publish steps' do
52
+ expect($logger).to receive(:warn).with(/skipped/)
53
+ environment.publish
54
+ end
55
+
56
+ it 'warns about skipped publish steps' do
57
+ expect($logger).to receive(:warn).with(/skipped/)
58
+ environment.publish
59
+ end
60
+
61
+ it 'warns about skipped clean_up steps' do
62
+ expect($logger).to receive(:warn).with(/skipped/)
63
+ environment.clean_up
64
+ end
65
+
66
+ it 'warns about skipped stop steps' do
67
+ expect($logger).to receive(:warn).with(/skipped/)
68
+ environment.stop
69
+ end
70
+
71
+ it 'informs about skipped ensure steps' do
72
+ expect($logger).to receive(:info).with(/skipped/)
73
+ environment.ensure
74
+ end
75
+ end
@@ -0,0 +1,63 @@
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_customizer/build/environment/vagrant/vagrant_file'
23
+ require 'pi_customizer/build/workspace/local_workspace'
24
+ require 'fileutils'
25
+ require 'pathname'
26
+
27
+ module PiCustomizer
28
+
29
+ RSpec.describe Environment::VagrantFileRenderer do
30
+
31
+ let(:tmp_dir) {'tmp_vagrant_file'}
32
+ let(:vagrant_file) {Environment::VagrantFile.new(Workspace::LocalWorkspace.new('', tmp_dir, ''), nil)}
33
+ let(:vagrant_file_builder) {Environment::VagrantFileRenderer.new(vagrant_file)}
34
+ let(:test_vagrant_file) {File.dirname(__FILE__) + '/../../../fixtures/TestVagrantfile'}
35
+
36
+ after(:each) do
37
+ #FileUtils.rm_rf tmp_dir
38
+ end
39
+
40
+ it 'renders a Vagrantfile in the given temporary directory' do
41
+ vagrant_file_builder.create_from_template
42
+ expect(Pathname.new(tmp_dir+'/Vagrantfile')).to be_file
43
+ end
44
+
45
+ it 'renders a Vagrantfile which copies a gem to the vagrant box when the modifier_gem_path is given' do
46
+ #Given
47
+ gem_name = 'my_gem.gem'
48
+ v_file = Environment::VagrantFile.new(Workspace::LocalWorkspace.new('', tmp_dir, gem_name), nil)
49
+ v_file_builder = Environment::VagrantFileRenderer.new(v_file)
50
+ #When
51
+ v_file_builder.create_from_template
52
+ #Then
53
+ expect(File.read(tmp_dir+'/Vagrantfile').to_s).to match(/config.vm.provision 'file', source: [-a-zA-Z0-9'\/_]+#{gem_name}/)
54
+ #expect(File.read(tmp_dir+'/Vagrantfile').to_s).to eq File.read(test_vagrant_file).to_s
55
+ end
56
+
57
+ it 'raises an error if the Vagrantfile.erb does not exist' do
58
+ vagrant_file.vagrant_template_path = 'some/random/path'
59
+ expect {vagrant_file_builder.create_from_template}.to raise_error("'Vagrantfile.erb' template not specified. Expected template in path 'some/random/path'")
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,41 @@
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 'fileutils'
23
+ require 'pathname'
24
+ require 'pi_customizer/build/environment/vagrant/vagrant'
25
+
26
+ module PiCustomizer
27
+ module Environment
28
+ RSpec.describe Vagrant do
29
+
30
+ let(:vagrant_env) {Vagrant.new(nil, nil)}
31
+
32
+ describe '#check' do
33
+ it 'checks for the existence of vagrant' do
34
+ expect(vagrant_env).to receive(:system).with('vagrant -v').and_return(true)
35
+ vagrant_env.check
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
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 'pi_customizer/version'
24
+
25
+ describe PiCustomizer do
26
+ it 'has a version number' do
27
+ expect(PiCustomizer::VERSION).not_to be nil
28
+ end
29
+ end
@@ -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 'pi_customizer/build/workspace/local_workspace'
23
+ require 'fileutils'
24
+ require 'pathname'
25
+
26
+ module PiCustomizer
27
+ module Workspace
28
+ RSpec.describe LocalWorkspace do
29
+
30
+ it 'uses default values for config_path and tmp_directory when no path is specified' do
31
+ #Given
32
+ #When
33
+ local_config = LocalWorkspace.new('', '', '')
34
+ #Then
35
+ expect(local_config.config_path.to_s).to eq DEFAULT_CONFIG_PATH
36
+ expect(local_config.workspace_directory.to_s).to eq DEFAULT_LOCAL_WORKSPACE_DIRECTORY
37
+ expect(local_config.modifier_gem_path).to be nil
38
+ end
39
+
40
+ it 'accepts absolute paths for config_path and stores them as absolute paths' do
41
+ #Given
42
+ expected_cfg = '/home/test/cfg.json'
43
+ expected_tmp = '/home/test/tmp'
44
+ expected_mod = '/home/test/mod.gem'
45
+ #When
46
+ local_config = LocalWorkspace.new(expected_cfg, expected_tmp, expected_mod)
47
+ #Then
48
+ expect(local_config.config_path.to_s).to eq expected_cfg
49
+ expect(local_config.workspace_directory.to_s).to eq expected_tmp
50
+ expect(local_config.modifier_gem_path.to_s).to eq expected_mod
51
+ end
52
+
53
+ it 'accepts relative paths for config_path and stores them as absolute paths' do
54
+ local_config = LocalWorkspace.new('a', 'b', 'c')
55
+ expect(local_config.config_path.to_s).to eq File.join(Dir.pwd, '/a')
56
+ expect(local_config.workspace_directory.to_s).to eq File.join(Dir.pwd, '/b')
57
+ expect(local_config.modifier_gem_path.to_s).to eq File.join(Dir.pwd, '/c')
58
+ end
59
+
60
+ it 'allows us to check for value equality' do
61
+ local_config_1 = LocalWorkspace.new('a', 'b', 'c')
62
+ local_config_2 = LocalWorkspace.new('a', 'b', 'c')
63
+ expect(local_config_1==local_config_2).to be true
64
+ end
65
+
66
+ it 'allows us to check for value inequality' do
67
+ local_config_1 = LocalWorkspace.new('a', 'b', 'c')
68
+ local_config_2 = LocalWorkspace.new('e', 'f', 'g')
69
+ expect(local_config_1==local_config_2).to be false
70
+ end
71
+
72
+ end
73
+ end
74
+ end