danarchy_deploy 0.2.3 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +48 -0
- data/Gemfile.lock +10 -10
- data/bin/{danarchy_deploy-console → console-dd} +0 -0
- data/bin/danarchy_deploy +6 -4
- data/danarchy_deploy.gemspec +3 -3
- data/lib/danarchy_deploy/groups.rb +1 -0
- data/lib/danarchy_deploy/services/init.rb +5 -4
- data/lib/danarchy_deploy/services/mongodb.rb +11 -11
- data/lib/danarchy_deploy/services/mysql/new_server.rb +4 -4
- data/lib/danarchy_deploy/services/mysql.rb +3 -3
- data/lib/danarchy_deploy/services.rb +1 -0
- data/lib/danarchy_deploy/system/cryptsetup.rb +144 -0
- data/lib/danarchy_deploy/system/fstab.rb +60 -0
- data/lib/danarchy_deploy/system.rb +30 -19
- data/lib/danarchy_deploy/users.rb +1 -1
- data/lib/danarchy_deploy/version.rb +1 -1
- data/lib/danarchy_deploy.rb +9 -9
- metadata +19 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4665ec27120f6fda4337da5a2b2cb465511534cef96b47c2a11791076012f64
|
4
|
+
data.tar.gz: e12104840e0273bf38d37a0465752ebc5bacc53d2d0f4a5b5783a936f5810afb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bc766ba4a3e8f6e0e691dd1904029f9c08cd6b040146214ae31fb0c18b3a779bae3258b033b1b50205f70c02ebfdbc1fcdd5756ae5ef7b727ce8225397cb4b4
|
7
|
+
data.tar.gz: 7b22f9218392944730cec707bbf62cf9cc9c696fd411eccf02e6d7ceff54748b141c76b2b3de6750867287e9221a17f0be08be524a29c58e14b38b6741da4036
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
danarchy_deploy
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.7.2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
patch_0.2.6
|
2
|
+
- DanarchyDeploy: gem install --bindir
|
3
|
+
- DanarchyDeploy: return from each class if not defined in a deployment
|
4
|
+
- Services::MySQL: Check for defaults_file instead of /etc/my.cnf, SecureRandom.hex for passwords
|
5
|
+
- Services::Init: clean up output and if statement
|
6
|
+
- Add RVM .ruby-version .ruby-gemset
|
7
|
+
- Rename danarchy_deploy-console to console-dd
|
8
|
+
- Add CHANGELOG.md
|
9
|
+
|
10
|
+
patch_0.2.5
|
11
|
+
- Adds Fstab system service
|
12
|
+
- Adds Dmcrypt/LVM system service
|
13
|
+
- Enforce MongoDB security/limits.d/mongodb.conf if it doesn't exist
|
14
|
+
- Clarify some CLI output
|
15
|
+
- Ignore first SSH known_hosts error in RemoteDeploy.remote_mkdir
|
16
|
+
|
17
|
+
patch_0.2.4
|
18
|
+
- mongodb limits newlines
|
19
|
+
|
20
|
+
patch_0.2.2
|
21
|
+
- Fix MongoDB so it correctly applies security limits file count
|
22
|
+
|
23
|
+
release_0.2.0
|
24
|
+
- Adds Applicator #wordpress #nginx #phpfpm #ssl
|
25
|
+
- Adds Services #init #mongodb #mysql
|
26
|
+
- Adds System #centos #debian #gentoo #openssue
|
27
|
+
|
28
|
+
patch_0.1.6
|
29
|
+
- User/Groups commands should use sudo
|
30
|
+
|
31
|
+
patch_0.1.5
|
32
|
+
- Don't upload to couchdb if using a .json/.yaml template
|
33
|
+
|
34
|
+
patch_0.1.4
|
35
|
+
- sudoers.d/ file root owned
|
36
|
+
|
37
|
+
patch_0.1.3
|
38
|
+
- prevents packages from being an empty array
|
39
|
+
|
40
|
+
patch_0.1.2
|
41
|
+
- chown/chmod on ~/.ssh contents
|
42
|
+
- fix JSON parse error
|
43
|
+
|
44
|
+
release_0.1.1
|
45
|
+
- Re-order archive extraction and template creation so that written templates aren't overwritten by archive data.
|
46
|
+
- Fixes user sudoers.d file creation; a+ append instead of r+ read-write (expects file to exist already).
|
47
|
+
- Cleans up package handling for Gentoo and also changes --usepkg to --buildpkg if hostname begins with 'image' or 'template' for binary creation during image builds.
|
48
|
+
|
data/Gemfile.lock
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danarchy_deploy (0.2.
|
5
|
-
danarchy_couchdb (~> 0.1
|
6
|
-
mongo (~> 2.
|
4
|
+
danarchy_deploy (0.2.6)
|
5
|
+
danarchy_couchdb (~> 0.1)
|
6
|
+
mongo (~> 2.17)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
bson (4.
|
12
|
-
danarchy_couchdb (0.1.
|
13
|
-
mongo (2.
|
11
|
+
bson (4.14.1)
|
12
|
+
danarchy_couchdb (0.1.3)
|
13
|
+
mongo (2.17.0)
|
14
14
|
bson (>= 4.8.2, < 5.0.0)
|
15
|
-
rake (13.0.
|
15
|
+
rake (13.0.6)
|
16
16
|
|
17
17
|
PLATFORMS
|
18
|
-
|
18
|
+
x86_64-linux
|
19
19
|
|
20
20
|
DEPENDENCIES
|
21
|
-
bundler (~> 2.
|
21
|
+
bundler (~> 2.3)
|
22
22
|
danarchy_deploy!
|
23
23
|
rake (~> 13.0)
|
24
24
|
|
25
25
|
BUNDLED WITH
|
26
|
-
2.
|
26
|
+
2.3.9
|
File without changes
|
data/bin/danarchy_deploy
CHANGED
@@ -5,7 +5,7 @@ require 'date'
|
|
5
5
|
require 'optparse'
|
6
6
|
|
7
7
|
deployment = nil
|
8
|
-
options = { couchdb: "#{ENV['HOME']}/.danarchy/danarchy_deploy/
|
8
|
+
options = { couchdb: "#{ENV['HOME']}/.danarchy/danarchy_deploy/danarchy_couchdb.json",
|
9
9
|
deploy_dir: '/danarchy/deploy',
|
10
10
|
deploy_file: nil,
|
11
11
|
first_run: false,
|
@@ -15,7 +15,8 @@ options = { couchdb: "#{ENV['HOME']}/.danarchy/danarchy_deploy/danarchy_deploy.j
|
|
15
15
|
|
16
16
|
ARGV.push('--help') if ARGV.empty?
|
17
17
|
optparse = OptionParser.new do |opts|
|
18
|
-
opts.banner
|
18
|
+
opts.banner = "Usage: danarchy_deploy (local|remote) --json #{options[:deploy_dir]}/<HOSTNAME>/<HOSTNAME>.json [options]"
|
19
|
+
opts.banner += "\n Local deployments require danarchy_deploy to be run as sudo/root.\n\n"
|
19
20
|
|
20
21
|
opts.on('-j=file', '--json=file', 'Read configuration from JSON file.') do |file|
|
21
22
|
require 'json'
|
@@ -65,7 +66,7 @@ optparse = OptionParser.new do |opts|
|
|
65
66
|
end.parse!
|
66
67
|
|
67
68
|
puts "DanarchyDeploy: #{DanarchyDeploy::VERSION}"
|
68
|
-
location = ARGV.delete('remote') || ARGV.delete('local') || abort("ERROR: Need
|
69
|
+
location = ARGV.delete('remote') || ARGV.delete('local') || abort("ERROR: Need a deployment type: 'local' or 'remote'!")
|
69
70
|
cdb_config = File.exist?(options[:couchdb]) ? JSON.parse(File.read(options[:couchdb]), symbolize_names: true)[:couchdb] : nil
|
70
71
|
cdb = DanarchyCouchDB::Connection.new(cdb_config) if cdb_config
|
71
72
|
|
@@ -94,7 +95,7 @@ end
|
|
94
95
|
if location == 'remote'
|
95
96
|
deployment = DanarchyDeploy::RemoteDeploy.new(deployment, options)
|
96
97
|
elsif location == 'local'
|
97
|
-
abort('Exiting!
|
98
|
+
abort('Exiting! Local deployment must be run with sudo!') if Process.uid != 0
|
98
99
|
puts "Deploying #{deployment[:hostname]} locally to #{`hostname`.chomp}."
|
99
100
|
|
100
101
|
if !options[:pretend]
|
@@ -113,6 +114,7 @@ end
|
|
113
114
|
|
114
115
|
if deployment && cdb && !options[:pretend] && options[:deploy_file] !~ /.*(json|yaml)$/
|
115
116
|
puts "Saving deployment to CouchDB."
|
117
|
+
deployment[:_attachments].values.map { |v| v.delete(:data) } if deployment[:_attachments]
|
116
118
|
old_rev = cdb.get(cdb_config[:database], deployment_name)[:_rev]
|
117
119
|
save = cdb.put(cdb_config[:database], deployment[:_id], deployment)
|
118
120
|
|
data/danarchy_deploy.gemspec
CHANGED
@@ -28,10 +28,10 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
|
-
spec.add_dependency "danarchy_couchdb", "~> 0.1
|
31
|
+
spec.add_dependency "danarchy_couchdb", "~> 0.1"
|
32
32
|
|
33
|
-
spec.add_development_dependency "bundler", "~> 2.
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.3"
|
34
34
|
spec.add_development_dependency "rake", "~> 13.0"
|
35
35
|
|
36
|
-
spec.add_runtime_dependency "mongo", "~> 2.
|
36
|
+
spec.add_runtime_dependency "mongo", "~> 2.17"
|
37
37
|
end
|
@@ -5,6 +5,7 @@ module DanarchyDeploy
|
|
5
5
|
module Services
|
6
6
|
class Init
|
7
7
|
def self.new(deployment, options)
|
8
|
+
return deployment if ! deployment[:services]
|
8
9
|
puts "\n" + self.name
|
9
10
|
|
10
11
|
deployment[:services].each do |service, params|
|
@@ -35,16 +36,16 @@ module DanarchyDeploy
|
|
35
36
|
|
36
37
|
init_result = init.send(action)
|
37
38
|
|
38
|
-
if init_result[:stderr]
|
39
|
-
if
|
39
|
+
if stderr = init_result[:stderr]
|
40
|
+
if stderr.include?('unknown function')
|
40
41
|
puts " ! Action: #{action} not available for service: #{service}.\n" +
|
41
42
|
" ! A restart may be needed! Otherwise, remove this action from the deployment.\n" +
|
42
43
|
" ! Not taking any action here.\n"
|
43
44
|
else
|
44
|
-
abort(" ! Action: #{
|
45
|
+
abort(" ! Action: #{action} #{service} failed!")
|
45
46
|
end
|
46
47
|
else
|
47
|
-
puts " |+ Action: #{
|
48
|
+
puts " |+ Action: #{action} #{service} succeeded."
|
48
49
|
end
|
49
50
|
end
|
50
51
|
end
|
@@ -13,7 +13,7 @@ module DanarchyDeploy
|
|
13
13
|
Mongo::Logger.logger.level = Logger::FATAL
|
14
14
|
mongodb_conf, updated_conf = self.load_mongodb_conf
|
15
15
|
host_port = mongodb_conf['net']['bindIp'].split(',').first + ':' + mongodb_conf['net']['port'].to_s
|
16
|
-
admin_user, new_admin
|
16
|
+
admin_user, new_admin = self.load_admin_user
|
17
17
|
|
18
18
|
if new_admin == true
|
19
19
|
client = Mongo::Client.new(['127.0.0.1'], database: 'admin')
|
@@ -48,9 +48,7 @@ module DanarchyDeploy
|
|
48
48
|
private
|
49
49
|
def self.load_mongodb_conf
|
50
50
|
updated_conf = false
|
51
|
-
@mongodb[:mongodb_conf]
|
52
|
-
@mongodb[:mongodb_conf] :
|
53
|
-
'/etc/mongodb.conf'
|
51
|
+
@mongodb[:mongodb_conf] ||= '/etc/mongodb.conf'
|
54
52
|
mongodb_conf = File.exist?(@mongodb[:mongodb_conf]) ? YAML.load_file(@mongodb[:mongodb_conf]) : Hash.new
|
55
53
|
|
56
54
|
generated_mongodb_conf = self.generate_mongodb_conf
|
@@ -59,13 +57,15 @@ module DanarchyDeploy
|
|
59
57
|
end
|
60
58
|
|
61
59
|
def self.generate_mongodb_conf
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
security_limits = '/etc/security/limits.d/mongodb.conf'
|
61
|
+
limits = <<~EOF
|
62
|
+
mongodb soft nofile 64000
|
63
|
+
mongodb hard nofile 64000
|
64
|
+
mongodb soft nproc 64000
|
65
|
+
mongodb hard nproc 64000
|
66
|
+
EOF
|
67
|
+
|
68
|
+
File.write(security_limits, limits) if !File.exist?(security_limits)
|
69
69
|
|
70
70
|
mongodb_conf = {
|
71
71
|
'net' => { 'port' => 27017, 'bindIp' => '127.0.0.1' },
|
@@ -49,13 +49,13 @@ module DanarchyDeploy
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def self.generate_root_mycnf(mysql, options)
|
52
|
-
return if File.exist?(mysql[:
|
53
|
-
puts " |+ Generating #{mysql[:
|
54
|
-
password = SecureRandom.
|
52
|
+
return if File.exist?(mysql[:defaults_file])
|
53
|
+
puts " |+ Generating #{mysql[:defaults_file]} file."
|
54
|
+
password = SecureRandom.hex(24)
|
55
55
|
source = options[:deploy_dir] +
|
56
56
|
'/templates/services/mysql/root_my.cnf.erb'
|
57
57
|
|
58
|
-
templates = [{ target: mysql[:
|
58
|
+
templates = [{ target: mysql[:defaults_file],
|
59
59
|
source: source,
|
60
60
|
variables: {
|
61
61
|
host: 'localhost',
|
@@ -11,7 +11,7 @@ module DanarchyDeploy
|
|
11
11
|
mysql = self.set_parameters(mysql)
|
12
12
|
self.generate_my_cnf(mysql, options)
|
13
13
|
|
14
|
-
if File.exist?(mysql[:
|
14
|
+
if File.exist?(mysql[:defaults_file]) && Dir.exist?(mysql[:datadir])
|
15
15
|
puts " |+ Using existing MySQL service."
|
16
16
|
else
|
17
17
|
MySQL::NewServer.new(os, mysql, options)
|
@@ -24,8 +24,8 @@ module DanarchyDeploy
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.set_parameters(mysql)
|
27
|
-
mysql[:
|
28
|
-
mysql[:
|
27
|
+
mysql[:defaults_file] = mysql[:defaults_file] ?
|
28
|
+
mysql[:defaults_file] :
|
29
29
|
'/root/.my.cnf'
|
30
30
|
mysql[:my_cnf] = mysql[:my_cnf] ?
|
31
31
|
mysql[:my_cnf] :
|
@@ -0,0 +1,144 @@
|
|
1
|
+
|
2
|
+
module DanarchyDeploy
|
3
|
+
module System
|
4
|
+
class Cryptsetup
|
5
|
+
def self.new(os, cryptsetup, options)
|
6
|
+
return false if cryptsetup.nil?
|
7
|
+
puts "\n" + self.name
|
8
|
+
|
9
|
+
# expects object: {
|
10
|
+
# "cryptsetup": {
|
11
|
+
# "source": "/danarchy/deploy/templates/system/cryptsetup.erb", (optional)
|
12
|
+
# "volumes": {
|
13
|
+
# "vg_name:vg0:/dev/vdb": {
|
14
|
+
# "target": "dm-vg0-mongodb",
|
15
|
+
# "source": "/dev/mapper/vg0-mongodb",
|
16
|
+
# "key": "/root/vdb_mongodb.key" } } } }
|
17
|
+
|
18
|
+
if os == 'gentoo'
|
19
|
+
DanarchyDeploy::Services::Init.init_manager(os, 'lvmetad', 'enable', options)
|
20
|
+
DanarchyDeploy::Services::Init.init_manager(os, 'lvmetad', 'start', options)
|
21
|
+
end
|
22
|
+
|
23
|
+
service, target, source = set_config(cryptsetup, options)
|
24
|
+
lvm_result, crypt_result = nil
|
25
|
+
cryptsetup[:volumes].each do |device, volume|
|
26
|
+
lvm_result = lvm_setup(device, volume, options)
|
27
|
+
crypt_result = encrypt_volume(volume, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
deploy_template(target, source, cryptsetup[:volumes], options)
|
31
|
+
if os == 'gentoo'
|
32
|
+
DanarchyDeploy::Services::Init.init_manager(os, service, 'enable', options)
|
33
|
+
DanarchyDeploy::Services::Init.init_manager(os, service, 'start', options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def self.set_config(cryptsetup, options)
|
39
|
+
service, target = File.exist?('/etc/conf.d/dmcrypt') ?
|
40
|
+
['dmcrypt','/etc/conf.d/dmcrypt'] :
|
41
|
+
['cryptsetup','/etc/crypttab']
|
42
|
+
|
43
|
+
source = if cryptsetup[:source]
|
44
|
+
cryptsetup[:source]
|
45
|
+
elsif target == '/etc/conf.d/dmcrypt'
|
46
|
+
options[:deploy_dir] + '/templates/system/dmcrypt.erb'
|
47
|
+
elsif target == '/etc/crypttab'
|
48
|
+
options[:deploy_dir] + '/templates/system/crypttab.erb'
|
49
|
+
else
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
[service, target, source]
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.lvm_setup(device, volume, options)
|
57
|
+
puts "\n > Configuring LVM"
|
58
|
+
name, vg, pv = device.to_s.split(/:/)
|
59
|
+
|
60
|
+
# Create physical volume
|
61
|
+
pvdisplay = DanarchyDeploy::Helpers.run_command("pvdisplay #{pv}", options)
|
62
|
+
if pvdisplay[:stderr]
|
63
|
+
puts "Creating physical volume: #{pv}"
|
64
|
+
pvcreate = DanarchyDeploy::Helpers.run_command("pvcreate -f #{pv}", options)
|
65
|
+
abort(" ! Failed to run pvcreate: #{pvcreate[:stderr]}") if pvcreate[:stderr]
|
66
|
+
puts pvcreate[:stdout]
|
67
|
+
pvdisplay = DanarchyDeploy::Helpers.run_command("pvdisplay #{pv}", options)
|
68
|
+
end
|
69
|
+
puts pvdisplay[:stderr] || pvdisplay[:stdout]
|
70
|
+
|
71
|
+
# Create volume group
|
72
|
+
vgdisplay = DanarchyDeploy::Helpers.run_command("vgdisplay #{vg}", options)
|
73
|
+
if vgdisplay[:stderr]
|
74
|
+
puts "Creating volume group: #{vg} with #{pv}"
|
75
|
+
vgcreate = DanarchyDeploy::Helpers.run_command("vgcreate #{vg} #{pv}", options)
|
76
|
+
abort(" ! Failed to run vgcreate: #{vgcreate[:stderr]}") if vgcreate[:stderr]
|
77
|
+
puts vgcreate[:stdout]
|
78
|
+
vgdisplay = DanarchyDeploy::Helpers.run_command("vgdisplay #{vg}", options)
|
79
|
+
end
|
80
|
+
puts vgdisplay[:stderr] || vgdisplay[:stdout]
|
81
|
+
|
82
|
+
# Create logical volume
|
83
|
+
lvdisplay = DanarchyDeploy::Helpers.run_command("lvdisplay #{vg}/#{name}", options)
|
84
|
+
if lvdisplay[:stderr]
|
85
|
+
puts "Creating volume group: #{vg}/#{name} with #{pv}"
|
86
|
+
lvcreate = DanarchyDeploy::Helpers.run_command("lvcreate -y -l 100%FREE -n #{name} #{vg}", options)
|
87
|
+
abort(" ! Failed to run lvcreate: #{lvcreate[:stderr]}") if lvcreate[:stderr]
|
88
|
+
puts lvcreate[:stdout]
|
89
|
+
lvdisplay = DanarchyDeploy::Helpers.run_command("lvdisplay #{vg}/#{name}", options)
|
90
|
+
end
|
91
|
+
puts lvdisplay[:stderr] || lvdisplay[:stdout]
|
92
|
+
|
93
|
+
[pvdisplay, vgdisplay, lvdisplay]
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.encrypt_volume(volume, options)
|
97
|
+
puts "\n > Configuring Cryptsetup"
|
98
|
+
deploy_key(volume, options)
|
99
|
+
target = volume[:variables][:target]
|
100
|
+
source = volume[:variables][:source]
|
101
|
+
key = volume[:variables][:key]
|
102
|
+
abort(" ! Failed to find key: #{key}") if !File.exist?(key) && !options[:pretend]
|
103
|
+
|
104
|
+
# Encrypt logical volume with key
|
105
|
+
luksdump = DanarchyDeploy::Helpers.run_command("cryptsetup luksDump #{source}", options)
|
106
|
+
if luksdump[:stderr]
|
107
|
+
puts "\n > Encrypting volume: #{source}"
|
108
|
+
luksformat = DanarchyDeploy::Helpers.run_command("cryptsetup luksFormat #{source} #{key}", options)
|
109
|
+
abort(" ! Failed to run luksFormat: #{luksformat[:stderr]}") if luksformat[:stderr]
|
110
|
+
puts luksformat[:stdout]
|
111
|
+
luksdump = DanarchyDeploy::Helpers.run_command("cryptsetup luksDump #{source}", options)
|
112
|
+
end
|
113
|
+
puts luksdump[:stderr] || luksdump[:stdout]
|
114
|
+
|
115
|
+
# Open luks target
|
116
|
+
luksopen = { stderr: nil }
|
117
|
+
if !File.exist?("/dev/mapper/#{target}")
|
118
|
+
puts "\n > Opening volume: #{source}"
|
119
|
+
luksopen = DanarchyDeploy::Helpers.run_command("cryptsetup luksOpen -d #{key} #{source} #{target}", options)
|
120
|
+
abort(" ! Failed to run luksOpen: #{luksopen[:stderr]}") if luksopen[:stderr]
|
121
|
+
puts luksopen[:stdout]
|
122
|
+
end
|
123
|
+
|
124
|
+
[luksdump, luksopen]
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.deploy_key(volume, options)
|
128
|
+
templates = [{ source: volume[:key_file],
|
129
|
+
target: volume[:variables][:key],
|
130
|
+
file_perms: {
|
131
|
+
owner: 'root',
|
132
|
+
group: 'root',
|
133
|
+
mode: '0400' } }]
|
134
|
+
|
135
|
+
DanarchyDeploy::Templater.new(templates, options)
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.deploy_template(target, source, volumes, options)
|
139
|
+
templates = [{ target: target, source: source, variables: volumes }]
|
140
|
+
DanarchyDeploy::Templater.new(templates, options)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
module DanarchyDeploy
|
3
|
+
module System
|
4
|
+
class Fstab
|
5
|
+
def self.new(os, fstab, options)
|
6
|
+
puts "\n" + self.name
|
7
|
+
target, source = set_config(fstab, options)
|
8
|
+
deploy_template(target, source, fstab[:mounts], options)
|
9
|
+
format_mountpoints(fstab, options)
|
10
|
+
mount_all(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.mount_all(options)
|
14
|
+
puts "\n > Mounting Filesystems"
|
15
|
+
mount_result = DanarchyDeploy::Helpers.run_command('mount -a', options)
|
16
|
+
abort(' ! Failed to mount filesystems!') if mount_result[:stderr]
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def self.set_config(fstab, options)
|
21
|
+
target = '/etc/fstab'
|
22
|
+
source = fstab[:source] ?
|
23
|
+
fstab[:source] :
|
24
|
+
'/danarchy/deploy/templates/system/fstab.erb'
|
25
|
+
|
26
|
+
[target, source]
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.deploy_template(target, source, mounts, options)
|
30
|
+
templates = [{ target: target,
|
31
|
+
source: source,
|
32
|
+
variables: mounts }]
|
33
|
+
|
34
|
+
DanarchyDeploy::Templater.new(templates, options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.format_mountpoints(fstab, options)
|
38
|
+
return false if fstab.nil?
|
39
|
+
puts "\n > Formatting mountpoints"
|
40
|
+
|
41
|
+
fstab[:mounts].each do |mount|
|
42
|
+
fs_check = DanarchyDeploy::Helpers.run_command(
|
43
|
+
"file -sL #{mount[:filesystem]}", options
|
44
|
+
)
|
45
|
+
|
46
|
+
if fs_check[:stdout] && fs_check[:stdout] =~ /.*data$/
|
47
|
+
puts "\n > Formatting #{mount[:filesystem]}"
|
48
|
+
mkfs = DanarchyDeploy::Helpers.run_command(
|
49
|
+
"mkfs -t #{mount[:type]} #{mount[:filesystem]}", options
|
50
|
+
)
|
51
|
+
abort(" ! Failed to run mkfs: #{mkfs[:stderr]}") if mkfs[:stderr]
|
52
|
+
end
|
53
|
+
|
54
|
+
FileUtils.mkdir_p(mount[:mountpoint]) if !options[:pretend] &&
|
55
|
+
!Dir.exist?(mount[:mountpoint])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -3,10 +3,14 @@ require_relative 'system/debian'
|
|
3
3
|
require_relative 'system/gentoo'
|
4
4
|
require_relative 'system/opensuse'
|
5
5
|
|
6
|
+
require_relative 'system/cryptsetup'
|
7
|
+
require_relative 'system/fstab'
|
8
|
+
|
6
9
|
module DanarchyDeploy
|
7
10
|
module System
|
8
11
|
def self.new(deployment, options)
|
9
12
|
abort('Operating System not defined! Exiting!') if !deployment[:os]
|
13
|
+
return deployment if ! deployment[:system]
|
10
14
|
puts "\n" + self.name
|
11
15
|
|
12
16
|
installer, updater, cleaner = prep_operating_system(deployment, options)
|
@@ -46,28 +50,17 @@ module DanarchyDeploy
|
|
46
50
|
if deployment[:system][:templates]
|
47
51
|
puts "\n > Configuring system templates for #{deployment[:os]}"
|
48
52
|
DanarchyDeploy::Templater.new(deployment[:system][:templates], options)
|
53
|
+
end
|
49
54
|
|
50
|
-
|
51
|
-
deployment[:system][:templates].each do |t|
|
52
|
-
if t[:target] == '/etc/fstab'
|
53
|
-
t[:variables].each do |v|
|
54
|
-
if !Dir.exist?(v[:mountpoint])
|
55
|
-
puts "Creating mountpoint: #{v[:mountpoint]}"
|
56
|
-
FileUtils.mkdir_p(v[:mountpoint]) if !options[:pretend]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
55
|
+
DanarchyDeploy::System::Cryptsetup.new(deployment[:os], deployment[:system][:cryptsetup], options)
|
61
56
|
|
57
|
+
if deployment[:system][:fstab]
|
58
|
+
DanarchyDeploy::System::Fstab.new(deployment[:os], deployment[:system][:fstab], options)
|
59
|
+
else
|
60
|
+
DanarchyDeploy::System::Fstab.mount_all(options)
|
62
61
|
end
|
63
62
|
end
|
64
63
|
|
65
|
-
puts "\n > Mounting Filesystems"
|
66
|
-
if !options[:pretend]
|
67
|
-
mount_result = DanarchyDeploy::Helpers.run_command('mount -a', options)
|
68
|
-
abort(' |! Failed to mount filesystems!') if mount_result[:stderr]
|
69
|
-
end
|
70
|
-
|
71
64
|
if os.downcase == 'gentoo'
|
72
65
|
(installer, updater, cleaner) = DanarchyDeploy::System::Gentoo.new(deployment, options)
|
73
66
|
elsif %w[debian ubuntu].include?(os.downcase)
|
@@ -75,12 +68,30 @@ module DanarchyDeploy
|
|
75
68
|
elsif os.downcase == 'opensuse'
|
76
69
|
puts 'OpenSUSE is not fully supported yet!'
|
77
70
|
(installer, updater, cleaner) = DanarchyDeploy::System::OpenSUSE.new(deployment, options)
|
78
|
-
elsif %w[centos redhat].include?(os.downcase)
|
79
|
-
puts 'CentOS/RedHat is not fully supported yet!'
|
71
|
+
elsif %w[fedora centos redhat].include?(os.downcase)
|
72
|
+
puts 'Fedora/CentOS/RedHat is not fully supported yet!'
|
80
73
|
(installer, updater, cleaner) = DanarchyDeploy::System::CentOS.new(deployment, options)
|
81
74
|
end
|
82
75
|
|
83
76
|
[installer, updater, cleaner]
|
84
77
|
end
|
78
|
+
|
79
|
+
def self.fstab_mount(deployment, options)
|
80
|
+
fstab = deployment[:system][:templates].collect { |t| t if t[:target] == '/etc/fstab' }.compact
|
81
|
+
fstab.each do |t|
|
82
|
+
t[:variables].each do |v|
|
83
|
+
if !Dir.exist?(v[:mountpoint])
|
84
|
+
puts "Creating mountpoint: #{v[:mountpoint]}"
|
85
|
+
FileUtils.mkdir_p(v[:mountpoint]) if !options[:pretend]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
puts "\n > Mounting Filesystems"
|
91
|
+
if !options[:pretend]
|
92
|
+
mount_result = DanarchyDeploy::Helpers.run_command('mount -a', options)
|
93
|
+
abort(' |! Failed to mount filesystems!') if mount_result[:stderr]
|
94
|
+
end
|
95
|
+
end
|
85
96
|
end
|
86
97
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
module DanarchyDeploy
|
3
3
|
class Users
|
4
4
|
def self.new(deployment, options)
|
5
|
+
return deployment if ! deployment[:users]
|
5
6
|
puts "\n" + self.name
|
6
7
|
(useradd_result, userdel_result, archives_result) = nil
|
7
8
|
|
@@ -56,7 +57,6 @@ module DanarchyDeploy
|
|
56
57
|
user.delete(:username)
|
57
58
|
end
|
58
59
|
|
59
|
-
# [useradd_result, userdel_result]
|
60
60
|
deployment
|
61
61
|
end
|
62
62
|
|
data/lib/danarchy_deploy.rb
CHANGED
@@ -21,10 +21,10 @@ module DanarchyDeploy
|
|
21
21
|
printf("%12s %0s\n", 'Packages:', deployment[:packages].join(', ')) if deployment[:packages]
|
22
22
|
|
23
23
|
deployment = DanarchyDeploy::System.new(deployment, options)
|
24
|
-
deployment = DanarchyDeploy::Services.new(deployment, options)
|
25
|
-
deployment = DanarchyDeploy::Groups.new(deployment, options)
|
26
|
-
deployment = DanarchyDeploy::Users.new(deployment, options)
|
27
|
-
deployment = DanarchyDeploy::Services::Init.new(deployment, options)
|
24
|
+
deployment = DanarchyDeploy::Services.new(deployment, options)
|
25
|
+
deployment = DanarchyDeploy::Groups.new(deployment, options)
|
26
|
+
deployment = DanarchyDeploy::Users.new(deployment, options)
|
27
|
+
deployment = DanarchyDeploy::Services::Init.new(deployment, options)
|
28
28
|
|
29
29
|
deployment[:last_deploy] = DateTime.now.strftime("%Y/%m/%d %H:%M:%S")
|
30
30
|
puts "\nFinished Local Deployment at #{deployment[:last_deploy]}!"
|
@@ -61,7 +61,7 @@ module DanarchyDeploy
|
|
61
61
|
|
62
62
|
gem_clean(connector, options)
|
63
63
|
gem_binary = _locate_gem_binary(connector, options) # this should run before any install; check version too
|
64
|
-
|
64
|
+
push_templates(connector, options)
|
65
65
|
push_deployment(connector, options)
|
66
66
|
deploy_result = remote_LocalDeploy(connector, gem_binary, options)
|
67
67
|
|
@@ -79,10 +79,10 @@ module DanarchyDeploy
|
|
79
79
|
private
|
80
80
|
def self.remote_mkdir(connector, options)
|
81
81
|
puts "\n > Creating directory: #{options[:working_dir]}"
|
82
|
-
mkdir_cmd = _ssh_command(connector, "test -d #{options[:working_dir]} || sudo mkdir -vp #{options[:working_dir]}")
|
82
|
+
mkdir_cmd = _ssh_command(connector, "test -d #{options[:working_dir]} && echo 'Directory exists!' || sudo mkdir -vp #{options[:working_dir]}")
|
83
83
|
mkdir_result = DanarchyDeploy::Helpers.run_command(mkdir_cmd, options)
|
84
84
|
|
85
|
-
if mkdir_result[:stderr]
|
85
|
+
if mkdir_result[:stderr] && ! mkdir_result[:stdout]
|
86
86
|
abort(' ! Directory creation failed!')
|
87
87
|
else
|
88
88
|
puts " |+ Created directory: '#{options[:deploy_dir]}'"
|
@@ -144,7 +144,7 @@ module DanarchyDeploy
|
|
144
144
|
end
|
145
145
|
|
146
146
|
puts "\n > Installing gem: #{gem} on #{connector[:hostname]}"
|
147
|
-
install_cmd = _ssh_command(connector, "sudo gem install -f #{options[:deploy_dir]}/#{File.basename(gem)}")
|
147
|
+
install_cmd = _ssh_command(connector, "sudo gem install --bindir /usr/local/bin -f #{options[:deploy_dir]}/#{File.basename(gem)}")
|
148
148
|
install_result = DanarchyDeploy::Helpers.run_command(install_cmd, options)
|
149
149
|
|
150
150
|
if install_result[:stderr]
|
@@ -159,7 +159,7 @@ module DanarchyDeploy
|
|
159
159
|
system(clean_cmd)
|
160
160
|
end
|
161
161
|
|
162
|
-
def self.
|
162
|
+
def self.push_templates(connector, options)
|
163
163
|
template_dir = options[:deploy_dir] + '/templates'
|
164
164
|
puts "\n > Pushing templates: #{template_dir}"
|
165
165
|
push_cmd = _rsync_push(connector, template_dir, template_dir)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danarchy_deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan James
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danarchy_couchdb
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1
|
19
|
+
version: '0.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1
|
26
|
+
version: '0.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2.
|
33
|
+
version: '2.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '2.
|
40
|
+
version: '2.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,35 +58,38 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2.
|
61
|
+
version: '2.17'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2.
|
68
|
+
version: '2.17'
|
69
69
|
description: DanarchyDeploy intends to simplify Gentoo Linux (and other distro) deployments
|
70
70
|
down to a single template from an input JSON or YAML file, or from a CouchDB file.
|
71
71
|
email:
|
72
72
|
- dan@danarchy.me
|
73
73
|
executables:
|
74
|
+
- console-dd
|
74
75
|
- danarchy_deploy
|
75
|
-
- danarchy_deploy-console
|
76
76
|
- setup
|
77
77
|
extensions: []
|
78
78
|
extra_rdoc_files: []
|
79
79
|
files:
|
80
80
|
- ".gitignore"
|
81
81
|
- ".rspec"
|
82
|
+
- ".ruby-gemset"
|
83
|
+
- ".ruby-version"
|
82
84
|
- ".travis.yml"
|
85
|
+
- CHANGELOG.md
|
83
86
|
- Gemfile
|
84
87
|
- Gemfile.lock
|
85
88
|
- LICENSE.txt
|
86
89
|
- README.md
|
87
90
|
- Rakefile
|
91
|
+
- bin/console-dd
|
88
92
|
- bin/danarchy_deploy
|
89
|
-
- bin/danarchy_deploy-console
|
90
93
|
- bin/setup
|
91
94
|
- danarchy_deploy.gemspec
|
92
95
|
- lib/danarchy_deploy.rb
|
@@ -115,7 +118,9 @@ files:
|
|
115
118
|
- lib/danarchy_deploy/services/mysql/privileges.rb
|
116
119
|
- lib/danarchy_deploy/system.rb
|
117
120
|
- lib/danarchy_deploy/system/centos.rb
|
121
|
+
- lib/danarchy_deploy/system/cryptsetup.rb
|
118
122
|
- lib/danarchy_deploy/system/debian.rb
|
123
|
+
- lib/danarchy_deploy/system/fstab.rb
|
119
124
|
- lib/danarchy_deploy/system/gentoo.rb
|
120
125
|
- lib/danarchy_deploy/system/opensuse.rb
|
121
126
|
- lib/danarchy_deploy/templater.rb
|
@@ -127,7 +132,7 @@ licenses:
|
|
127
132
|
- MIT
|
128
133
|
metadata:
|
129
134
|
allowed_push_host: https://rubygems.org
|
130
|
-
post_install_message:
|
135
|
+
post_install_message:
|
131
136
|
rdoc_options: []
|
132
137
|
require_paths:
|
133
138
|
- lib
|
@@ -142,8 +147,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
147
|
- !ruby/object:Gem::Version
|
143
148
|
version: '0'
|
144
149
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
146
|
-
signing_key:
|
150
|
+
rubygems_version: 3.1.4
|
151
|
+
signing_key:
|
147
152
|
specification_version: 4
|
148
153
|
summary: Pushes deployments locally or remotely based on a JSON/YAML/CouchDB template.
|
149
154
|
test_files: []
|