forked from BrandonArp/Chimera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_environment.rb
executable file
·64 lines (50 loc) · 1.27 KB
/
deploy_environment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env ruby
$: << File.dirname( __FILE__)
require 'lib/deploy'
require 'find'
require 'digest'
require 'fileutils'
require 'optparse'
opts = OptionParser.new
environment_name = ""
manifest = ""
opts.on("-e", "--environment ENVIRONMENT", "environment to build") do |env|
environment_name = env
end
opts.on("-m", "--manifest MANIFEST", "manifest input file") do |mani|
manifest = mani
end
opts.on("-h", "--help", "display this help dialog") do
puts opts
exit 0
end
opts.parse!
error = false
if environment_name == ""
puts "required argument evironment not found"
error = true
end
if manifest == ""
puts "required argument manifest not found"
error = true
end
if error == true
puts opts
exit 1
end
hash = Digest::SHA256.hexdigest(File.read(manifest))
manifest_file = File.new(manifest, "r")
new_env = "/chimera/_env/#{environment_name}/#{hash}/"
FileUtils.rm_rf(new_env)
while (line = manifest_file.gets) do
if (line =~ /(.*)=>(.*)/)
package_name = $1
package_version = $2
build_sym_links(package_name, package_version, new_env)
end
end
#delete the old symlink
env = "/chimera/env/#{environment_name}"
File.delete(env) if File.symlink?(env)
FileUtils.mkpath("/chimera/env/") if not File.exist?("/chimera/env/")
File.symlink(new_env, env)