negroku 0.0.1 → 0.0.2
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.
- data/lib/negroku/cli.rb +119 -31
- data/lib/negroku/config.rb +19 -19
- data/lib/negroku/helpers.rb +1 -1
- data/lib/negroku/tasks/base.rb +1 -1
- data/lib/negroku/tasks/nginx.rb +2 -2
- data/lib/negroku/tasks/rbenv.rb +12 -4
- data/lib/negroku/tasks/templates/nginx.erb +2 -2
- data/lib/negroku/templates/deploy.rb.erb +4 -1
- data/lib/negroku/version.rb +1 -1
- metadata +2 -18
data/lib/negroku/cli.rb
CHANGED
@@ -2,6 +2,8 @@ require 'thor'
|
|
2
2
|
require 'rainbow'
|
3
3
|
require 'highline/import'
|
4
4
|
|
5
|
+
trap('INT') { exit }
|
6
|
+
|
5
7
|
class App < Thor
|
6
8
|
|
7
9
|
say "\n\n#############################################".bright()
|
@@ -12,6 +14,23 @@ class App < Thor
|
|
12
14
|
method_option :local_recipes, :type => :boolean, :aliases => "-l"
|
13
15
|
method_option :path, :type => :string, :aliases => "-p"
|
14
16
|
def create(name=nil)
|
17
|
+
# Get configuration
|
18
|
+
config = getConfig
|
19
|
+
|
20
|
+
# Test for config
|
21
|
+
if config.empty?
|
22
|
+
say "[WARNING]".foreground(:red)
|
23
|
+
say "It's recommended that you add some default settings to negroku before you create your app deployment\n\n"
|
24
|
+
say "For example you can add your most common git urls using:\n"
|
25
|
+
say "negroku repo add git@github.com:yourusername.git\n".foreground(:yellow)
|
26
|
+
say "Also you can add your deployment servers urls using:\n"
|
27
|
+
say "negroku target add my.deployment.com".foreground(:yellow)
|
28
|
+
say "negroku target add 104.284.3.1\n".foreground(:yellow)
|
29
|
+
unless yes? "Do you want to continue without adding default settings? [y/N]"
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
15
34
|
say "We're about to create your application deploy setup\n".foreground(:green)
|
16
35
|
|
17
36
|
# Hash to hold the app info
|
@@ -25,43 +44,86 @@ class App < Thor
|
|
25
44
|
end
|
26
45
|
|
27
46
|
# The application code repository
|
28
|
-
config = YAML.load_file(CONFIG_FILE) || {}
|
29
47
|
choose do |menu|
|
30
48
|
|
31
|
-
say "\nREPOSITORIES"
|
49
|
+
say "\nREPOSITORIES"
|
50
|
+
say "============"
|
32
51
|
menu.prompt = "Please choose your repository?".bright()
|
52
|
+
menu.select_by = :index
|
33
53
|
|
34
|
-
|
35
|
-
|
36
|
-
|
54
|
+
# find local remote from git repo
|
55
|
+
if File.directory?(".git")
|
56
|
+
say "[INFO] The first repo was taken from the local git checkout remotes".color(:yellow)
|
57
|
+
local_repo = %x(git remote -v | grep origin | grep push | awk '{print $2}').gsub(/\n/,"")
|
58
|
+
menu.choice("#{local_repo}") do |command|
|
59
|
+
say("Using #{command}")
|
37
60
|
data[:repo] = command;
|
38
61
|
end
|
39
62
|
end
|
40
63
|
|
64
|
+
# adds the repos in the config file if there is one
|
65
|
+
if config[:repo]
|
66
|
+
config[:repo].each do |val|
|
67
|
+
repo_url = "#{val}/#{data[:application_name]}.git"
|
68
|
+
# skip if the repo url is the same as the local one
|
69
|
+
unless repo_url == local_repo
|
70
|
+
menu.choice(repo_url) do |command|
|
71
|
+
say("Using #{command}/#{data[:application_name]}.git")
|
72
|
+
data[:repo] = command;
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
else
|
77
|
+
say "[INFO] There are no repos in the default settings".color(:yellow)
|
78
|
+
end
|
79
|
+
|
80
|
+
# add other repo choice
|
41
81
|
menu.choice(:other) {
|
42
|
-
data[:repo] = ask "Type the url and username e.g. git@github.com:username".bright()
|
82
|
+
data[:repo] = ask "Type the url and username e.g. git@github.com:username: ".bright()
|
43
83
|
}
|
44
84
|
end
|
45
85
|
|
46
86
|
# The application target deploy server
|
47
87
|
choose do |menu|
|
48
88
|
|
49
|
-
say "\nTARGET SERVERS"
|
89
|
+
say "\nTARGET SERVERS"
|
90
|
+
say "=============="
|
50
91
|
menu.prompt = "Please choose your deployment server?".bright()
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
92
|
+
menu.select_by = :index
|
93
|
+
|
94
|
+
# Adds the targets in the config file if there is one
|
95
|
+
if config[:repo]
|
96
|
+
config[:target].each do |val|
|
97
|
+
menu.choice(val) do |command|
|
98
|
+
say("Using #{command}")
|
99
|
+
data[:target_server] = command;
|
100
|
+
end
|
56
101
|
end
|
102
|
+
else
|
103
|
+
say "[INFO] There are no target urls in the default settings".color(:yellow)
|
57
104
|
end
|
58
105
|
|
59
106
|
menu.choice(:other) {
|
60
|
-
data[:target_server] = ask "Type the hostname or ip of the server to deploy to".bright()
|
107
|
+
data[:target_server] = ask "Type the hostname or ip of the server to deploy to:".bright()
|
61
108
|
}
|
62
109
|
end
|
63
110
|
|
111
|
+
# Add custom domain
|
112
|
+
say "\nCUSTOM DOMAIN"
|
113
|
+
say "============="
|
114
|
+
if yes? "Do you want to use #{data[:target_server].gsub(/^([a-z\d]*)/, data[:application_name])}? [Y/n]"
|
115
|
+
data[:domains] = data[:target_server].gsub(/^([a-z\d]*)/, data[:application_name])
|
116
|
+
else
|
117
|
+
data[:domains] = ask "Please enter the domains separated by spaces"
|
118
|
+
end
|
119
|
+
|
120
|
+
|
64
121
|
init(".", data)
|
122
|
+
|
123
|
+
say "\n\nWhat to do next?\n".bright()
|
124
|
+
say "You can try with cap -T to see the available tasks"
|
125
|
+
say "Also you can check the config/deploy.rb file, you may want to change some things there"
|
126
|
+
say "\n HAPPY DEPLOY".foreground(:green)
|
65
127
|
end
|
66
128
|
|
67
129
|
desc "deploy", "Deploy the application"
|
@@ -77,7 +139,7 @@ class Repo < Thor
|
|
77
139
|
if url.nil?
|
78
140
|
url = ask("Type the url and username e.g. git@github.com:username")
|
79
141
|
end
|
80
|
-
saveConfig(
|
142
|
+
saveConfig(:add, :repo, url)
|
81
143
|
end
|
82
144
|
|
83
145
|
desc "remove", "remove some repo"
|
@@ -97,7 +159,7 @@ class Target < Thor
|
|
97
159
|
if host.nil?
|
98
160
|
host = ask("Type the host or ip for the target machine")
|
99
161
|
end
|
100
|
-
saveConfig(
|
162
|
+
saveConfig(:add, :target, host)
|
101
163
|
end
|
102
164
|
|
103
165
|
desc "remove", "remove some target"
|
@@ -111,21 +173,6 @@ class Target < Thor
|
|
111
173
|
end
|
112
174
|
end
|
113
175
|
|
114
|
-
class Hosts < Thor
|
115
|
-
desc "add", "add new default target server"
|
116
|
-
def add(host=nil)
|
117
|
-
if host.nil?
|
118
|
-
host = ask("Type the host or ip for the target machine")
|
119
|
-
end
|
120
|
-
saveConfig("add", "target", host)
|
121
|
-
end
|
122
|
-
|
123
|
-
desc "remove", "remove some target"
|
124
|
-
def remove
|
125
|
-
puts "I will remove a target"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
176
|
class Konfig < Thor
|
130
177
|
namespace "config"
|
131
178
|
|
@@ -136,12 +183,53 @@ class Konfig < Thor
|
|
136
183
|
end
|
137
184
|
end
|
138
185
|
|
186
|
+
class RemoteEnv < Thor
|
187
|
+
namespace "env"
|
188
|
+
|
189
|
+
desc "show", "Show the current remote variables"
|
190
|
+
def show
|
191
|
+
`cap rbenv:vars:show`
|
192
|
+
end
|
193
|
+
|
194
|
+
desc "add", "Adds env variables to the remote server"
|
195
|
+
method_option :local, :type => :boolean, :aliases => "-l"
|
196
|
+
def add(key=nil, value=nil)
|
197
|
+
|
198
|
+
# Check if the paramenter were sent in the call
|
199
|
+
# Ask for the value if only the key was sent
|
200
|
+
if !key.nil? && value.nil?
|
201
|
+
value = ask("Please enter the value for #{key}:")
|
202
|
+
# If nothing was sent
|
203
|
+
elsif key.nil? && value.nil?
|
204
|
+
# Check if the .rbenv-vars file exists and offer get the info from there
|
205
|
+
if File.exist?(".rbenv-vars") && (yes? "Do you want to add variables from your local .rbenv-vars file [y/N]")
|
206
|
+
choose do |menu|
|
207
|
+
menu.prompt = "Please choose variable you want to add?".bright()
|
208
|
+
menu.select_by = :index
|
209
|
+
|
210
|
+
File.readlines(".rbenv-vars").each do |line|
|
211
|
+
menu.choice(line.gsub("\n","")) do |command|
|
212
|
+
key = command.split("=")[0]
|
213
|
+
value = command.split("=")[1]
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
else
|
218
|
+
key = ask("Please enter the variable key:")
|
219
|
+
value = ask("Please enter the value for #{key}:")
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
`cap rbenv:vars:add -s key=#{key} -s value=#{value}`
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
139
227
|
module Negroku
|
140
228
|
class CLI < Thor
|
141
229
|
register(App, 'app', 'app [COMMAND]', 'Application')
|
142
230
|
register(Repo, 'repo', 'repo [COMMAND]', 'Repositories')
|
143
231
|
register(Target, 'target', 'target [COMMAND]', 'Target servers')
|
144
|
-
register(Hosts, 'host', 'host [COMMAND]', 'Hosts')
|
145
232
|
register(Konfig, 'config', 'config [COMMAND]', 'Configuration')
|
233
|
+
register(RemoteEnv, 'env', 'env [COMMAND]', 'Remote environmental variables')
|
146
234
|
end
|
147
235
|
end
|
data/lib/negroku/config.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
|
-
# the yaml file where we'll write the settings
|
4
|
-
CONFIG_FILE = File.join(ENV['HOME'], ".negroku", "config.yaml")
|
5
|
-
|
6
3
|
def saveConfig(action, type, data)
|
7
|
-
# create the ~/.negroku folder
|
8
|
-
unless File.directory?(File.join(ENV['HOME'], ".negroku"))
|
9
|
-
puts "[Negroku] => Creating config file in #{ENV['HOME']}/.negroku"
|
10
|
-
%x(mkdir #{File.join(ENV['HOME'], ".negroku")})
|
11
|
-
end
|
12
|
-
|
13
|
-
# create an empty config.yaml file
|
14
|
-
unless File.exist?(CONFIG_FILE)
|
15
|
-
%x(touch #{CONFIG_FILE})
|
16
|
-
end
|
17
|
-
|
18
4
|
# Load the yaml file
|
19
|
-
|
5
|
+
config_file = File.join(ENV['HOME'], ".negroku")
|
6
|
+
config = getConfig
|
20
7
|
|
21
8
|
# If I need to add some multiple values
|
22
|
-
if action
|
9
|
+
if action === :add
|
23
10
|
newData = config[type] || []
|
24
11
|
newData.push(data)
|
25
12
|
newData.uniq!
|
26
13
|
config = config.merge({ type => newData })
|
27
|
-
elsif action
|
14
|
+
elsif action === :remove
|
28
15
|
#..
|
29
|
-
elsif action
|
16
|
+
elsif action === :replace
|
30
17
|
#..
|
31
18
|
end
|
32
19
|
|
33
|
-
File.open(
|
20
|
+
File.open(config_file, 'w') do |f|
|
34
21
|
f.write config.to_yaml
|
35
22
|
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def getConfig
|
26
|
+
# load config from file
|
27
|
+
config_file = File.join(ENV['HOME'], ".negroku")
|
28
|
+
|
29
|
+
# create an empty .negroku file
|
30
|
+
unless File.exist?(config_file)
|
31
|
+
%x(touch #{config_file})
|
32
|
+
end
|
33
|
+
|
34
|
+
# base config
|
35
|
+
YAML.load_file(config_file) || {}
|
36
36
|
end
|
data/lib/negroku/helpers.rb
CHANGED
data/lib/negroku/tasks/base.rb
CHANGED
@@ -33,7 +33,7 @@ namespace :deploy do
|
|
33
33
|
desc "Sets up additional symlinks after deploy."
|
34
34
|
task :symlinks do
|
35
35
|
# Exmaple:
|
36
|
-
|
36
|
+
run "ln -nfs '#{shared_path}/.rbenv-vars' '#{release_path}/.rbenv-vars'"
|
37
37
|
end
|
38
38
|
|
39
39
|
after "deploy:setup", "deploy:setup_shared"
|
data/lib/negroku/tasks/nginx.rb
CHANGED
@@ -6,12 +6,12 @@
|
|
6
6
|
# Feel free to further modify the template to your needs as it doesn't cover every use-case of course,
|
7
7
|
# but tries to get all the common requirements out of the way to lessen research time (if any).
|
8
8
|
|
9
|
-
set_default :domains, ["
|
9
|
+
set_default :domains, ["your.domain.com"]
|
10
10
|
set_default :static_dir, "public"
|
11
11
|
|
12
12
|
set_default :app_server, true
|
13
13
|
#set_default :app_server_port, 8080
|
14
|
-
set_default :app_server_socket, "/home/#{fetch(:user)}/tmp/
|
14
|
+
set_default :app_server_socket, "/home/#{fetch(:user)}/tmp/negroku.#{fetch(:application)}.sock"
|
15
15
|
|
16
16
|
# set_default :use_ssl, true
|
17
17
|
# set_default :ssl_key, "/path/to/local/ssh.key"
|
data/lib/negroku/tasks/rbenv.rb
CHANGED
@@ -4,9 +4,17 @@
|
|
4
4
|
set_default :ruby_version, "1.9.3-p125"
|
5
5
|
|
6
6
|
namespace :rbenv do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
namespace :vars do
|
8
|
+
desc "Show current rbenv vars"
|
9
|
+
task :show, :roles => :app do
|
10
|
+
run "sh -c 'cd #{shared_path} && cat .rbenv-vars'" do |channel, stream, data|
|
11
|
+
puts data
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Add rbenv vars"
|
16
|
+
task :add, :roles => :app do
|
17
|
+
run "echo '#{key}=#{value}' >> #{shared_path}/.rbenv-vars"
|
18
|
+
end
|
11
19
|
end
|
12
20
|
end
|
@@ -11,8 +11,8 @@ upstream <%= fetch(:application) %>-app-server {
|
|
11
11
|
|
12
12
|
# HTTP Server
|
13
13
|
server {
|
14
|
-
listen 80
|
15
|
-
server_name <%= fetch(:domains
|
14
|
+
listen 80;
|
15
|
+
server_name <%= fetch(:domains) %>;
|
16
16
|
root <%= fetch(:deploy_to) %>/current/<%= fetch(:static_dir) %>;
|
17
17
|
|
18
18
|
access_log /home/<%= fetch(:user) %>/log/<%= fetch(:application) %>-nginx-access.log;
|
@@ -8,11 +8,14 @@ set :deploy_to, "/home/#{user}/applications/#{application}"
|
|
8
8
|
|
9
9
|
# Repository (if any) configuration.
|
10
10
|
set :deploy_via, :remote_cache
|
11
|
-
set :repository, "<%= data[:repo]
|
11
|
+
set :repository, "<%= data[:repo] %>"
|
12
12
|
set :branch, "production" # Optional, defaults to master
|
13
13
|
# set :remote, "negroku" # Optional, defaults to origin
|
14
14
|
# set :git_enable_submodules, 1
|
15
15
|
|
16
|
+
# Web server configuration
|
17
|
+
set :domains, "<%= data[:domains] %>"
|
18
|
+
|
16
19
|
# Use the bundler capistrano task to deploy to the shared folder
|
17
20
|
require "bundler/capistrano"
|
18
21
|
set :bundle_flags, "--deployment --binstubs"
|
data/lib/negroku/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: negroku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -75,22 +75,6 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 0.17.0
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: parseconfig
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ! '>='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 1.0.2
|
86
|
-
type: :runtime
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 1.0.2
|
94
78
|
description: ! '["To deploy application"]'
|
95
79
|
email:
|
96
80
|
- jidonoso@gmail.com
|