pi_customizer 0.1.1.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 +7 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +3 -0
- data/Rakefile +13 -0
- data/Vagrantfile +16 -0
- data/bin/pi_customizer +5 -0
- data/envs/aws/outputs.tf +3 -0
- data/envs/aws/pi-build-env.tf +160 -0
- data/envs/aws/variables.tf +55 -0
- data/envs/config.json +12 -0
- data/envs/docker/Dockerfile +6 -0
- data/envs/pi_build_modifier-0.1.0.gem +0 -0
- data/envs/pi_build_modifier.gem +0 -0
- data/envs/sh/build-pi-img.sh +28 -0
- data/envs/vagrant/Vagrantfile +56 -0
- data/lib/pi_customizer/builder/builder.rb +60 -0
- data/lib/pi_customizer/builder/prepare_start_execute_builder.rb +44 -0
- data/lib/pi_customizer/builder/start_prepare_execute_builder.rb +44 -0
- data/lib/pi_customizer/environment/aws/aws.rb +73 -0
- data/lib/pi_customizer/environment/docker/docker.rb +91 -0
- data/lib/pi_customizer/environment/environment.rb +61 -0
- data/lib/pi_customizer/environment/environment_builder_factory.rb +75 -0
- data/lib/pi_customizer/environment/vagrant/templates/Vagrantfile.erb +49 -0
- data/lib/pi_customizer/environment/vagrant/vagrant.rb +85 -0
- data/lib/pi_customizer/environment/vagrant/vagrant_file.rb +91 -0
- data/lib/pi_customizer/utils/logex.rb +25 -0
- data/lib/pi_customizer/version.rb +23 -0
- data/lib/pi_customizer/workspace/local_workspace.rb +50 -0
- data/lib/pi_customizer/workspace/remote_workspace.rb +53 -0
- data/lib/pi_customizer.rb +63 -0
- data/pi_customizer.gemspec +31 -0
- metadata +174 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
# Copyright (c) 2017 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 = '/config'
|
30
|
+
|
31
|
+
def check
|
32
|
+
$logger.info '[Check | Docker] Pre-flight checks are executing...'
|
33
|
+
ensure_docker
|
34
|
+
end
|
35
|
+
|
36
|
+
def start
|
37
|
+
$logger.info "[Start | Docker] Build docker image: #{DOCKERFILE}"
|
38
|
+
system "docker build --rm=true --file=#{DOCKERFILE} --tag=pi:build #{DOCKERFILE_PATH}"
|
39
|
+
$logger.info "[Start | Docker] Start docker image with volume #{@config.tmp_directory}:#{@workspace.workspace_directory}"
|
40
|
+
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"
|
41
|
+
end
|
42
|
+
|
43
|
+
def prepare
|
44
|
+
prepare_workspace
|
45
|
+
prepare_configuration
|
46
|
+
end
|
47
|
+
|
48
|
+
def build_image
|
49
|
+
$logger.info '[Build| Docker] customization of build sources'
|
50
|
+
system "sudo docker exec --tty \"$(cat cid)\" bash -c \"sudo pi_build_modifier modify #{CONFIG_PATH_IN_DOCKER}/config.json #{@workspace.workspace_directory}\""
|
51
|
+
$logger.info '[Build| Docker] pi-image build step'
|
52
|
+
system "sudo docker exec --tty \"$(cat cid)\" bash -c \"cd #{@workspace.workspace_directory} && sudo ./build.sh\"" #sudo chown docker #{@workspace.workspace_directory} &&
|
53
|
+
end
|
54
|
+
|
55
|
+
def clean_up
|
56
|
+
$logger.info '[Clean Up | Docker] pi-image remove contents of temporary container'
|
57
|
+
end
|
58
|
+
|
59
|
+
def stop
|
60
|
+
$logger.info '[Stop | Docker] Stop pi:build container'
|
61
|
+
#system 'docker stop "$(cat cid)"'
|
62
|
+
$logger.info '[Stop | Docker] RM pi:build container'
|
63
|
+
#system 'docker rm "$(cat cid)"'
|
64
|
+
#TODO: rm cid file!
|
65
|
+
end
|
66
|
+
|
67
|
+
private def ensure_docker
|
68
|
+
unless system 'docker -v'
|
69
|
+
raise 'Docker is not installed. Please ensure that Docker is running.'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private def prepare_configuration
|
74
|
+
$logger.info "[Prepare | Docker] Copy the configuration file from #{@config.config_path} to #{CONFIG_PATH_IN_DOCKER}/config.json in container"
|
75
|
+
system "docker exec --tty \"$(cat cid)\" bash -c \"sudo mkdir -p #{CONFIG_PATH_IN_DOCKER}\""
|
76
|
+
system "docker cp #{@config.config_path} \"$(cat cid)\":#{CONFIG_PATH_IN_DOCKER}/config.json"
|
77
|
+
gem_path = File.join(File.dirname(__FILE__), '/../../../../envs/pi_build_modifier.gem')
|
78
|
+
system "docker cp #{gem_path} \"$(cat cid)\":#{CONFIG_PATH_IN_DOCKER}/pi_build_modifier.gem"
|
79
|
+
system "docker exec --tty \"$(cat cid)\" bash -c \"sudo gem install #{CONFIG_PATH_IN_DOCKER}/pi_build_modifier.gem\""
|
80
|
+
end
|
81
|
+
|
82
|
+
private def prepare_workspace
|
83
|
+
$logger.info "[Prepare | Docker] Clone git project: #{@workspace}"
|
84
|
+
system "docker exec --tty \"$(cat cid)\" bash -c \"sudo mkdir -p #{@workspace.workspace_directory}\""
|
85
|
+
#TODO: git clone vs git pull when code exists...
|
86
|
+
system "docker exec --tty \"$(cat cid)\" bash -c \"sudo git clone #{@workspace.git_path} #{@workspace.workspace_directory}\""
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright (c) 2017 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 EnvironmentControl
|
26
|
+
|
27
|
+
attr_reader :workspace, :config
|
28
|
+
|
29
|
+
def initialize(workspace, config)
|
30
|
+
@workspace = workspace
|
31
|
+
@config = config
|
32
|
+
end
|
33
|
+
|
34
|
+
def check
|
35
|
+
$logger.warn '[Check] Pre-flight checks are skipped...'
|
36
|
+
end
|
37
|
+
|
38
|
+
def prepare
|
39
|
+
$logger.warn '[Prepare] Preparation steps are skipped...'
|
40
|
+
end
|
41
|
+
|
42
|
+
def start
|
43
|
+
$logger.warn '[Start] Environment is not started...'
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_image
|
47
|
+
$logger.warn '[Build Image] Missing build_image command'
|
48
|
+
end
|
49
|
+
|
50
|
+
def clean_up
|
51
|
+
$logger.warn '[Clean up] Missing clean_up command'
|
52
|
+
end
|
53
|
+
|
54
|
+
def stop
|
55
|
+
$logger.warn '[Stop] Missing stop command'
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Copyright (c) 2017 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/environment/environment'
|
22
|
+
require 'pi_customizer/environment/aws/aws'
|
23
|
+
require 'pi_customizer/environment/vagrant/vagrant'
|
24
|
+
require 'pi_customizer/environment/docker/docker'
|
25
|
+
require 'pi_customizer/builder/builder'
|
26
|
+
require 'pi_customizer/builder/prepare_start_execute_builder'
|
27
|
+
require 'pi_customizer/builder/start_prepare_execute_builder'
|
28
|
+
require 'pi_customizer/workspace/remote_workspace'
|
29
|
+
require 'pi_customizer/workspace/local_workspace'
|
30
|
+
require 'pi_customizer/utils/logex'
|
31
|
+
|
32
|
+
|
33
|
+
module PiCustomizer
|
34
|
+
module Environment
|
35
|
+
|
36
|
+
ENV_AWS = 'AWS'
|
37
|
+
ENV_VAGRANT = 'VAGRANT'
|
38
|
+
ENV_DOCKER = 'DOCKER'
|
39
|
+
ENV_ECHO = 'ECHO'
|
40
|
+
|
41
|
+
def Environment.environment_builder_factory(env, local_config, workspace)
|
42
|
+
|
43
|
+
environment = environment_factory(env, local_config, workspace)
|
44
|
+
|
45
|
+
case env
|
46
|
+
when ENV_AWS, ENV_VAGRANT
|
47
|
+
env_builder = Builder::PrepareExecuteBuilder.new(environment)
|
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)
|
51
|
+
else
|
52
|
+
$logger.warn 'No valid build environment defined!'
|
53
|
+
env_builder = Builder::PiBuilder.new(environment)
|
54
|
+
end
|
55
|
+
env_builder
|
56
|
+
end
|
57
|
+
|
58
|
+
def Environment.environment_factory(env, local_config, workspace)
|
59
|
+
case env
|
60
|
+
when ENV_AWS
|
61
|
+
environment = AWS.new(workspace, local_config)
|
62
|
+
when ENV_VAGRANT
|
63
|
+
environment = Vagrant.new(workspace, local_config)
|
64
|
+
when ENV_DOCKER
|
65
|
+
environment = Docker.new(workspace, local_config)
|
66
|
+
when ENV_ECHO
|
67
|
+
environment = EnvironmentControl.new(workspace, local_config)
|
68
|
+
else
|
69
|
+
$logger.info 'NO valid environment (e.g., AWS or VAGRANT) defined!'
|
70
|
+
environment = EnvironmentControl.new(workspace, local_config)
|
71
|
+
end
|
72
|
+
environment
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
$dependencies = <<SCRIPT
|
7
|
+
sudo apt update
|
8
|
+
sudo apt -y upgrade
|
9
|
+
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
|
11
|
+
SCRIPT
|
12
|
+
|
13
|
+
$prepare = <<SCRIPT
|
14
|
+
# install gem
|
15
|
+
gem install pi_customizer --pre
|
16
|
+
mkdir -p <%= workspace %>
|
17
|
+
if [ -f "<%= workspace %>" ]; then
|
18
|
+
git clone <%= git_path %> <%= workspace %>
|
19
|
+
else
|
20
|
+
git pull <%= git_path %> -r
|
21
|
+
end
|
22
|
+
SCRIPT
|
23
|
+
|
24
|
+
$modify = <<SCRIPT
|
25
|
+
# 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
|
30
|
+
SCRIPT
|
31
|
+
|
32
|
+
Vagrant.configure('2') do |config|
|
33
|
+
|
34
|
+
config.vm.box = 'debian/stretch64'
|
35
|
+
config.disksize.size = '<%= disk_size %>'
|
36
|
+
|
37
|
+
# Prepare environment by updating the dependencies
|
38
|
+
config.vm.provision 'shell', inline: $dependencies
|
39
|
+
|
40
|
+
# Copy config file
|
41
|
+
config.vm.provision "file", source: "<%= config_file_source %>", destination: "<%= config_file_destination %>"
|
42
|
+
|
43
|
+
# Prepare the modification
|
44
|
+
config.vm.provision 'shell', inline: $prepare
|
45
|
+
|
46
|
+
# Actually modify the build sources and then build the environment
|
47
|
+
config.vm.provision 'shell', inline: $modify
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# Copyright (c) 2017 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_relative 'vagrant_file'
|
23
|
+
require 'pi_customizer/utils/logex'
|
24
|
+
require 'pi_customizer/environment/environment'
|
25
|
+
|
26
|
+
module PiCustomizer
|
27
|
+
module Environment
|
28
|
+
class Vagrant < EnvironmentControl
|
29
|
+
|
30
|
+
VAGRANT_PATH = File.join(File.dirname(__FILE__), '/templates')
|
31
|
+
|
32
|
+
def check
|
33
|
+
$logger.info '[Check] Pre-flight checks are executing...'
|
34
|
+
ensure_vagrant
|
35
|
+
end
|
36
|
+
|
37
|
+
def prepare
|
38
|
+
$logger.info '[Prepare] pi-image in vagrant environment'
|
39
|
+
VagrantFileRenderer.new(VagrantFile.new(@config_path, @workspace)).create_from_template
|
40
|
+
end
|
41
|
+
|
42
|
+
def start
|
43
|
+
$logger.info '[Start] pi-image in local vagrant environment'
|
44
|
+
Dir.chdir(VAGRANT_PATH) do
|
45
|
+
system 'vagrant destroy -f' # cleanup old environment
|
46
|
+
system 'vagrant up --provider=virtualbox --no-provision'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_image
|
51
|
+
system 'vagrant provision'
|
52
|
+
#TODO: push finished product to some destination, e.g. an S3 bucket
|
53
|
+
end
|
54
|
+
|
55
|
+
def clean_up
|
56
|
+
$logger.info '[Clean Up] pi-image in local vagrant environment'
|
57
|
+
end
|
58
|
+
|
59
|
+
def stop
|
60
|
+
$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
|
70
|
+
system 'vagrant destroy -f'
|
71
|
+
system 'vagrant up --provider=virtualbox --provision'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
=end
|
75
|
+
|
76
|
+
def ensure_vagrant
|
77
|
+
unless system 'vagrant -v'
|
78
|
+
raise 'Vagrant not installed. Please ensure that vagrant is installed correctly.'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# Copyright (c) 2017 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 'erb'
|
22
|
+
require 'fileutils'
|
23
|
+
require 'pi_customizer/workspace/remote_workspace'
|
24
|
+
|
25
|
+
module PiCustomizer
|
26
|
+
module Environment
|
27
|
+
class VagrantFile
|
28
|
+
|
29
|
+
attr_accessor :vagrant_path, :disk_size, :config_file_destination, :config_file_source, :workspace, :git_path
|
30
|
+
|
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'
|
37
|
+
else
|
38
|
+
@config_file_source = config_path
|
39
|
+
end
|
40
|
+
if workspace.nil?
|
41
|
+
@git_path = Workspace::DEFAULT_GIT_PATH
|
42
|
+
@workspace =Workspace::DEFAULT_WORKSPACE_DIRECTORY
|
43
|
+
else
|
44
|
+
@git_path = workspace.git_path
|
45
|
+
@workspace = workspace.workspace_directory
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_binding
|
50
|
+
binding
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class VagrantFileRenderer
|
57
|
+
|
58
|
+
def initialize(vagrant_file)
|
59
|
+
@vagrant_file = vagrant_file
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_from_template
|
63
|
+
check_dependencies
|
64
|
+
read_template
|
65
|
+
write_rendered
|
66
|
+
end
|
67
|
+
|
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]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private def read_template
|
75
|
+
File.open(@vagrant_file.vagrant_path.to_s + 'Vagrantfile.erb', 'r+') do |f|
|
76
|
+
@template = f.read
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def render
|
81
|
+
ERB.new(@template).result(@vagrant_file.get_binding)
|
82
|
+
end
|
83
|
+
|
84
|
+
private def write_rendered
|
85
|
+
File.open(@vagrant_file.vagrant_path.to_s + 'Vagrantfile', 'w+') do |f|
|
86
|
+
f.write(render)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright (c) 2017 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 'logger'
|
22
|
+
|
23
|
+
module PiCustomizer
|
24
|
+
$logger = Logger.new(STDOUT)
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Copyright (c) 2017 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
|
+
module PiCustomizer
|
22
|
+
VERSION = '0.1.1-alpha'
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright (c) 2017 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
|
+
|
24
|
+
module PiCustomizer
|
25
|
+
module Workspace
|
26
|
+
|
27
|
+
DEFAULT_CONFIG_PATH = File.join(File.dirname(__FILE__), '/../../../envs/config.json')
|
28
|
+
DEFAULT_TMP_DIRECTORY = Dir.getwd + '/tmp'
|
29
|
+
|
30
|
+
class LocalConfig
|
31
|
+
|
32
|
+
attr_reader :config_path, :tmp_directory
|
33
|
+
|
34
|
+
def initialize(config_path = '', tmp_directory = '')
|
35
|
+
@config_path = if config_path.nil? or config_path == ''
|
36
|
+
DEFAULT_CONFIG_PATH
|
37
|
+
else
|
38
|
+
config_path.to_s
|
39
|
+
end
|
40
|
+
@tmp_directory = if tmp_directory.nil? or tmp_directory == ''
|
41
|
+
DEFAULT_TMP_DIRECTORY
|
42
|
+
else
|
43
|
+
tmp_directory.to_s
|
44
|
+
end
|
45
|
+
$logger.debug "Local Config at '#{@config_path}' with tmp dir '#{@tmp_directory}'"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright (c) 2017 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
|
+
|
24
|
+
module PiCustomizer
|
25
|
+
module Workspace
|
26
|
+
|
27
|
+
DEFAULT_WORKSPACE_DIRECTORY = '/build/pi-gen'
|
28
|
+
DEFAULT_GIT_PATH = 'https://github.com/ottenwbe/pi-gen.git'
|
29
|
+
|
30
|
+
class Workspace
|
31
|
+
|
32
|
+
attr_reader :git_path, :workspace_directory
|
33
|
+
|
34
|
+
def initialize(workspace_dir = '', git_path = '')
|
35
|
+
$logger.debug "Workspace at '#{workspace_dir}' with source '#{git_path}'"
|
36
|
+
@workspace_directory = if workspace_dir.nil? or workspace_dir == ''
|
37
|
+
DEFAULT_WORKSPACE_DIRECTORY
|
38
|
+
else
|
39
|
+
workspace_dir.to_s
|
40
|
+
end
|
41
|
+
@git_path = if git_path.nil? or git_path == ''
|
42
|
+
DEFAULT_GIT_PATH
|
43
|
+
else
|
44
|
+
git_path.to_s
|
45
|
+
end
|
46
|
+
$logger.debug "Workspace at '#{@workspace_directory}' with source '#{@git_path}'"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Copyright (c) 2017 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/environment/environment_builder_factory'
|
25
|
+
require 'pi_customizer/workspace/remote_workspace'
|
26
|
+
require 'pi_customizer/workspace/local_workspace'
|
27
|
+
|
28
|
+
module PiCustomizer
|
29
|
+
|
30
|
+
##
|
31
|
+
# The pi_customizer's cli
|
32
|
+
|
33
|
+
class PiCustomizer < Thor
|
34
|
+
|
35
|
+
##
|
36
|
+
# The build command can be called to trigger a build of a pi image
|
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'
|
40
|
+
method_option :workspace, :default => Workspace::DEFAULT_WORKSPACE_DIRECTORY, :aliases => '-w'
|
41
|
+
method_option :deploy_dir, :default => Dir.getwd, :aliases => '-d'
|
42
|
+
method_option :config_file, :default => Workspace::DEFAULT_CONFIG_PATH, :aliases => '-c'
|
43
|
+
method_option :tmp_folder, :default => Workspace::DEFAULT_TMP_DIRECTORY, :aliases => '-t'
|
44
|
+
def build(env)
|
45
|
+
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)
|
49
|
+
builder.build
|
50
|
+
rescue Exception => e
|
51
|
+
$logger.error e.message
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# The version command prints the current version of the pi_customizer gem to the command line
|
57
|
+
|
58
|
+
desc 'version', 'Shows the version number.'
|
59
|
+
def version
|
60
|
+
puts VERSION
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|