stuzo-recipes 0.0.0 → 0.1.0
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/VERSION +1 -1
- data/lib/cap/tasks.rb +113 -0
- data/lib/rake/tasks.rb +31 -0
- metadata +3 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.0
|
data/lib/cap/tasks.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'yaml'
|
5
|
+
require 'capistrano/ext/multistage'
|
6
|
+
require 'stuzo-recipes/git-deployment/gitflow.rb'
|
7
|
+
require 'railsless-deploy'
|
8
|
+
require 'erb'
|
9
|
+
require 'cap_recipes/tasks/apache/manage'
|
10
|
+
require 'active_record/schema_dumper'
|
11
|
+
|
12
|
+
|
13
|
+
def _cset(name, *args, &block)
|
14
|
+
unless exists?(name)
|
15
|
+
set(name, *args, &block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# =========================================================================
|
20
|
+
# These variables MUST be set in the client capfiles. If they are not set,
|
21
|
+
# the deploy will fail with an error.
|
22
|
+
# =========================================================================
|
23
|
+
|
24
|
+
_cset(:application) { abort "Please specify the name of your application, set :application, 'foo'" }
|
25
|
+
_cset(:repository) { abort "Please specify the repository that houses your application's code, set :repository, 'foo'" }
|
26
|
+
|
27
|
+
_cset :scm, :git
|
28
|
+
_cset :deploy_via, :remote_cache
|
29
|
+
|
30
|
+
_cset :sz_user, 'gunter'
|
31
|
+
def generate_vhost
|
32
|
+
vhost_erb = <<ERB
|
33
|
+
<VirtualHost *>
|
34
|
+
ServerName <%= data[:server_name] %>
|
35
|
+
ServerAdmin admin@stuzo.com
|
36
|
+
|
37
|
+
DocumentRoot <%= data[:document_root] %>
|
38
|
+
|
39
|
+
ErrorLog <%= data[:error_log] %>
|
40
|
+
LogLevel warn
|
41
|
+
CustomLog <%= data[:error_log] %> combined
|
42
|
+
</VirtualHost>
|
43
|
+
ERB
|
44
|
+
data = {:server_name => "#{application}.#{base_domain}",
|
45
|
+
:document_root => "#{deploy_to}/current",
|
46
|
+
:error_log => "#{shared_path}/logs/#{application}.log"}
|
47
|
+
buffer = ERB.new(vhost_erb).result(binding)
|
48
|
+
return StringIO.new(buffer)
|
49
|
+
end
|
50
|
+
|
51
|
+
def _render_template(data, template)
|
52
|
+
template = File.read(File.join(project_root, 'config/templates', template))
|
53
|
+
buffer = ERB.new(template).result(binding)
|
54
|
+
return StringIO.new(buffer)
|
55
|
+
end
|
56
|
+
|
57
|
+
def run_remote_rake(rake_cmd)
|
58
|
+
run "cd #{current_path} && #{rake} #{env_args} CI_ENV=#{ci_env} #{rakefile} #{rake_cmd.split(',').join(' ')}"
|
59
|
+
set :rakefile, nil if exists?(:rakefile)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Temporarily sets an environment variable, yields to a block, and restores
|
63
|
+
# the value when it is done.
|
64
|
+
def with_env(name, value)
|
65
|
+
saved, ENV[name] = ENV[name], value
|
66
|
+
yield
|
67
|
+
ensure
|
68
|
+
ENV[name] = saved
|
69
|
+
end
|
70
|
+
|
71
|
+
# logs the command then executes it locally.
|
72
|
+
# returns the command output as a string
|
73
|
+
def run_locally(cmd)
|
74
|
+
logger.trace "executing locally: #{cmd.inspect}" if logger
|
75
|
+
`#{cmd}`
|
76
|
+
end
|
77
|
+
|
78
|
+
namespace :deploy do
|
79
|
+
desc <<-DESC
|
80
|
+
Create folder skeleton
|
81
|
+
DESC
|
82
|
+
task :setup, :except => { :no_release => true } do
|
83
|
+
set :use_sudo, false
|
84
|
+
sudo("chown -R deploy:deploy #{File.expand_path(File.join(deploy_to,'..'))}")
|
85
|
+
dirs = [deploy_to, releases_path, shared_path]
|
86
|
+
dirs += shared_children.map { |d| File.join(shared_path, d) }
|
87
|
+
run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
_cset :aws_private_key_path, "~/.ec2/ec2keypair.pem"
|
92
|
+
_cset :use_sudo, false
|
93
|
+
_cset :user, 'deploy'
|
94
|
+
_cset :password, 'xxxxx'
|
95
|
+
_cset :application, "yyyyy.stuzo.com"
|
96
|
+
_cset :domain, "yyyyy.stuzo.com"
|
97
|
+
_cset :deploy_to, "/data/www/development/#{sz_user}/#{application}"
|
98
|
+
|
99
|
+
namespace :ec2 do
|
100
|
+
desc "uploads id_rsa.pub to the EC2 instance's deploy users authorized_keys2 file"
|
101
|
+
task :bootstrap_deploy_user do
|
102
|
+
system "ssh -i #{aws_private_key_path} root@#{domain} \"groupadd admin\""
|
103
|
+
system "ssh -i #{aws_private_key_path} root@#{domain} \"useradd -d /home/#{user} -s /bin/bash -m #{user}\""
|
104
|
+
system "ssh -i #{aws_private_key_path} root@#{domain} \"echo #{user}:#{password} | chpasswd\""
|
105
|
+
system "ssh -i #{aws_private_key_path} root@#{domain} \"usermod -a -G admin deploy\""
|
106
|
+
system "ssh -i #{aws_private_key_path} root@#{domain} \"mkdir /home/#{user}/.ssh\""
|
107
|
+
for key in ssh_options[:keys]
|
108
|
+
system "cat #{key}.pub | ssh -i #{aws_private_key_path} root@#{domain} \"cat >> /home/#{user}/.ssh/authorized_keys2\""
|
109
|
+
end
|
110
|
+
system "ssh -i #{aws_private_key_path} root@#{domain} \"chown -R #{user}:#{user} /home/#{user}/.ssh\""
|
111
|
+
syst
|
112
|
+
end
|
113
|
+
end
|
data/lib/rake/tasks.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
|
5
|
+
namespace :stuzo do
|
6
|
+
namespace :tunnel do
|
7
|
+
desc "Start a reverse tunnel for local development. Reads from config/tunnel.yml"
|
8
|
+
task :start do
|
9
|
+
config_yml = YAML.load_file(File.join(BASE_PATH, 'config/tunnel.yml'))
|
10
|
+
remote_port = config_yml['remote_port']
|
11
|
+
local_port = config_yml['local_port']
|
12
|
+
remote_domain = config_yml['remote_domain']
|
13
|
+
local_domain = config_yml['local_domain']
|
14
|
+
user = config_yml['user']
|
15
|
+
cmd = "ssh -nNT -R #{remote_port}:#{local_domain}:#{local_port} #{user}@#{remote_domain}"
|
16
|
+
exec cmd
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Check if reverse tunnel is running"
|
20
|
+
task :status do
|
21
|
+
config_yml = YAML.load_file(File.join(BASE_PATH, 'config/tunnel.yml'))
|
22
|
+
|
23
|
+
if `ssh #{config_yml['remote_domain']} netstat -an |
|
24
|
+
egrep "tcp.*:#{config_yml['remote_port']}.*LISTEN" | wc`.to_i > 0
|
25
|
+
puts "Seems ok"
|
26
|
+
else
|
27
|
+
puts "Down"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stuzo-recipes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse McPherson
|
@@ -40,10 +40,12 @@ files:
|
|
40
40
|
- README.rdoc
|
41
41
|
- Rakefile
|
42
42
|
- VERSION
|
43
|
+
- lib/cap/tasks.rb
|
43
44
|
- lib/git-deployment/README
|
44
45
|
- lib/git-deployment/VERSION
|
45
46
|
- lib/git-deployment/gitflow.rb
|
46
47
|
- lib/git-deployment/natcmp.rb
|
48
|
+
- lib/rake/tasks.rb
|
47
49
|
- lib/stuzo-recipes.rb
|
48
50
|
- spec/spec.opts
|
49
51
|
- spec/spec_helper.rb
|