cli_deployer 0.0.1
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/bin/cli_deployer +5 -0
- data/lib/simple_deployer.rb +123 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9bbdd9978d21c4aa30bc18767c3dd6029754cc89
|
4
|
+
data.tar.gz: 874286628e87384383dea129ff890937bde7fb11
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 31a9adb785795145afc1b4fa2aa412bd7f2808df82102283f9ae6d4e588ad302ac501b1b915243de293cfdafb2cd8e86967555704f5bc9690388a42263dbf28c
|
7
|
+
data.tar.gz: 1b79d10ee9baff1a4eea2851f3ba5bf2b7c838c70ffabf99e9acb3af3887f176d8372e8d312801a63e863dcbe47a80511c3c7bb313e0ac33eb84ec3e028f9c16
|
data/bin/cli_deployer
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'git'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'net/scp'
|
5
|
+
require 'net/ssh'
|
6
|
+
|
7
|
+
class SimpleDeployer
|
8
|
+
|
9
|
+
def self.run()
|
10
|
+
|
11
|
+
trap 'SIGINT' do
|
12
|
+
exit 130
|
13
|
+
end
|
14
|
+
|
15
|
+
if ARGV.length && ARGV[0] == '-h'
|
16
|
+
puts 'Usage: deployer.rb OR deployer.rb <config_file.yml>'
|
17
|
+
end
|
18
|
+
|
19
|
+
config_file = ARGV[0] ? ARGV[0] : 'config.yml'
|
20
|
+
|
21
|
+
unless File.exists?(config_file)
|
22
|
+
puts 'Invalid config file'
|
23
|
+
exit(false)
|
24
|
+
end
|
25
|
+
|
26
|
+
config = YAML.load_file(config_file)
|
27
|
+
deployment_directory = config['deployment-directory']
|
28
|
+
|
29
|
+
applications = []
|
30
|
+
config['applications'].each_key { |app| applications << app }
|
31
|
+
|
32
|
+
app_choice = nil
|
33
|
+
|
34
|
+
while !(1..applications.length).to_a.include?(app_choice.to_i)
|
35
|
+
puts 'Invalid Selection' unless app_choice === nil
|
36
|
+
puts 'Select your desired application:'
|
37
|
+
applications.each_with_index do |application, i|
|
38
|
+
puts "#{i + 1} #{application.to_s}"
|
39
|
+
end
|
40
|
+
|
41
|
+
puts ''
|
42
|
+
$stdout.flush
|
43
|
+
|
44
|
+
app_choice = gets.chomp
|
45
|
+
end
|
46
|
+
|
47
|
+
application_name = applications[app_choice.to_i - 1]
|
48
|
+
configured_app = config['applications'][application_name]
|
49
|
+
application_directory = "#{deployment_directory}/#{application_name}"
|
50
|
+
|
51
|
+
FileUtils.makedirs(deployment_directory) unless File.directory?(deployment_directory)
|
52
|
+
|
53
|
+
if File.directory?(application_directory)
|
54
|
+
puts '-- Fetching latest --'
|
55
|
+
g = Git.open(application_directory)
|
56
|
+
g.reset_hard
|
57
|
+
g.fetch
|
58
|
+
g.checkout('master')
|
59
|
+
else
|
60
|
+
puts '-- Cloning project --'
|
61
|
+
Git.clone(configured_app['git'], application_name, path: deployment_directory)
|
62
|
+
end
|
63
|
+
|
64
|
+
servers = []
|
65
|
+
configured_app['build-commands'].each_key { |server| servers << server }
|
66
|
+
|
67
|
+
server_choice = nil
|
68
|
+
|
69
|
+
while !(1..servers.length).to_a.include?(server_choice.to_i)
|
70
|
+
puts 'Invalid Selection' unless server_choice === nil
|
71
|
+
puts "Where should #{application_name} be deployed:"
|
72
|
+
servers.each_with_index do |server, i|
|
73
|
+
puts "#{i + 1} #{server.to_s}"
|
74
|
+
end
|
75
|
+
|
76
|
+
puts ''
|
77
|
+
$stdout.flush
|
78
|
+
|
79
|
+
server_choice = gets.chomp
|
80
|
+
end
|
81
|
+
|
82
|
+
server = servers[server_choice.to_i - 1]
|
83
|
+
build_commands = configured_app['build-commands'][server]
|
84
|
+
|
85
|
+
if build_commands.length
|
86
|
+
build_commands.insert(0, "cd #{application_directory}")
|
87
|
+
status = system(build_commands.join(' && '))
|
88
|
+
|
89
|
+
unless status
|
90
|
+
puts '-- Error during build steps --'
|
91
|
+
exit(false)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
remote_server = config['servers'][server]
|
96
|
+
|
97
|
+
|
98
|
+
if configured_app['file-to-deploy']
|
99
|
+
puts '-- Uploading file --'
|
100
|
+
Net::SCP.upload!(remote_server['url'],
|
101
|
+
remote_server['user'],
|
102
|
+
"#{application_directory}/#{configured_app['file-to-deploy']}",
|
103
|
+
configured_app['file-deploy-location'],
|
104
|
+
{ssh: {port: remote_server['port']}})
|
105
|
+
puts '-- File uploaded --'
|
106
|
+
end
|
107
|
+
|
108
|
+
if configured_app['ssh-commands']
|
109
|
+
puts '-- Running ssh commands --'
|
110
|
+
Net::SSH.start(remote_server['url'], remote_server['user'], port: remote_server['port']) do |ssh|
|
111
|
+
output = ssh.exec! configured_app['ssh-commands'][server].join(' && ')
|
112
|
+
if output
|
113
|
+
puts output
|
114
|
+
puts '-- Error while executing remote commands --'
|
115
|
+
exit(false)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
puts '-- Build completed --'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cli_deployer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Blair Motchan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fileutils
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: net-scp
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ssh
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.1'
|
69
|
+
description: A gem that parses an easy to create yaml file and provides a command
|
70
|
+
line interface for deploying your applications
|
71
|
+
email: blair.motchan@gmail.com
|
72
|
+
executables:
|
73
|
+
- cli_deployer
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- bin/cli_deployer
|
78
|
+
- lib/simple_deployer.rb
|
79
|
+
homepage: https://github.com/bdogger/simple-deployer
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.8
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Simple Application Deployment Using the CLI
|
103
|
+
test_files: []
|