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,55 @@
1
+ /** Access key. NOTE: DO NOT CHECK IN */
2
+ variable "access_key" {
3
+ description = "Access Key"
4
+ }
5
+
6
+ /** Secret key. NOTE: DO NOT CHECK IN */
7
+ variable "secret_key" {
8
+ description = "Secret Access"
9
+ }
10
+
11
+ variable "ssh_path" {
12
+ description = "Secret Access"
13
+ }
14
+
15
+ /** AZ which is used by default during the deployment */
16
+ variable "default_az" {
17
+ description = "Default AZ"
18
+ default = "eu-central-1a"
19
+ }
20
+
21
+ /** Region which is used by default during te rollout */
22
+ variable "region" {
23
+ description = "AWS region to host the bosh network"
24
+ default = "eu-central-1"
25
+ }
26
+
27
+ variable "vpc_gw" {
28
+ description = "GW for the vpc"
29
+ default = "10.0.0.1"
30
+ }
31
+
32
+ variable "gateway" {
33
+ description = "GW for the bosh network"
34
+ default = "10.0.1.1"
35
+ }
36
+
37
+ variable "vpc_cidr" {
38
+ description = "CIDR for VPC"
39
+ default = "10.0.0.0/16"
40
+ }
41
+
42
+ variable "public_subnet_cidr" {
43
+ description = "CIDR for public subnet"
44
+ default = "10.0.0.0/24"
45
+ }
46
+
47
+ /* Ubuntu ami by region */
48
+ variable "amis" {
49
+ type = "map"
50
+ description = "Base AMI to launch the vms"
51
+
52
+ default = {
53
+ eu-central-1 = "ami-7f42e510"
54
+ }
55
+ }
@@ -0,0 +1,6 @@
1
+ FROM ubuntu:16.04
2
+ RUN apt update
3
+ RUN apt install -y sudo git ruby ruby-dev build-essential \
4
+ quilt parted realpath qemu-user-static debootstrap zerofree pxz zip \
5
+ dosfstools bsdtar libcap2-bin grep rsync xz-utils fakeroot curl vim
6
+ CMD ["/sbin/init"]
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Install dependencies
4
+ sudo apt update
5
+ sudo apt -y install parted zerofree dosfstools git quilt qemu-user-static debootstrap pxz zip bsdtar ruby-full libcap2-bin
6
+
7
+ file="gitpath"
8
+ if [ -f "$file" ]; then
9
+ git clone "$(< gitpath)"
10
+ fi
11
+
12
+ cd pi-gen
13
+ echo "IMG_NAME=\"chiipi\"" > config
14
+
15
+ wpa_supplicant_folder=stage1/02-net-tweaks/files/interfaces
16
+
17
+ cp ../conf/wpa_supplicant.json ./stage2/02-net-tweaks/rb
18
+
19
+ touch ./stage3/SKIP ./stage4/SKIP ./stage5/SKIP
20
+ rm stage4/EXPORT* stage5/EXPORT*
21
+
22
+ # Build it
23
+ gem install bundler
24
+ gem install rake
25
+ gem install rspec
26
+
27
+ bundle install
28
+ rake pi_gen
@@ -0,0 +1,149 @@
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 'pi_customizer/utils/logex'
22
+
23
+ module PiCustomizer
24
+ module Builder
25
+
26
+ ##
27
+ # BuildExecutor triggers the steps of a build process in a given environment (e.g., a vagrant box).
28
+ # It skips individual steps in the build process when they are defined as skip_build_steps.
29
+
30
+ class BuildExecutor
31
+
32
+ attr_reader :env, :skip_build_steps
33
+
34
+ def initialize(environment, skip_build_steps = Array.new)
35
+ @env = environment
36
+ @skip_build_steps = convert_to_skip(skip_build_steps)
37
+ end
38
+
39
+ ##
40
+ # check if a build environment is specified and then calls the check step for this environment
41
+
42
+ def check
43
+ check_env
44
+ @env.check
45
+ end
46
+
47
+ ##
48
+ # execute the prepare step for the build environment
49
+
50
+ def prepare
51
+ unless @skip_build_steps.include?(:prepare)
52
+ @env.prepare
53
+ end
54
+ end
55
+
56
+ ##
57
+ # execute the start step for the build environment
58
+
59
+ def start
60
+ unless @skip_build_steps.include?(:start)
61
+ @env.start
62
+ end
63
+ end
64
+
65
+ ##
66
+ # execute the build_image step for the build environment
67
+
68
+ def build_image
69
+ unless @skip_build_steps.include?(:build_image)
70
+ @env.build_image
71
+ end
72
+ end
73
+
74
+ ##
75
+ # publish the image from the build environment
76
+
77
+ def publish
78
+ unless @skip_build_steps.include?(:publish)
79
+ @env.publish
80
+ end
81
+ end
82
+
83
+ ##
84
+ # clean_up the build environment
85
+
86
+ def clean_up
87
+ unless @skip_build_steps.include?(:clean_up)
88
+ @env.clean_up
89
+ end
90
+ end
91
+
92
+ ##
93
+ # execute the stop step of the environment
94
+
95
+ def stop
96
+ unless @skip_build_steps.include?(:stop)
97
+ @env.stop
98
+ end
99
+ end
100
+
101
+ ##
102
+ # execute the ensure step of an environment
103
+
104
+ def ensure
105
+ @env.ensure
106
+ end
107
+
108
+ ##
109
+ # convert a list of stringified build steps to a list of symbols
110
+
111
+ private def convert_to_skip(skip_build_steps)
112
+ if skip_build_steps.nil?
113
+ skip_build_steps = Array.new
114
+ else
115
+ # convert every key to a symbol
116
+ skip_build_steps = skip_build_steps.collect {|k| k.to_sym}
117
+ end
118
+ $logger.debug "Skipping the following build steps: #{skip_build_steps}"
119
+ skip_build_steps
120
+ end
121
+
122
+ ##
123
+ # check if an environment is specified
124
+
125
+ private def check_env
126
+ if @env.nil?
127
+ raise 'No environment specified, please specify the "environment", e.g. Vagrant'
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+
@@ -0,0 +1,59 @@
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 'pi_customizer/build/builder/build_executor'
22
+
23
+ module PiCustomizer
24
+ module Builder
25
+
26
+ ##
27
+ # PiBuilder defines abstractly the steps of a build process.
28
+ # However, the concrete orchestration of the build process's steps is done by its sub-classes.
29
+
30
+ class PiBuilder
31
+
32
+ attr_reader :build_executor
33
+
34
+ def initialize(environment, skip_build_steps)
35
+ @build_executor = BuildExecutor.new(environment,skip_build_steps)
36
+ end
37
+
38
+ ##
39
+ # build orchestrates an environment and therefore the build process of an image
40
+
41
+ def build
42
+ begin
43
+ execute_builder
44
+ rescue Exception => e
45
+ $logger.error e.message
46
+ ensure
47
+ ensure_builder
48
+ end
49
+ end
50
+
51
+ protected def ensure_builder
52
+ end
53
+
54
+ protected def execute_builder
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,43 @@
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 'pi_customizer/build/builder/builder'
22
+
23
+ module PiCustomizer
24
+ module Builder
25
+ class PrepareExecuteBuilder < PiBuilder
26
+
27
+ protected def execute_builder
28
+ @build_executor.check
29
+ @build_executor.prepare
30
+ @build_executor.publish
31
+ @build_executor.clean_up
32
+ @build_executor.start
33
+ @build_executor.build_image
34
+ @build_executor.stop
35
+ end
36
+
37
+ protected def ensure_builder
38
+ @build_executor.ensure
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
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 'pi_customizer/build/builder/builder'
22
+
23
+ module PiCustomizer
24
+ module Builder
25
+ class StartExecuteBuilder < PiBuilder
26
+
27
+ protected def execute_builder
28
+ @build_executor.check
29
+ @build_executor.start
30
+ @build_executor.prepare
31
+ @build_executor.build_image
32
+ @build_executor.publish
33
+ @build_executor.clean_up
34
+ @build_executor.stop
35
+ end
36
+
37
+ protected def ensure_builder
38
+ @build_executor.ensure
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,76 @@
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 'fileutils'
22
+ require 'pi_customizer/utils/logex'
23
+ require 'pi_customizer/build/environment/environment'
24
+
25
+ module PiCustomizer
26
+ module Environment
27
+ class AWS < EnvironmentControl
28
+
29
+ def build
30
+
31
+ puts 'NOTE: AWS is not yet officially supported!'
32
+
33
+ create_ssh_folder
34
+ create_keys
35
+ begin
36
+ terraform
37
+ ensure
38
+ del_keys
39
+ end
40
+ end
41
+
42
+ def terraform
43
+ puts 'Build env with terraform'
44
+ Dir.chdir 'envs/aws' do
45
+ system 'terraform plan'
46
+ system 'terraform apply'
47
+ end
48
+ end
49
+
50
+ def create_keys(key_name = 'pi-builder')
51
+ $logger.info 'Create AWS key unless it exists'
52
+ FileUtils.mkdir_p 'ssh'
53
+ unless File.file?("ssh/#{key_name}.pub")
54
+ system "ssh-keygen -t rsa -C pi-builder -P '' -f ssh/#{key_name} -b 4096"
55
+ FileUtils.mv "ssh/#{key_name}", "ssh/#{key_name}.pem"
56
+ FileUtils.chmod 400, "ssh/#{key_name}.pem"
57
+ end
58
+ end
59
+
60
+ def del_keys(key_name = 'pi-builder')
61
+ if File.file?("ssh/#{key_name}.pub")
62
+ FileUtils.rm "ssh/#{key_name}.pub"
63
+ end
64
+ if File.file?("ssh/#{key_name}.pem")
65
+ FileUtils.rm "ssh/#{key_name}.pem"
66
+ end
67
+ end
68
+
69
+ def create_ssh_folder
70
+ unless File.directory?('ssh')
71
+ FileUtils.mkdir_p 'ssh'
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,94 @@
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 'pi_customizer/utils/logex'
22
+
23
+ module PiCustomizer
24
+ module Environment
25
+ class Docker < EnvironmentControl
26
+
27
+ DOCKERFILE_PATH = File.join(File.dirname(__FILE__), '/../../../../envs/docker')
28
+ DOCKERFILE = "#{DOCKERFILE_PATH}/Dockerfile"
29
+ CONFIG_PATH_IN_DOCKER = '/resources'
30
+
31
+ def check
32
+
33
+ puts 'NOTE: Docker is not yet officially supported!'
34
+
35
+ $logger.info '[Check | Docker] Pre-flight checks are executing...'
36
+ ensure_docker
37
+ end
38
+
39
+ def start
40
+ $logger.info "[Start | Docker] Build docker image: #{DOCKERFILE}"
41
+ system "docker build --rm=true --file=#{DOCKERFILE} --tag=pi:build #{DOCKERFILE_PATH}"
42
+ $logger.info "[Start | Docker] Start docker image with volume #{@config.tmp_directory}:#{@workspace.workspace_directory}"
43
+ system "sudo docker run -v #{@config.tmp_directory}:#{@workspace.workspace_directory}:rw -v /dev:/dev -v /lib/modules:/lib/modules --cap-add=ALL --privileged=true --detach --security-opt label:disable pi:build \"/sbin/init\" > cid"
44
+ end
45
+
46
+ def prepare
47
+ prepare_workspace
48
+ prepare_configuration
49
+ end
50
+
51
+ def build_image
52
+ $logger.info '[Build| Docker] customization of build sources'
53
+ system "sudo docker exec --tty \"$(cat cid)\" bash -c \"sudo pi_build_modifier modify #{CONFIG_PATH_IN_DOCKER}/resources.json #{@workspace.workspace_directory}\""
54
+ $logger.info '[Build| Docker] pi-image build step'
55
+ system "sudo docker exec --tty \"$(cat cid)\" bash -c \"cd #{@workspace.workspace_directory} && sudo ./build.sh\"" #sudo chown docker #{@workspace.workspace_directory} &&
56
+ end
57
+
58
+ def clean_up
59
+ $logger.info '[Clean Up | Docker] pi-image remove contents of temporary container'
60
+ end
61
+
62
+ def stop
63
+ $logger.info '[Stop | Docker] Stop pi:build container'
64
+ #system 'docker stop "$(cat cid)"'
65
+ $logger.info '[Stop | Docker] RM pi:build container'
66
+ #system 'docker rm "$(cat cid)"'
67
+ #TODO: rm cid file!
68
+ end
69
+
70
+ private def ensure_docker
71
+ unless system 'docker -v'
72
+ raise 'Docker is not installed. Please ensure that Docker is running.'
73
+ end
74
+ end
75
+
76
+ private def prepare_configuration
77
+ $logger.info "[Prepare | Docker] Copy the configuration file from #{@config.config_path} to #{CONFIG_PATH_IN_DOCKER}/resources.json in container"
78
+ system "docker exec --tty \"$(cat cid)\" bash -c \"sudo mkdir -p #{CONFIG_PATH_IN_DOCKER}\""
79
+ system "docker cp #{@config.config_path} \"$(cat cid)\":#{CONFIG_PATH_IN_DOCKER}/resources.json"
80
+ gem_path = File.join(File.dirname(__FILE__), '/../../../../envs/pi_build_modifier.gem')
81
+ system "docker cp #{gem_path} \"$(cat cid)\":#{CONFIG_PATH_IN_DOCKER}/pi_build_modifier.gem"
82
+ system "docker exec --tty \"$(cat cid)\" bash -c \"sudo gem install #{CONFIG_PATH_IN_DOCKER}/pi_build_modifier.gem\""
83
+ end
84
+
85
+ private def prepare_workspace
86
+ $logger.info "[Prepare | Docker] Clone git project: #{@workspace}"
87
+ system "docker exec --tty \"$(cat cid)\" bash -c \"sudo mkdir -p #{@workspace.workspace_directory}\""
88
+ #TODO: git clone vs git pull when code exists...
89
+ system "docker exec --tty \"$(cat cid)\" bash -c \"sudo git clone #{@workspace.git_path} #{@workspace.workspace_directory}\""
90
+ end
91
+
92
+ end
93
+ end
94
+ 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 'pi_customizer/utils/logex'
22
+
23
+ module PiCustomizer
24
+ module Environment
25
+
26
+ ##
27
+ # EnvironmentControl defines the build steps that must be supported for a concrete environment
28
+
29
+ class EnvironmentControl
30
+
31
+ attr_reader :workspace, :config
32
+
33
+ def initialize(remote_workspace, local_workspace)
34
+ @workspace = remote_workspace
35
+ @config = local_workspace
36
+ end
37
+
38
+ def check
39
+ $logger.warn '[Check] skipped...'
40
+ end
41
+
42
+ def prepare
43
+ $logger.warn '[Prepare] skipped...'
44
+ end
45
+
46
+ def start
47
+ $logger.warn '[Start] skipped...'
48
+ end
49
+
50
+ def build_image
51
+ $logger.warn '[Build Image] skipped...'
52
+ end
53
+
54
+ def publish
55
+ $logger.warn '[Publish] skipped...'
56
+ end
57
+
58
+ def clean_up
59
+ $logger.warn '[Clean up] skipped...'
60
+ end
61
+
62
+ def stop
63
+ $logger.warn '[Stop] skipped...'
64
+ end
65
+
66
+ def ensure
67
+ $logger.info '[Ensure] skipped...'
68
+ end
69
+
70
+ end
71
+ end
72
+ end
73
+