lib/sunzi/cli.rb in sunzi-1.4.0 vs lib/sunzi/cli.rb in sunzi-1.5.0
- old
+ new
@@ -9,14 +9,14 @@
desc 'create', 'Create sunzi project'
def create(project = 'sunzi')
do_create(project)
end
- desc 'deploy [user@host:port] [role] [--sudo]', 'Deploy sunzi project'
+ desc 'deploy [user@host:port] [role] [--sudo] or deploy [linode|digital_ocean] [name] [role] [--sudo]', 'Deploy sunzi project'
method_options :sudo => false
- def deploy(target, role = nil)
- do_deploy(target, role, options.sudo?)
+ def deploy(first, *args)
+ do_deploy(first, *args)
end
desc 'compile', 'Compile sunzi project'
def compile(role = nil)
do_compile(role)
@@ -52,12 +52,21 @@
copy_file 'templates/create/roles/db.sh', "#{project}/roles/db.sh"
copy_file 'templates/create/roles/web.sh', "#{project}/roles/web.sh"
copy_file 'templates/create/files/.gitkeep', "#{project}/files/.gitkeep"
end
- def do_deploy(target, role, force_sudo)
- sudo = 'sudo ' if force_sudo
+ def do_deploy(first, *args)
+ if ['linode', 'digital_ocean'].include?(first)
+ @instance_attributes = YAML.load(File.read("#{first}/instances/#{args[0]}.yml"))
+ target = @instance_attributes[:fqdn]
+ role = args[1]
+ else
+ target = first
+ role = args[0]
+ end
+
+ sudo = 'sudo ' if options.sudo?
user, host, port = parse_target(target)
endpoint = "#{user}@#{host}"
# compile attributes and recipes
do_compile(role)
@@ -101,9 +110,13 @@
# Check if role exists
abort_with "#{role} doesn't exist!" if role and !File.exists?("roles/#{role}.sh")
# Load sunzi.yml
@config = YAML.load(File.read('sunzi.yml'))
+
+ # Merge instance attributes
+ @config['attributes'] ||= {}
+ @config['attributes'].update(Hash[@instance_attributes.map{|k,v| [k.to_s, v] }]) if @instance_attributes
# Break down attributes into individual files
(@config['attributes'] || {}).each {|key, value| create_file "compiled/attributes/#{key}", value }
# Retrieve remote recipes via HTTP