atech_cloud 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module AtechCloud
2
+ end
3
+
@@ -0,0 +1,116 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ ## Server configuration
4
+ set :user, `whoami`.chomp
5
+ set :ssh_options, {:forward_agent => true, :port => 22}
6
+
7
+ ## Deployment namespace
8
+ namespace :deploy do
9
+ desc 'Deploy the latest revision of the application'
10
+ task :default do
11
+ update_code
12
+ restart
13
+ end
14
+
15
+ desc 'Deploy and migrate the database before restart'
16
+ task :migrations do
17
+ set :run_migrations, true
18
+ default
19
+ end
20
+
21
+ task :update_code, :roles => :app do
22
+ path = fetch(:deploy_to)
23
+ ## Create a branch for previous (pre-deployment)
24
+ run "cd #{path} && git branch -d rollback && git branch rollback"
25
+ ## Update remote repository and merge deploy branch into current branch
26
+ run "cd #{path} && git fetch origin && git reset --hard origin/#{fetch(:branch)}"
27
+ finalise
28
+ end
29
+
30
+ task :finalise, :roles => :app do
31
+ execute = Array.new
32
+ execute << "cd #{fetch(:deploy_to)}"
33
+ execute << "git submodule init"
34
+ execute << "git submodule sync"
35
+ execute << "git submodule update --recursive"
36
+ run execute.join(' && ')
37
+
38
+ run "cd #{fetch(:deploy_to)} && bundle --deployment --quiet"
39
+ migrate if fetch(:run_migrations, false)
40
+ end
41
+
42
+ desc 'Setup the repository on the remote server for the first time'
43
+ task :setup, :roles => :app do
44
+ path = fetch(:deploy_to)
45
+ run "git clone -n #{fetch(:repository)} #{path} --branch #{fetch(:branch)}"
46
+ run "cd #{path} && git branch rollback && git checkout -b deploy && git branch -d #{fetch(:branch)}"
47
+ run "sed 's/socket: \\\/tmp\\\/mysql.sock/host: db-a.cloud.atechmedia.net/' #{path}/config/database.yml.example > #{path}/config/database.yml ; true"
48
+ update_code
49
+ end
50
+ end
51
+
52
+ ## ==================================================================
53
+ ## Database
54
+ ## ==================================================================
55
+ desc 'Run database migrations on the remote'
56
+ task :migrate, :roles => :app, :only => {:database_ops => true} do
57
+ run "cd #{fetch(:deploy_to)} && RAILS_ENV=#{fetch(:environment)} bundle exec rake db:migrate"
58
+ end
59
+
60
+ ## ==================================================================
61
+ ## Rollback
62
+ ## ==================================================================
63
+ desc 'Rollback to the previous deployment'
64
+ task :rollback, :roles => :app do
65
+ run "cd #{fetch(:deploy_to)} && git reset --hard rollback"
66
+ deploy.finalise
67
+ deploy.restart
68
+ end
69
+
70
+ ## ==================================================================
71
+ ## Test
72
+ ## ==================================================================
73
+ desc 'Test the deployment connection'
74
+ task :testing do
75
+ run "whoami"
76
+ end
77
+
78
+ ## ==================================================================
79
+ ## init
80
+ ## ==================================================================
81
+ desc 'Restart the whole remote application'
82
+ task :restart, :roles => :app do
83
+ unicorn.restart
84
+ workers.restart if respond_to?(:workers)
85
+ end
86
+
87
+ desc 'Stop the whole remote application'
88
+ task :stop, :roles => :app do
89
+ unicorn.stop
90
+ workers.stop if respond_to?(:workers)
91
+ end
92
+
93
+ desc 'Start the whole remote application'
94
+ task :start, :roles => :app do
95
+ unicorn.start
96
+ workers.start if respond_to?(:workers)
97
+ end
98
+
99
+ ## ==================================================================
100
+ ## Unicorn Management
101
+ ## ==================================================================
102
+ namespace :unicorn do
103
+ task :start, :roles => :app do
104
+ run "sudo -u app sh -c \"cd #{fetch(:deploy_to)} && bundle exec unicorn_rails -E #{fetch(:environment)} -c #{fetch(:deploy_to)}/config/unicorn.rb -D\""
105
+ end
106
+
107
+ task :stop, :roles => :app do
108
+ run "sudo -u app sh -c \"kill `cat #{fetch(:deploy_to)}/tmp/pids/unicorn.pid`\""
109
+ end
110
+
111
+ task :restart, :roles => :app do
112
+ run "sudo -u app sh -c \"kill -USR2 `cat #{fetch(:deploy_to)}/tmp/pids/unicorn.pid`\""
113
+ end
114
+ end
115
+
116
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atech_cloud
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Adam Cooke
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-28 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: adam@atechmedia.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/atech_cloud/deploy.rb
32
+ - lib/atech_cloud.rb
33
+ has_rdoc: true
34
+ homepage: http://atechmedia.com
35
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: The RubyGem for the aTech Cloud
67
+ test_files: []
68
+