pi_customizer 0.1.1.pre.alpha → 0.1.2.pre.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f698a621a439c36c15d29b5f7b6541038db705b5
4
- data.tar.gz: 051fe8cac727d42da227c6573225912c8e2cb718
3
+ metadata.gz: 82107bf6c11e36cecbd418fa1f81ca000de390ae
4
+ data.tar.gz: f7b844fbbbc25d3f55734016b7da402140046327
5
5
  SHA512:
6
- metadata.gz: 89b188d2ca8396f7c1d4f755d4559d5f0b69e4d95db6c0c4d8ae1d1fb573dd812d17aba3dd7977f3a668e3169be260852f4cc6a68e67d90fd5d7189481dbe5b6
7
- data.tar.gz: 172527c3fbf8c3bb2f9b52fd20d9b8e4de7943d01386ea86d3bbb0dc1699a01a454949c4d3d8eba5cd8004d8c6886c4d4fb78b49768211b5be62a0fa0949e171
6
+ metadata.gz: 2566295f0a85408526a356f5e481e9a14f915e7969464300abfa6411a0230e1e3b2b0039bb65756916b355b7862cdf064ccab7ce8909e3f9492bf650926db954
7
+ data.tar.gz: '0480eb4e02291f2a3a0a6c4151f01de65e4031ee0416474148d713e0cc938f8c9a85c3e031fa1aa520e5be70a94c0e8ad9c343c981149e5e9653984f6f92cdac'
Binary file
@@ -27,10 +27,10 @@ module PiCustomizer
27
27
  protected def start
28
28
  @env.check
29
29
  @env.prepare
30
+ @env.start
30
31
  end
31
32
 
32
33
  protected def execute
33
- @env.start
34
34
  @env.build_image
35
35
  end
36
36
 
@@ -22,7 +22,7 @@ require 'pi_customizer/builder/builder'
22
22
 
23
23
  module PiCustomizer
24
24
  module Builder
25
- class StartStopBuilder < PiBuilder
25
+ class StartExecuteBuilder < PiBuilder
26
26
 
27
27
  protected def start
28
28
  @env.check
@@ -38,16 +38,16 @@ module PiCustomizer
38
38
  ENV_DOCKER = 'DOCKER'
39
39
  ENV_ECHO = 'ECHO'
40
40
 
41
- def Environment.environment_builder_factory(env, local_config, workspace)
41
+ def Environment.environment_builder_factory(env, local_workspace, remote_workspace)
42
42
 
43
- environment = environment_factory(env, local_config, workspace)
43
+ environment = environment_factory(env, local_workspace, remote_workspace)
44
44
 
45
45
  case env
46
46
  when ENV_AWS, ENV_VAGRANT
47
47
  env_builder = Builder::PrepareExecuteBuilder.new(environment)
48
48
  when ENV_DOCKER, ENV_ECHO
49
- puts "Echo: - Git Path: #{workspace.git_path}, Workspace Path: #{workspace.workspace_directory}, Config Path: #{local_config.config_path}"
50
- env_builder = Builder::StartStopBuilder.new(environment)
49
+ puts "Echo: - Git Path: #{remote_workspace.git_path}, Workspace Path: #{remote_workspace.workspace_directory}, Config Path: #{local_workspace.config_path}"
50
+ env_builder = Builder::StartExecuteBuilder.new(environment)
51
51
  else
52
52
  $logger.warn 'No valid build environment defined!'
53
53
  env_builder = Builder::PiBuilder.new(environment)
@@ -55,19 +55,19 @@ module PiCustomizer
55
55
  env_builder
56
56
  end
57
57
 
58
- def Environment.environment_factory(env, local_config, workspace)
58
+ def Environment.environment_factory(env, local_workspace, remote_workspace)
59
59
  case env
60
60
  when ENV_AWS
61
- environment = AWS.new(workspace, local_config)
61
+ environment = AWS.new(remote_workspace, local_workspace)
62
62
  when ENV_VAGRANT
63
- environment = Vagrant.new(workspace, local_config)
63
+ environment = Vagrant.new(remote_workspace, local_workspace)
64
64
  when ENV_DOCKER
65
- environment = Docker.new(workspace, local_config)
65
+ environment = Docker.new(remote_workspace, local_workspace)
66
66
  when ENV_ECHO
67
- environment = EnvironmentControl.new(workspace, local_config)
67
+ environment = EnvironmentControl.new(remote_workspace, local_workspace)
68
68
  else
69
69
  $logger.info 'NO valid environment (e.g., AWS or VAGRANT) defined!'
70
- environment = EnvironmentControl.new(workspace, local_config)
70
+ environment = EnvironmentControl.new(remote_workspace, local_workspace)
71
71
  end
72
72
  environment
73
73
  end
@@ -1,44 +1,57 @@
1
1
  # -*- mode: ruby -*-
2
2
  # vi: set ft=ruby :
3
3
 
4
- require 'fileutils'
5
-
6
4
  $dependencies = <<SCRIPT
7
5
  sudo apt update
8
6
  sudo apt -y upgrade
9
7
  sudo apt -y install quilt parted qemu-user-static debootstrap zerofree pxz zip dosfstools libcap2-bin bsdtar
10
- sudo apt -y install git curl ruby-full
8
+ sudo apt -y install git curl ruby-full build-essential
11
9
  SCRIPT
12
10
 
13
- $prepare = <<SCRIPT
11
+ $install_modifier_gem = <<SCRIPT
14
12
  # install gem
15
- gem install pi_customizer --pre
16
- mkdir -p <%= workspace %>
17
- if [ -f "<%= workspace %>" ]; then
18
- git clone <%= git_path %> <%= workspace %>
13
+ <% if config.modifier_gem_path.nil? %>gem install pi_build_modifier --pre <% else %>gem install /home/ubuntu/pi_build_modifier.gem<% end %>
14
+ SCRIPT
15
+
16
+ $prepare = <<SCRIPT
17
+ mkdir -p <%= workspace.workspace_directory %>
18
+ if [ -f "<%= workspace.workspace_directory %>" ]; then
19
+ echo 'git pull to workspace'
20
+ git pull <%= workspace.git_path %> <%= workspace.workspace_directory %> -r
19
21
  else
20
- git pull <%= git_path %> -r
21
- end
22
+ echo 'git clone to workspace'
23
+ git clone <%= workspace.git_path %> <%= workspace.workspace_directory %>
24
+ fi
22
25
  SCRIPT
23
26
 
24
27
  $modify = <<SCRIPT
25
28
  # Execute gem with parameters
26
- cd <%= workspace %>
27
- pi_build_modifier modify --config-file=<%= config_file_destination %>
28
- sh build.sh
29
- mv deploy/* /vagrant
29
+ cd <%= workspace.workspace_directory %>
30
+ pi_build_modifier modify <%= config_file_destination %> <%= workspace.workspace_directory %>
31
+ sudo ./build.sh
32
+ cp -r deploy /vagrant
30
33
  SCRIPT
31
34
 
32
35
  Vagrant.configure('2') do |config|
33
36
 
34
- config.vm.box = 'debian/stretch64'
37
+ config.vm.box = 'ubuntu/xenial64' #Note, that 'debian/stretch64' cannot be resized with the disksize plugin
38
+
39
+ unless Vagrant.has_plugin?("vagrant-disksize")
40
+ raise 'vagrant-disksize plugin is not installed! Use: vagrant plugin install vagrant-disksize'
41
+ end
42
+
35
43
  config.disksize.size = '<%= disk_size %>'
36
44
 
37
45
  # Prepare environment by updating the dependencies
38
46
  config.vm.provision 'shell', inline: $dependencies
39
47
 
48
+ <% unless config.modifier_gem_path.nil? %>config.vm.provision 'file', source: '<%= config.modifier_gem_path.to_s %>', destination: '/home/ubuntu/pi_build_modifier.gem' <% end %>
49
+
50
+ # Modifier gem is installed
51
+ config.vm.provision 'shell', inline: $install_modifier_gem
52
+
40
53
  # Copy config file
41
- config.vm.provision "file", source: "<%= config_file_source %>", destination: "<%= config_file_destination %>"
54
+ config.vm.provision 'file', source: '<%= config.config_path.to_s %>', destination: '<%= config_file_destination %>'
42
55
 
43
56
  # Prepare the modification
44
57
  config.vm.provision 'shell', inline: $prepare
@@ -27,7 +27,7 @@ module PiCustomizer
27
27
  module Environment
28
28
  class Vagrant < EnvironmentControl
29
29
 
30
- VAGRANT_PATH = File.join(File.dirname(__FILE__), '/templates')
30
+ VAGRANT_SOURCE = File.join(File.dirname(__FILE__), '/templates')
31
31
 
32
32
  def check
33
33
  $logger.info '[Check] Pre-flight checks are executing...'
@@ -36,20 +36,22 @@ module PiCustomizer
36
36
 
37
37
  def prepare
38
38
  $logger.info '[Prepare] pi-image in vagrant environment'
39
- VagrantFileRenderer.new(VagrantFile.new(@config_path, @workspace)).create_from_template
39
+ VagrantFileRenderer.new(VagrantFile.new(@config, @workspace)).create_from_template
40
40
  end
41
41
 
42
42
  def start
43
43
  $logger.info '[Start] pi-image in local vagrant environment'
44
- Dir.chdir(VAGRANT_PATH) do
44
+ Dir.chdir(@config.tmp_directory) do
45
45
  system 'vagrant destroy -f' # cleanup old environment
46
46
  system 'vagrant up --provider=virtualbox --no-provision'
47
47
  end
48
48
  end
49
49
 
50
50
  def build_image
51
- system 'vagrant provision'
52
- #TODO: push finished product to some destination, e.g. an S3 bucket
51
+ $logger.info '[Build] pi-image in local vagrant environment'
52
+ Dir.chdir(@config.tmp_directory) do
53
+ system 'vagrant provision'
54
+ end
53
55
  end
54
56
 
55
57
  def clean_up
@@ -58,20 +60,10 @@ module PiCustomizer
58
60
 
59
61
  def stop
60
62
  $logger.info '[Stop] pi-image in local vagrant environment'
61
- Dir.chdir(VAGRANT_PATH) do
62
- system 'vagrant destroy -f'
63
- end
64
- end
65
-
66
- =begin
67
- def build
68
- $logger.info 'Building pi-image in local vagrant environment'
69
- Dir.chdir(VAGRANT_PATH) do
63
+ Dir.chdir(@config.tmp_directory) do
70
64
  system 'vagrant destroy -f'
71
- system 'vagrant up --provider=virtualbox --provision'
72
65
  end
73
66
  end
74
- =end
75
67
 
76
68
  def ensure_vagrant
77
69
  unless system 'vagrant -v'
@@ -21,28 +21,31 @@
21
21
  require 'erb'
22
22
  require 'fileutils'
23
23
  require 'pi_customizer/workspace/remote_workspace'
24
+ require 'pi_customizer/workspace/local_workspace'
24
25
 
25
26
  module PiCustomizer
26
27
  module Environment
28
+
29
+ ##
30
+ # VagrantFile describes the dynamic attributes of the Vagrantfile which is used to start up the vagrant environment
31
+
27
32
  class VagrantFile
28
33
 
29
- attr_accessor :vagrant_path, :disk_size, :config_file_destination, :config_file_source, :workspace, :git_path
34
+ attr_accessor :vagrant_template_path, :disk_size, :config_file_destination, :workspace, :config
30
35
 
31
- def initialize(config_path, workspace)
32
- @vagrant_path = File.join(File.dirname(__FILE__), '/templates/')
33
- @disk_size = '20GB'
34
- @config_file_destination = '~/conf.json'
35
- if config_path.nil? || config_path.empty?
36
- @config_file_source = 'conf.json'
36
+ def initialize(config, workspace)
37
+ @vagrant_template_path = File.join(File.dirname(__FILE__), '/templates/Vagrantfile.erb')
38
+ @disk_size = '40GB'
39
+ @config_file_destination = '/vagrant/conf.json'
40
+ if config.nil?
41
+ @config = Workspace::LocalWorkspace.new
37
42
  else
38
- @config_file_source = config_path
43
+ @config = config
39
44
  end
40
45
  if workspace.nil?
41
- @git_path = Workspace::DEFAULT_GIT_PATH
42
- @workspace =Workspace::DEFAULT_WORKSPACE_DIRECTORY
46
+ @workspace = Workspace::RemoteWorkspace.new
43
47
  else
44
- @git_path = workspace.git_path
45
- @workspace = workspace.workspace_directory
48
+ @workspace = workspace
46
49
  end
47
50
  end
48
51
 
@@ -51,41 +54,42 @@ module PiCustomizer
51
54
  end
52
55
 
53
56
  end
54
- end
55
57
 
56
- class VagrantFileRenderer
57
58
 
58
- def initialize(vagrant_file)
59
- @vagrant_file = vagrant_file
60
- end
59
+ class VagrantFileRenderer
61
60
 
62
- def create_from_template
63
- check_dependencies
64
- read_template
65
- write_rendered
66
- end
61
+ def initialize(vagrant_file)
62
+ @vagrant_file = vagrant_file
63
+ end
67
64
 
68
- private def check_dependencies
69
- unless File.file?(@vagrant_file.vagrant_path.to_s + 'Vagrantfile.erb')
70
- raise "'Vagrantfile.erb' template not specified. Searching in path '%s'" % [@vagrant_file.vagrant_path]
65
+ def create_from_template
66
+ check_dependencies
67
+ read_template
68
+ write_vagrantfile
69
+ end
70
+
71
+ private def check_dependencies
72
+ unless File.file?(@vagrant_file.vagrant_template_path.to_s)
73
+ raise "'Vagrantfile.erb' template not specified. Expected template in path '%s'" % [@vagrant_file.vagrant_template_path]
74
+ end
71
75
  end
72
- end
73
76
 
74
- private def read_template
75
- File.open(@vagrant_file.vagrant_path.to_s + 'Vagrantfile.erb', 'r+') do |f|
76
- @template = f.read
77
+ private def read_template
78
+ File.open(@vagrant_file.vagrant_template_path.to_s, 'r+') do |f|
79
+ @template = f.read
80
+ end
77
81
  end
78
- end
79
82
 
80
- def render
81
- ERB.new(@template).result(@vagrant_file.get_binding)
82
- end
83
+ def render
84
+ ERB.new(@template).result(@vagrant_file.get_binding)
85
+ end
83
86
 
84
- private def write_rendered
85
- File.open(@vagrant_file.vagrant_path.to_s + 'Vagrantfile', 'w+') do |f|
86
- f.write(render)
87
+ private def write_vagrantfile
88
+ FileUtils.mkdir_p @vagrant_file.config.tmp_directory
89
+ File.open(@vagrant_file.config.tmp_directory.to_s + '/Vagrantfile', 'w+') do |f|
90
+ f.write(render)
91
+ end
87
92
  end
88
93
  end
89
-
90
94
  end
91
95
  end
@@ -19,5 +19,9 @@
19
19
  # SOFTWARE.
20
20
 
21
21
  module PiCustomizer
22
- VERSION = '0.1.1-alpha'
22
+
23
+ ##
24
+ # The current version of the pi_customizer gem
25
+
26
+ VERSION = '0.1.2-alpha'
23
27
  end
@@ -19,32 +19,74 @@
19
19
  # SOFTWARE.
20
20
 
21
21
  require 'fileutils'
22
+ require 'pathname'
22
23
  require 'pi_customizer/utils/logex'
23
24
 
24
25
  module PiCustomizer
25
26
  module Workspace
26
27
 
28
+ ##
29
+ # The default path which points to the configuration file
30
+
27
31
  DEFAULT_CONFIG_PATH = File.join(File.dirname(__FILE__), '/../../../envs/config.json')
28
- DEFAULT_TMP_DIRECTORY = Dir.getwd + '/tmp'
29
32
 
30
- class LocalConfig
33
+ ##
34
+ # The default directory which is used to store temporary build files, e.g., the Vagrantfile for a build with vagrant
35
+
36
+ DEFAULT_TMP_DIRECTORY = Dir.pwd + '/tmp'
37
+
38
+ ##
39
+ # The LocalWorkspace class encapsulates the configuration of the workspace on the machine where the build of the pi image is triggered
40
+
41
+ class LocalWorkspace
42
+
43
+ attr_reader :config_path, :tmp_directory, :modifier_gem_path
44
+
45
+ def initialize(config_path = '', tmp_directory = '', modifier_gem_path = '')
46
+ self.config_path = config_path
47
+ self.tmp_directory = tmp_directory
48
+ self.modifier_gem_path = modifier_gem_path
49
+ $logger.debug "Local Workspace is at '#{@config_path}' with tmp directory '#{@tmp_directory}' and modifier_gem_path '#{@modifier_gem_path}'"
50
+ end
51
+
52
+ ##
53
+ # Checks for value equality between a pair of LocalWorkspace's attributes
31
54
 
32
- attr_reader :config_path, :tmp_directory
55
+ def ==(other)
56
+ (@tmp_directory == other.tmp_directory) && (@modifier_gem_path == other.modifier_gem_path) && (@config_path == other.config_path)
57
+ end
33
58
 
34
- def initialize(config_path = '', tmp_directory = '')
59
+ private def config_path=(config_path)
35
60
  @config_path = if config_path.nil? or config_path == ''
36
- DEFAULT_CONFIG_PATH
61
+ Pathname.new(DEFAULT_CONFIG_PATH)
37
62
  else
38
- config_path.to_s
63
+ absolute_path_name(config_path)
39
64
  end
65
+ end
66
+
67
+ private def tmp_directory=(tmp_directory)
40
68
  @tmp_directory = if tmp_directory.nil? or tmp_directory == ''
41
- DEFAULT_TMP_DIRECTORY
69
+ Pathname.new(DEFAULT_TMP_DIRECTORY)
42
70
  else
43
- tmp_directory.to_s
71
+ absolute_path_name(tmp_directory)
44
72
  end
45
- $logger.debug "Local Config at '#{@config_path}' with tmp dir '#{@tmp_directory}'"
46
73
  end
47
74
 
75
+ private def modifier_gem_path=(modifier_gem_path)
76
+ @modifier_gem_path = if modifier_gem_path.nil? or modifier_gem_path == ''
77
+ nil
78
+ else
79
+ absolute_path_name(modifier_gem_path)
80
+ end
81
+ end
82
+
83
+ private def absolute_path_name(path)
84
+ tmp_path = Pathname.new(path)
85
+ if tmp_path.relative?
86
+ tmp_path = File.expand_path(path, Dir.pwd)
87
+ end
88
+ tmp_path
89
+ end
48
90
  end
49
91
  end
50
92
  end
@@ -27,7 +27,10 @@ module PiCustomizer
27
27
  DEFAULT_WORKSPACE_DIRECTORY = '/build/pi-gen'
28
28
  DEFAULT_GIT_PATH = 'https://github.com/ottenwbe/pi-gen.git'
29
29
 
30
- class Workspace
30
+ ##
31
+ # The RemoteWorkspace class encapsulates the configuration of the workspace in the build environment
32
+
33
+ class RemoteWorkspace
31
34
 
32
35
  attr_reader :git_path, :workspace_directory
33
36
 
@@ -46,6 +49,13 @@ module PiCustomizer
46
49
  $logger.debug "Workspace at '#{@workspace_directory}' with source '#{@git_path}'"
47
50
  end
48
51
 
52
+ ##
53
+ # Checks for value equality between a pair of RemoteWorkspace's attributes
54
+
55
+ def ==(other)
56
+ (@git_path == other.git_path) && (@workspace_directory == other.workspace_directory)
57
+ end
58
+
49
59
  end
50
60
  end
51
61
  end
data/lib/pi_customizer.rb CHANGED
@@ -28,24 +28,25 @@ require 'pi_customizer/workspace/local_workspace'
28
28
  module PiCustomizer
29
29
 
30
30
  ##
31
- # The pi_customizer's cli
31
+ # PiCustomizer defines all of pi_customizer's cli commands
32
32
 
33
33
  class PiCustomizer < Thor
34
34
 
35
35
  ##
36
36
  # The build command can be called to trigger a build of a pi image
37
37
 
38
- desc 'build ENV', 'Build pi image on environment ENV (options are AWS or VAGRANT).'
39
- method_option :git_path, :default => Workspace::DEFAULT_GIT_PATH, :aliases => '-g'
38
+ desc 'build ENV', 'Build pi image on environment ENV (valid environments are DOCKER, AWS or VAGRANT).'
39
+ method_option :git_build_sources, :default => Workspace::DEFAULT_GIT_PATH, :aliases => '-g'
40
40
  method_option :workspace, :default => Workspace::DEFAULT_WORKSPACE_DIRECTORY, :aliases => '-w'
41
41
  method_option :deploy_dir, :default => Dir.getwd, :aliases => '-d'
42
42
  method_option :config_file, :default => Workspace::DEFAULT_CONFIG_PATH, :aliases => '-c'
43
43
  method_option :tmp_folder, :default => Workspace::DEFAULT_TMP_DIRECTORY, :aliases => '-t'
44
+ method_option :modifier_gem_path, :default => '', :aliases => '-m'
44
45
  def build(env)
45
46
  begin
46
- workspace = Workspace::Workspace.new("#{options[:workspace]}", "#{options[:git_path]}")
47
- local_config = Workspace::LocalConfig.new("#{options[:config_file]}", "#{options[:tmp_folder]}")
48
- builder = Environment::environment_builder_factory(env, local_config, workspace)
47
+ remote_workspace = Workspace::RemoteWorkspace.new("#{options[:workspace]}", "#{options[:git_build_sources]}")
48
+ local_workspace = Workspace::LocalWorkspace.new("#{options[:config_file]}", "#{options[:tmp_folder]}", "#{options[:modifier_gem_path]}")
49
+ builder = Environment::environment_builder_factory(env, local_workspace, remote_workspace)
49
50
  builder.build
50
51
  rescue Exception => e
51
52
  $logger.error e.message
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pi_customizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1.pre.alpha
4
+ version: 0.1.2.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beate Ottenwälder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-09 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler