capistrano-alice 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in capistrano-alice.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "capistrano-alice/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "capistrano-alice"
7
+ s.version = Capistrano::Alice::VERSION
8
+ s.authors = ["Simon Menke"]
9
+ s.email = ["simon.menke@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{[ALICE] capistrano extention for alice}
12
+ s.description = %q{This makes deploying apps to alice/pluto much easier.}
13
+
14
+ s.rubyforge_project = "capistrano-alice"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "yajl-ruby"
24
+ end
@@ -0,0 +1,36 @@
1
+
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+
4
+ namespace :alice do
5
+ namespace :maintenance do
6
+
7
+ # happens before deploy:update_code
8
+ task :on do
9
+ on_rollback { find_and_execute_task("alice:maintenance:off") }
10
+
11
+ path = "/api_v1/applications/#{alice_config.application}/maintenance.json"
12
+ Net::HTTP.start(alice_config.alice_host, alice_config.alice_port) do |http|
13
+ request = Net::HTTP::Post.new(path)
14
+ request.body = Yajl::Encoder.encode({})
15
+ request.content_type = "application/json"
16
+ request['Accepts'] = "application/json"
17
+ response = http.request(request)
18
+ end
19
+ end
20
+
21
+ # happens after deploy:restart
22
+ task :off do
23
+ path = "/api_v1/applications/#{alice_config.application}/maintenance.json"
24
+ Net::HTTP.start(alice_config.alice_host, alice_config.alice_port) do |http|
25
+ request = Net::HTTP::Delete.new(path)
26
+ request.body = Yajl::Encoder.encode({})
27
+ request.content_type = "application/json"
28
+ request['Accepts'] = "application/json"
29
+ response = http.request(request)
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,166 @@
1
+ class Capistrano::Alice::Release
2
+ attr_accessor :servers
3
+ attr_accessor :processes
4
+ attr_accessor :path_rules
5
+
6
+ attr_accessor :id
7
+ attr_accessor :number
8
+
9
+ def initialize(config)
10
+ @config = config
11
+ end
12
+
13
+ def create!
14
+ body = {
15
+ "application" => @config.application,
16
+ "machines" => @servers,
17
+ "processes" => @processes,
18
+ "path_rules" => (@path_rules || {}).to_a
19
+ }
20
+
21
+ Net::HTTP.start(@config.alice_host, @config.alice_port) do |http|
22
+ request = Net::HTTP::Post.new("/api_v1/releases.json")
23
+ request.body = Yajl::Encoder.encode(body)
24
+ request.content_type = "application/json"
25
+ request['Accepts'] = "application/json"
26
+ response = http.request(request)
27
+ if Net::HTTPSuccess === response
28
+ response = Yajl::Parser.parse(response.body)
29
+ @id = response['release']['id']
30
+ @number = response['release']['number']
31
+ else
32
+ raise "Failed to create release!"
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ def activate!
39
+ Net::HTTP.start(@config.alice_host, @config.alice_port) do |http|
40
+ request = Net::HTTP::Post.new("/api_v1/releases/#{@id}/activate.json")
41
+ request.body = Yajl::Encoder.encode({})
42
+ request.content_type = "application/json"
43
+ request['Accepts'] = "application/json"
44
+ response = http.request(request)
45
+ end
46
+ end
47
+
48
+ def destroy!
49
+ Net::HTTP.start(@config.alice_host, @config.alice_port) do |http|
50
+ request = Net::HTTP::Delete.new("/api_v1/releases/#{@id}.json")
51
+ request.content_type = "application/json"
52
+ request['Accepts'] = "application/json"
53
+ response = http.request(request)
54
+ end
55
+ end
56
+ end
57
+
58
+
59
+ Capistrano::Configuration.instance(:must_exist).load do
60
+ set(:alice_release) { Capistrano::Alice::Release.new(alice_config) }
61
+
62
+ namespace :alice do
63
+ namespace :release do
64
+
65
+ # happens before deploy:update_code
66
+ task :create, :except => { :no_release => true } do
67
+ find_and_execute_task("alice:release:_create:collect_servers")
68
+ find_and_execute_task("alice:release:_create:collect_processes")
69
+ find_and_execute_task("alice:release:_create:collect_path_rules")
70
+
71
+ on_rollback { find_and_execute_task("alice:release:destroy") }
72
+
73
+ alice_release.create!
74
+ end
75
+
76
+ task :destroy, :except => { :no_release => true } do
77
+ alice_release.destroy!
78
+ end
79
+
80
+ # happens after deploy:restart
81
+ task :activate, :except => { :no_release => true } do
82
+ alice_release.activate!
83
+ end
84
+
85
+ namespace :_create do
86
+
87
+ task :collect_servers, :except => { :no_release => true } do
88
+ alice_release.servers = find_servers.map(&:to_s)
89
+ end
90
+
91
+ task :collect_processes, :except => { :no_release => true } do
92
+ processes = {}
93
+
94
+ unless File.file?('Procfile')
95
+ abort "[ALICE]: Missing Procfile!"
96
+ end
97
+
98
+ File.read('Procfile').split("\n").each do |line|
99
+ line = line.split('#', 2).first
100
+ name, command = line.split(':', 2)
101
+ name, command = (name || '').strip, (command || '').strip
102
+
103
+ next if name.empty? or command.empty?
104
+
105
+ processes[name] = command
106
+ end
107
+
108
+ if processes.empty?
109
+ abort "[ALICE]: Empty or invalid Procfile!"
110
+ end
111
+
112
+ alice_release.processes = processes
113
+ end
114
+
115
+ task :collect_path_rules, :except => { :no_release => true } do
116
+ path_rules = {}
117
+
118
+ if alice_release.processes.key?('web')
119
+ path_rules.merge!('/*' => [["forward", "web"]])
120
+ end
121
+
122
+ if alice_release.processes.key?('static')
123
+ path_rules.merge!(
124
+ '/assets/*' => [
125
+ ["cache-control", "public,max-age=600"],
126
+ ["forward", "static"]
127
+ ],
128
+ '/system/*' => [
129
+ ["cache-control", "public,max-age=600"],
130
+ ["forward", "static"]
131
+ ]
132
+ )
133
+
134
+ fetch(:alice_static_paths, []).each do |path|
135
+ path_rules[path] = [
136
+ ["cache-control", "public,max-age=600"],
137
+ ["forward", "static"]
138
+ ]
139
+ end
140
+
141
+ Dir.entries('public').each do |path|
142
+ next if path[0,1] == '.'
143
+
144
+ if File.directory?(path)
145
+ path_rules[File.join('', path, '*')] = [
146
+ ["cache-control", "public,max-age=600"],
147
+ ["forward", "static"]
148
+ ]
149
+ elsif File.file?(path)
150
+ path_rules[File.join('', path)] = [
151
+ ["cache-control", "public,max-age=600"],
152
+ ["forward", "static"]
153
+ ]
154
+ end
155
+ end
156
+ end
157
+
158
+ path_rules.merge! fetch(:alice_path_rules, {})
159
+
160
+ alice_release.path_rules = path_rules
161
+ end
162
+
163
+ end
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Alice
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ require 'net/http'
2
+ require 'yajl'
3
+
4
+ module Capistrano
5
+ module Alice
6
+ require "capistrano-alice/version"
7
+ end
8
+ end
9
+
10
+ class Capistrano::Alice::Configuration
11
+
12
+ attr_accessor :alice_host
13
+ attr_accessor :alice_port
14
+ attr_accessor :application
15
+
16
+ end
17
+
18
+ Capistrano::Configuration.instance(:must_exist).load do
19
+ require 'capistrano-alice/maintenance_mode'
20
+ require 'capistrano-alice/release_managment'
21
+
22
+ set :alice_application do
23
+ application
24
+ end
25
+
26
+ set :alice_config do
27
+ conf = Capistrano::Alice::Configuration.new
28
+ conf.alice_host = alice_host
29
+ conf.alice_port = alice_port
30
+ conf.application = alice_application
31
+ conf
32
+ end
33
+
34
+ before "deploy:update_code", "alice:maintenance:on"
35
+ before "deploy:update_code", "alice:release:create"
36
+ after "deploy:restart", "alice:release:activate"
37
+ after "deploy:restart", "alice:maintenance:off"
38
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-alice
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Simon Menke
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-01-13 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: yajl-ruby
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: This makes deploying apps to alice/pluto much easier.
35
+ email:
36
+ - simon.menke@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - Rakefile
47
+ - capistrano-alice.gemspec
48
+ - lib/capistrano-alice.rb
49
+ - lib/capistrano-alice/maintenance_mode.rb
50
+ - lib/capistrano-alice/release_managment.rb
51
+ - lib/capistrano-alice/version.rb
52
+ homepage: ""
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project: capistrano-alice
81
+ rubygems_version: 1.8.6
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: "[ALICE] capistrano extention for alice"
85
+ test_files: []
86
+