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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f698a621a439c36c15d29b5f7b6541038db705b5
|
4
|
+
data.tar.gz: 051fe8cac727d42da227c6573225912c8e2cb718
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 89b188d2ca8396f7c1d4f755d4559d5f0b69e4d95db6c0c4d8ae1d1fb573dd812d17aba3dd7977f3a668e3169be260852f4cc6a68e67d90fd5d7189481dbe5b6
|
7
|
+
data.tar.gz: 172527c3fbf8c3bb2f9b52fd20d9b8e4de7943d01386ea86d3bbb0dc1699a01a454949c4d3d8eba5cd8004d8c6886c4d4fb78b49768211b5be62a0fa0949e171
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Beate Ottenwälder
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
lib = File.join(File.dirname(__FILE__), '/lib')
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
task :default => :spec
|
10
|
+
|
11
|
+
rescue LoadError
|
12
|
+
puts 'RSpec or Bundler is not installed. This means rake is not able to execute tests!'
|
13
|
+
end
|
data/Vagrantfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
Vagrant.configure('2') do |config|
|
5
|
+
|
6
|
+
config.vm.box = "ubuntu/xenial64"
|
7
|
+
|
8
|
+
config.vm.provision 'shell', inline: <<-SHELL
|
9
|
+
sudo apt update
|
10
|
+
sudo apt -y install build-essential ruby-full
|
11
|
+
gem install bundler
|
12
|
+
cd /vagrant
|
13
|
+
bundle install
|
14
|
+
rake spec
|
15
|
+
SHELL
|
16
|
+
end
|
data/bin/pi_customizer
ADDED
data/envs/aws/outputs.tf
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
/* Setup the aws provider */
|
2
|
+
provider "aws" {
|
3
|
+
access_key = "${var.access_key}"
|
4
|
+
secret_key = "${var.secret_key}"
|
5
|
+
region = "${var.region}"
|
6
|
+
}
|
7
|
+
|
8
|
+
/* Define the vpc */
|
9
|
+
resource "aws_vpc" "pi_builder_vpc" {
|
10
|
+
cidr_block = "${var.vpc_cidr}"
|
11
|
+
enable_dns_hostnames = true
|
12
|
+
|
13
|
+
tags {
|
14
|
+
name = "pi-builder vpc"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
/** key for deployment of jumpbox and nat */
|
19
|
+
resource "aws_key_pair" "pi_builder_key" {
|
20
|
+
key_name = "pi-builder"
|
21
|
+
public_key = "${file("${var.ssh_path}/pi-builder.pub")}"
|
22
|
+
}
|
23
|
+
|
24
|
+
|
25
|
+
/** pi-build-vm instance */
|
26
|
+
resource "aws_instance" "pi_builder_vm" {
|
27
|
+
ami = "${lookup(var.amis, var.region)}"
|
28
|
+
availability_zone = "${var.default_az}"
|
29
|
+
instance_type = "t2.micro"
|
30
|
+
subnet_id = "${aws_subnet.pi_builder_subnet.id}"
|
31
|
+
|
32
|
+
root_block_device {
|
33
|
+
delete_on_termination = true
|
34
|
+
iops = 0
|
35
|
+
volume_size = 50
|
36
|
+
volume_type = "gp2"
|
37
|
+
}
|
38
|
+
|
39
|
+
vpc_security_group_ids = [
|
40
|
+
"${aws_security_group.ssh.id}",
|
41
|
+
"${aws_security_group.http.id}"]
|
42
|
+
key_name = "${aws_key_pair.pi_builder_key.key_name}"
|
43
|
+
|
44
|
+
provisioner "file" {
|
45
|
+
connection {
|
46
|
+
user = "ubuntu"
|
47
|
+
host = "${aws_instance.pi_builder_vm.public_dns}"
|
48
|
+
timeout = "25m"
|
49
|
+
private_key = "${file("${var.ssh_path}/pi-builder.pem")}"
|
50
|
+
}
|
51
|
+
source = "../sh/build-pi-img.sh"
|
52
|
+
destination = "/home/ubuntu/build-pi-img.sh"
|
53
|
+
}
|
54
|
+
|
55
|
+
provisioner "remote-exec" {
|
56
|
+
connection {
|
57
|
+
user = "ubuntu"
|
58
|
+
host = "${aws_instance.pi_builder_vm.public_dns}"
|
59
|
+
timeout = "25m"
|
60
|
+
private_key = "${file("${var.ssh_path}/pi-builder.pem")}"
|
61
|
+
}
|
62
|
+
inline = [
|
63
|
+
"sh build-pi-img.sh"
|
64
|
+
]
|
65
|
+
}
|
66
|
+
|
67
|
+
tags = {
|
68
|
+
name = "pi-builder vm"
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
resource "aws_eip" "lb" {
|
73
|
+
instance = "${aws_instance.pi_builder_vm.id}"
|
74
|
+
vpc = true
|
75
|
+
}
|
76
|
+
|
77
|
+
resource "aws_security_group" "ssh" {
|
78
|
+
name = "ssh"
|
79
|
+
description = "SSH access to instances from the internet"
|
80
|
+
vpc_id = "${aws_vpc.pi_builder_vpc.id}"
|
81
|
+
|
82
|
+
ingress {
|
83
|
+
from_port = 22
|
84
|
+
to_port = 22
|
85
|
+
protocol = "tcp"
|
86
|
+
|
87
|
+
cidr_blocks = [
|
88
|
+
"0.0.0.0/0",
|
89
|
+
]
|
90
|
+
}
|
91
|
+
|
92
|
+
tags {
|
93
|
+
name = "ssh sg"
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
resource "aws_security_group" "http" {
|
98
|
+
|
99
|
+
name = "http"
|
100
|
+
description = "Outbound http(s) connections."
|
101
|
+
vpc_id = "${aws_vpc.pi_builder_vpc.id}"
|
102
|
+
|
103
|
+
egress {
|
104
|
+
from_port = 80
|
105
|
+
to_port = 80
|
106
|
+
protocol = "tcp"
|
107
|
+
cidr_blocks = [
|
108
|
+
"0.0.0.0/0"]
|
109
|
+
}
|
110
|
+
|
111
|
+
egress {
|
112
|
+
from_port = 443
|
113
|
+
to_port = 443
|
114
|
+
protocol = "tcp"
|
115
|
+
cidr_blocks = [
|
116
|
+
"0.0.0.0/0"]
|
117
|
+
}
|
118
|
+
|
119
|
+
tags {
|
120
|
+
name = "http sg"
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
/** internet access */
|
125
|
+
resource "aws_internet_gateway" "pi_builder_gateway" {
|
126
|
+
vpc_id = "${aws_vpc.pi_builder_vpc.id}"
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
/** public subnet for the nat instance and the jumpbox */
|
131
|
+
resource "aws_subnet" "pi_builder_subnet" {
|
132
|
+
vpc_id = "${aws_vpc.pi_builder_vpc.id}"
|
133
|
+
cidr_block = "${var.public_subnet_cidr}"
|
134
|
+
availability_zone = "${var.default_az}"
|
135
|
+
map_public_ip_on_launch = true
|
136
|
+
depends_on = [
|
137
|
+
"aws_internet_gateway.pi_builder_gateway"]
|
138
|
+
|
139
|
+
tags {
|
140
|
+
name = "pi-builder subnet"
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
resource "aws_route_table" "pi_builder_rt" {
|
145
|
+
vpc_id = "${aws_vpc.pi_builder_vpc.id}"
|
146
|
+
|
147
|
+
route {
|
148
|
+
cidr_block = "0.0.0.0/0"
|
149
|
+
gateway_id = "${aws_internet_gateway.pi_builder_gateway.id}"
|
150
|
+
}
|
151
|
+
|
152
|
+
tags {
|
153
|
+
name = "pi-builder rt"
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
resource "aws_route_table_association" "pi_builder_rta" {
|
158
|
+
subnet_id = "${aws_subnet.pi_builder_subnet.id}"
|
159
|
+
route_table_id = "${aws_route_table.pi_builder_rt.id}"
|
160
|
+
}
|
@@ -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
|
+
}
|
data/envs/config.json
ADDED
Binary file
|
Binary file
|
@@ -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,56 @@
|
|
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
|
+
if [ -f "pi_build_modifier.gem" ]; then
|
16
|
+
echo "Gem exists"
|
17
|
+
else
|
18
|
+
gem install --local pi_build_modifier.gem
|
19
|
+
end
|
20
|
+
mkdir /build/pi-gen
|
21
|
+
if [ -f "/build/pi-gen" ]; then
|
22
|
+
git clone https://github.com/ottenwbe/pi-gen.git /build/pi-gen
|
23
|
+
else
|
24
|
+
git pull https://github.com/ottenwbe/pi-gen.git -r
|
25
|
+
end
|
26
|
+
SCRIPT
|
27
|
+
|
28
|
+
$modify = <<SCRIPT
|
29
|
+
# Execute gem with parameters
|
30
|
+
pi_build_modifier ~/conf.json
|
31
|
+
SCRIPT
|
32
|
+
|
33
|
+
Vagrant.configure('2') do |config|
|
34
|
+
|
35
|
+
config.vm.box = 'debian/stretch64'
|
36
|
+
config.disksize.size = '20GB'
|
37
|
+
|
38
|
+
# Prepare environment by updating the dependencies
|
39
|
+
config.vm.provision 'shell', inline: $dependencies
|
40
|
+
|
41
|
+
# Copy config file
|
42
|
+
config.vm.provision "file", source: "conf.json", destination: "~/conf.json"
|
43
|
+
|
44
|
+
if File.exists? pi_build_modifier.gem
|
45
|
+
config.vm.provision "file", source: "pi_build_modifier.gem", destination: "~/pi_build_modifier.gem"
|
46
|
+
else
|
47
|
+
raise 'Config file cannot be found!'
|
48
|
+
end
|
49
|
+
|
50
|
+
# Actually modify and build
|
51
|
+
config.vm.provision 'shell', inline: $prepare
|
52
|
+
|
53
|
+
# Actually modify the build sources and build the environment
|
54
|
+
config.vm.provision 'shell', inline: $modify
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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_builder_factory'
|
22
|
+
|
23
|
+
module PiCustomizer
|
24
|
+
module Builder
|
25
|
+
class PiBuilder
|
26
|
+
|
27
|
+
def initialize(environment)
|
28
|
+
@env = environment
|
29
|
+
end
|
30
|
+
|
31
|
+
def build
|
32
|
+
check_builder
|
33
|
+
begin
|
34
|
+
start
|
35
|
+
execute
|
36
|
+
rescue Exception => e
|
37
|
+
$logger.error e.message
|
38
|
+
ensure
|
39
|
+
stop
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
protected def check_builder
|
44
|
+
if @env.nil?
|
45
|
+
raise 'No environment specified, please specify the "environment", e.g. Vagrant'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
protected def start
|
50
|
+
end
|
51
|
+
|
52
|
+
protected def execute
|
53
|
+
end
|
54
|
+
|
55
|
+
protected def stop
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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/builder/builder'
|
22
|
+
|
23
|
+
module PiCustomizer
|
24
|
+
module Builder
|
25
|
+
class PrepareExecuteBuilder < PiBuilder
|
26
|
+
|
27
|
+
protected def start
|
28
|
+
@env.check
|
29
|
+
@env.prepare
|
30
|
+
end
|
31
|
+
|
32
|
+
protected def execute
|
33
|
+
@env.start
|
34
|
+
@env.build_image
|
35
|
+
end
|
36
|
+
|
37
|
+
protected def stop
|
38
|
+
@env.clean_up
|
39
|
+
@env.stop
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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/builder/builder'
|
22
|
+
|
23
|
+
module PiCustomizer
|
24
|
+
module Builder
|
25
|
+
class StartStopBuilder < PiBuilder
|
26
|
+
|
27
|
+
protected def start
|
28
|
+
@env.check
|
29
|
+
@env.start
|
30
|
+
@env.prepare
|
31
|
+
end
|
32
|
+
|
33
|
+
protected def execute
|
34
|
+
@env.build_image
|
35
|
+
end
|
36
|
+
|
37
|
+
protected def stop
|
38
|
+
@env.clean_up
|
39
|
+
@env.stop
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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
|
+
require 'pi_customizer/environment/environment'
|
24
|
+
|
25
|
+
module PiCustomizer
|
26
|
+
module Environment
|
27
|
+
class AWS < EnvironmentControl
|
28
|
+
|
29
|
+
def build
|
30
|
+
create_ssh_folder
|
31
|
+
create_keys
|
32
|
+
begin
|
33
|
+
terraform
|
34
|
+
ensure
|
35
|
+
del_keys
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def terraform
|
40
|
+
puts 'Build env with terraform'
|
41
|
+
Dir.chdir 'envs/aws' do
|
42
|
+
system 'terraform plan'
|
43
|
+
system 'terraform apply'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_keys(key_name = 'pi-builder')
|
48
|
+
$logger.info 'Create AWS key unless it exists'
|
49
|
+
FileUtils.mkdir_p 'ssh'
|
50
|
+
unless File.file?("ssh/#{key_name}.pub")
|
51
|
+
system "ssh-keygen -t rsa -C pi-builder -P '' -f ssh/#{key_name} -b 4096"
|
52
|
+
FileUtils.mv "ssh/#{key_name}", "ssh/#{key_name}.pem"
|
53
|
+
FileUtils.chmod 400, "ssh/#{key_name}.pem"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def del_keys(key_name = 'pi-builder')
|
58
|
+
if File.file?("ssh/#{key_name}.pub")
|
59
|
+
FileUtils.rm "ssh/#{key_name}.pub"
|
60
|
+
end
|
61
|
+
if File.file?("ssh/#{key_name}.pem")
|
62
|
+
FileUtils.rm "ssh/#{key_name}.pem"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_ssh_folder
|
67
|
+
unless File.directory?('ssh')
|
68
|
+
FileUtils.mkdir_p 'ssh'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|