gv-valley 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/.gitignore +17 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/README.md +38 -0
- data/Rakefile +9 -0
- data/bin/gv-valley +6 -0
- data/bin/valley +319 -0
- data/gv-valley.gemspec +27 -0
- data/lib/gv/addons/etcd.rb +41 -0
- data/lib/gv/addons/memcached.rb +34 -0
- data/lib/gv/addons/postgresql.rb +42 -0
- data/lib/gv/tasks/install.rake +116 -0
- data/lib/gv/valley/addon.rb +62 -0
- data/lib/gv/valley/app.rb +108 -0
- data/lib/gv/valley/balancer.rb +61 -0
- data/lib/gv/valley/deployer.rb +104 -0
- data/lib/gv/valley/etcd.rb +40 -0
- data/lib/gv/valley/file_server.rb +115 -0
- data/lib/gv/valley/runner.rb +138 -0
- data/lib/gv/valley/version.rb +5 -0
- data/lib/gv/valley.rb +10 -0
- data/scripts/haproxy.cfg +47 -0
- data/scripts/receiver +22 -0
- data/test/gv/test_app.rb +64 -0
- data/test/gv/test_etcd.rb +39 -0
- data/test/minitest_helper.rb +7 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c6117529adbc808f6a13a4e17c1e8f697b5e085
|
4
|
+
data.tar.gz: 49fc611a1c2b486427db03b8085036d34dc9cb91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4543b48176a0bd9f1311f084d06ca6b825bf860a9e6614967971b21b38beb6dea9ffc755c795ec038d1ab19d668314a28a15a9c314e70d368f42abf3d6e6a117
|
7
|
+
data.tar.gz: 4c5c60f9385db2840999e50488212506452c1e8d9b0959cf076ba6c766611653351f2867a0d8d38f33978822ef4b491f0ad17ebef6fc1f068a98dba88d039e99
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <http://unlicense.org>
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# GV::Valley
|
2
|
+
|
3
|
+
Micro Private PaaS with Ruby.
|
4
|
+
Heavily influenced from dokku and flynn, also uses several flynn components. You
|
5
|
+
should use flynn instead, this is a distributed Ruby experiment which is not for
|
6
|
+
production use.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'gv-valley'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install gv-valley
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
$ gv-valley run # runs valley server
|
25
|
+
|
26
|
+
## Todo
|
27
|
+
|
28
|
+
- Write more tests
|
29
|
+
- Documentation
|
30
|
+
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( http://github.com/<my-github-username>/gv-valley/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/gv-valley
ADDED
data/bin/valley
ADDED
@@ -0,0 +1,319 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$stdout.sync = true
|
4
|
+
$stderr.sync = true
|
5
|
+
|
6
|
+
require "gv/valley"
|
7
|
+
require "commander/import"
|
8
|
+
|
9
|
+
require 'gv/valley/app'
|
10
|
+
require 'gv/valley/deployer'
|
11
|
+
require 'gv/valley/runner'
|
12
|
+
require 'gv/valley/balancer'
|
13
|
+
require 'sticks/pipe'
|
14
|
+
|
15
|
+
program :name, "Green Valley"
|
16
|
+
program :version, '0.0.1'
|
17
|
+
program :description, 'Green Valley CLI'
|
18
|
+
|
19
|
+
def restart_app app
|
20
|
+
deployer = GV::Valley::Deployer.service
|
21
|
+
deployer.stop app, &Sticks::Pipe::Blocks.stream
|
22
|
+
deployer.start app
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Apps API
|
27
|
+
|
28
|
+
command :'apps:deploy' do |c|
|
29
|
+
c.syntax = 'valley apps:deploy APP_NAME'
|
30
|
+
c.description = 'deploys app'
|
31
|
+
c.action do |args, options|
|
32
|
+
|
33
|
+
DRb.start_service
|
34
|
+
service = GV::Valley::Deployer.random_service
|
35
|
+
service.deploy args.first, &Sticks::Pipe::Blocks.stream
|
36
|
+
DRb.stop_service
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
command :'apps:config' do |c|
|
41
|
+
c.syntax = 'valley apps:config APP_NAME'
|
42
|
+
c.description = 'shows app config'
|
43
|
+
c.action do |args, options|
|
44
|
+
|
45
|
+
DRb.start_service
|
46
|
+
puts GV::Valley::App.find!(args.first)['config']
|
47
|
+
DRb.stop_service
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
command :'apps:config add' do |c|
|
52
|
+
c.syntax = 'valley apps:config add APP_NAME KEY=VALUE [KEY=VALUE]'
|
53
|
+
c.description = 'adds item to app config'
|
54
|
+
c.action do |args, options|
|
55
|
+
|
56
|
+
DRb.start_service
|
57
|
+
|
58
|
+
name = args.shift
|
59
|
+
config = Hash[args.map{|kv| kv.split("=")}]
|
60
|
+
app = GV::Valley::App.find!(name)
|
61
|
+
app["config"].update(config)
|
62
|
+
app.save
|
63
|
+
|
64
|
+
restart_app app
|
65
|
+
|
66
|
+
DRb.stop_service
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
command :'apps:config remove' do |c|
|
71
|
+
c.syntax = 'valley apps:config remove APP_NAME KEY [KEY]'
|
72
|
+
c.description = 'removes item from app config'
|
73
|
+
c.action do |args, options|
|
74
|
+
|
75
|
+
DRb.start_service
|
76
|
+
|
77
|
+
name = args.shift
|
78
|
+
app = GV::Valley::App.find!(name)
|
79
|
+
args.each do |key|
|
80
|
+
app["config"].delete(key)
|
81
|
+
end
|
82
|
+
app.save
|
83
|
+
|
84
|
+
restart_app app
|
85
|
+
|
86
|
+
DRb.stop_service
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
command :'apps:ps' do |c|
|
91
|
+
c.syntax = 'valley apps:ps APP_NAME'
|
92
|
+
c.description = 'shows app processes'
|
93
|
+
c.action do |args, options|
|
94
|
+
|
95
|
+
DRb.start_service
|
96
|
+
puts GV::Valley::App.find!(args.first)['ps'].map{|type,ps| {type => ps['scale']} }
|
97
|
+
DRb.stop_service
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
command :'apps:ps scale' do |c|
|
102
|
+
c.syntax = 'valley apps:ps scale APP_NAME TYPE=SCALE [TYPE=SCALE]'
|
103
|
+
c.description = 'shows app processes'
|
104
|
+
c.action do |args, options|
|
105
|
+
|
106
|
+
DRb.start_service
|
107
|
+
|
108
|
+
name = args.shift
|
109
|
+
ps = Hash[args.map{|kv| kv.split("=")}]
|
110
|
+
app = GV::Valley::App.find!(name)
|
111
|
+
ps.each do |key,scale|
|
112
|
+
if app['ps'][key]
|
113
|
+
app['ps'][key]['scale'] = scale.to_i
|
114
|
+
else
|
115
|
+
error "Process type #{key} not found"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
app.save
|
119
|
+
restart_app app
|
120
|
+
|
121
|
+
DRb.stop_service
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
command :'apps:domains' do |c|
|
126
|
+
c.syntax = 'valley apps:domains APP_NAME'
|
127
|
+
c.description = 'shows app domains'
|
128
|
+
c.action do |args, options|
|
129
|
+
|
130
|
+
DRb.start_service
|
131
|
+
puts GV::Valley::App.find!(args.first)['domains']
|
132
|
+
DRb.stop_service
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
command :'apps:domains add' do |c|
|
137
|
+
c.syntax = 'valley apps:domains add APP_NAME DOMAIN [DOMAIN]'
|
138
|
+
c.description = 'adds item to app domains'
|
139
|
+
c.action do |args, options|
|
140
|
+
|
141
|
+
DRb.start_service
|
142
|
+
|
143
|
+
name = args.shift
|
144
|
+
app = GV::Valley::App.find!(name)
|
145
|
+
domains = args - GV::Valley::App.all.map{|a| a["domains"]}.flatten
|
146
|
+
app["domains"] = (app["domains"] + domains).compact.uniq
|
147
|
+
app.save
|
148
|
+
|
149
|
+
GV::Valley::Balancer.service.reload &Sticks::Pipe::Blocks.stream
|
150
|
+
|
151
|
+
DRb.stop_service
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
command :'apps:domains remove' do |c|
|
156
|
+
c.syntax = 'valley apps:domains remove APP_NAME DOMAIN [DOMAIN]'
|
157
|
+
c.description = 'removes item from app domains'
|
158
|
+
c.action do |args, options|
|
159
|
+
|
160
|
+
DRb.start_service
|
161
|
+
|
162
|
+
name = args.shift
|
163
|
+
app = GV::Valley::App.find!(name)
|
164
|
+
app["domains"] = app["domains"] - args
|
165
|
+
app.save
|
166
|
+
|
167
|
+
GV::Valley::Balancer.service.reload &Sticks::Pipe::Blocks.stream
|
168
|
+
|
169
|
+
DRb.stop_service
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
command :'apps:run' do |c|
|
174
|
+
c.syntax = 'valley apps:run APP_NAME CMD'
|
175
|
+
c.description = 'runs cmd on app'
|
176
|
+
c.action do |args, options|
|
177
|
+
|
178
|
+
DRb.start_service
|
179
|
+
service = GV::Valley::Runner.random_service
|
180
|
+
name = args.shift
|
181
|
+
cmd = args.join(" ")
|
182
|
+
block = cmd =~ Sticks::Pipe::INTERACTIVE_COMMANDS ? Sticks::Pipe::Blocks.interactive : Sticks::Pipe::Blocks.stream
|
183
|
+
service.run name, cmd, &block
|
184
|
+
DRb.stop_service
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
command :'apps:logs' do |c|
|
189
|
+
c.syntax = 'valley apps:logs APP_NAME <PS>'
|
190
|
+
c.description = 'runs cmd on app'
|
191
|
+
c.option '-f','--follow', String, 'streams log'
|
192
|
+
c.action do |args, options|
|
193
|
+
|
194
|
+
DRb.start_service
|
195
|
+
name = args.shift
|
196
|
+
app = GV::Valley::App.find!(name)
|
197
|
+
ps = args.shift
|
198
|
+
psname = "#{name}.#{ps}"
|
199
|
+
|
200
|
+
# debug GV::Valley::Deployer.space.read_all([:ps,/#{psname}/,nil,nil])
|
201
|
+
|
202
|
+
tuple = [:ps, /#{psname}/, nil, nil ]
|
203
|
+
block = options.follow ? Sticks::Pipe::Blocks.stream : Sticks::Pipe::Blocks.capture
|
204
|
+
(GV::Valley::Deployer.space.read_all(tuple) rescue []).each do |h|
|
205
|
+
h[2].logs psname,options.follow, &block
|
206
|
+
end
|
207
|
+
|
208
|
+
DRb.stop_service
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
command :'apps:logs' do |c|
|
213
|
+
c.syntax = 'valley apps:logs APP_NAME <PS>'
|
214
|
+
c.description = 'runs cmd on app'
|
215
|
+
c.option '-f','--follow', String, 'streams log'
|
216
|
+
c.action do |args, options|
|
217
|
+
|
218
|
+
DRb.start_service
|
219
|
+
name = args.shift
|
220
|
+
app = GV::Valley::App.find!(name)
|
221
|
+
ps = args.shift
|
222
|
+
psname = "#{name}.#{ps}"
|
223
|
+
|
224
|
+
# debug GV::Valley::Deployer.space.read_all([:ps,/#{psname}/,nil,nil])
|
225
|
+
|
226
|
+
tuple = [:ps, /#{psname}/, nil, nil ]
|
227
|
+
block = options.follow ? Sticks::Pipe::Blocks.stream : Sticks::Pipe::Blocks.capture
|
228
|
+
(GV::Valley::Deployer.space.read_all(tuple) rescue []).each do |h|
|
229
|
+
h[2].logs psname,options.follow, &block
|
230
|
+
end
|
231
|
+
|
232
|
+
DRb.stop_service
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
command :'apps:destroy' do |c|
|
237
|
+
c.syntax = 'valley apps:destroy APP_NAME'
|
238
|
+
c.description = 'destroys app'
|
239
|
+
c.action do |args, options|
|
240
|
+
|
241
|
+
DRb.start_service
|
242
|
+
|
243
|
+
name = args.shift
|
244
|
+
app = GV::Valley::App.find!(name)
|
245
|
+
|
246
|
+
deployer = GV::Valley::Deployer.service
|
247
|
+
deployer.stop app, &Sticks::Pipe::Blocks.stream
|
248
|
+
|
249
|
+
app.delete
|
250
|
+
|
251
|
+
DRb.stop_service
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
command :'balancer:reload' do |c|
|
256
|
+
c.syntax = 'valley balancer:reload'
|
257
|
+
c.description = 'reloads haproxy config'
|
258
|
+
c.action do |args, options|
|
259
|
+
|
260
|
+
DRb.start_service
|
261
|
+
|
262
|
+
balancer = GV::Valley::Balancer.service
|
263
|
+
balancer.reload &Sticks::Pipe::Blocks.stream
|
264
|
+
|
265
|
+
DRb.stop_service
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
command :'addons:create' do |c|
|
270
|
+
c.syntax = 'valley addons:create NAME APP_NAME'
|
271
|
+
c.description = 'creates addon service'
|
272
|
+
c.action do |args, options|
|
273
|
+
|
274
|
+
DRb.start_service
|
275
|
+
addon = args.shift
|
276
|
+
app_name = args.shift
|
277
|
+
|
278
|
+
require "gv/addons/#{addon}"
|
279
|
+
addon_service = "GV::Addons::#{addon.classify}".constantize.service
|
280
|
+
addon_service.create app_name
|
281
|
+
|
282
|
+
DRb.stop_service
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
command :'addons:run' do |c|
|
287
|
+
c.syntax = 'valley addons:run NAME APP_NAME CMD'
|
288
|
+
c.description = 'runs method on addon service'
|
289
|
+
c.action do |args, options|
|
290
|
+
|
291
|
+
DRb.start_service
|
292
|
+
addon = args.shift
|
293
|
+
app_name = args.shift
|
294
|
+
cmd = args.shift
|
295
|
+
|
296
|
+
require "gv/addons/#{addon}"
|
297
|
+
addon_service = "GV::Addons::#{addon.classify}".constantize.service
|
298
|
+
puts addon_service.public_send(cmd, app_name)
|
299
|
+
|
300
|
+
DRb.stop_service
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
command :'addons:destroy' do |c|
|
305
|
+
c.syntax = 'valley addons:destroy NAME APP_NAME'
|
306
|
+
c.description = 'destroys addon service'
|
307
|
+
c.action do |args, options|
|
308
|
+
|
309
|
+
DRb.start_service
|
310
|
+
addon = args.shift
|
311
|
+
app_name = args.shift
|
312
|
+
|
313
|
+
require "gv/addons/#{addon}"
|
314
|
+
addon_service = "GV::Addons::#{addon.classify}".constantize.service
|
315
|
+
addon_service.destroy app_name
|
316
|
+
|
317
|
+
DRb.stop_service
|
318
|
+
end
|
319
|
+
end
|
data/gv-valley.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gv/valley/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gv-valley"
|
8
|
+
spec.version = GV::Valley::VERSION
|
9
|
+
spec.authors = ["Onur Uyar"]
|
10
|
+
spec.email = ["me@onuruyar.com"]
|
11
|
+
spec.summary = %q{Micro Private PaaS with Ruby}
|
12
|
+
spec.homepage = "https://github.com/green-valley/gv-valley"
|
13
|
+
spec.license = "Unlicense"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "minitest"
|
23
|
+
spec.add_dependency 'goliath'
|
24
|
+
spec.add_dependency 'etcd'
|
25
|
+
spec.add_dependency 'gv-common'
|
26
|
+
spec.add_dependency 'gv-bedrock'
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'gv/valley'
|
2
|
+
require 'gv/valley/addon'
|
3
|
+
|
4
|
+
module GV
|
5
|
+
module Addons
|
6
|
+
class Etcd < GV::Valley::Addon
|
7
|
+
|
8
|
+
PORT = 4001
|
9
|
+
|
10
|
+
CONTAINER_DIR="/data/db"
|
11
|
+
|
12
|
+
def image; "flynn/etcd" end
|
13
|
+
|
14
|
+
def params
|
15
|
+
"-v #{@home}/#{@name}/#{@app_name}:#{CONTAINER_DIR}:rw"
|
16
|
+
end
|
17
|
+
|
18
|
+
def cmd
|
19
|
+
"--name=#{@app_name} -data-dir=#{CONTAINER_DIR}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def url app_name
|
23
|
+
@app_name = app_name
|
24
|
+
self.class.space.read([@name.to_sym,@app_name,nil,nil],0) rescue nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def create app_name
|
28
|
+
super app_name
|
29
|
+
self.class.space.write([@name.to_sym,@app_name,"http://#{self.external_ip}:#{port(app_name)}",self.external_ip])
|
30
|
+
end
|
31
|
+
|
32
|
+
def destroy app_name
|
33
|
+
super app_name
|
34
|
+
tuple = [@name.to_sym,@app_name,nil,nil]
|
35
|
+
(self.class.space.take(tuple,0) rescue nil) while (self.class.space.read(tuple,0) rescue nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'gv/valley'
|
2
|
+
require 'gv/valley/addon'
|
3
|
+
|
4
|
+
module GV
|
5
|
+
module Addons
|
6
|
+
class Memcached < GV::Valley::Addon
|
7
|
+
|
8
|
+
PORT = 4001
|
9
|
+
|
10
|
+
CONTAINER_DIR="/data/db"
|
11
|
+
|
12
|
+
def image; "bacongobbler/memcached" end
|
13
|
+
|
14
|
+
|
15
|
+
def url app_name
|
16
|
+
@app_name = app_name
|
17
|
+
self.class.space.read([@name.to_sym,@app_name,nil,nil],0) rescue nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def create app_name
|
21
|
+
super app_name
|
22
|
+
self.class.space.write([@name.to_sym,@app_name,"#{self.external_ip}:#{port(app_name)}",self.external_ip])
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy app_name
|
26
|
+
super app_name
|
27
|
+
tuple = [@name.to_sym,@app_name,nil,nil]
|
28
|
+
(self.class.space.take(tuple,0) rescue nil) while (self.class.space.read(tuple,0) rescue nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'gv/valley'
|
2
|
+
require 'gv/valley/addon'
|
3
|
+
|
4
|
+
module GV
|
5
|
+
module Addons
|
6
|
+
class Postgresql < GV::Valley::Addon
|
7
|
+
|
8
|
+
PORT = 5432
|
9
|
+
|
10
|
+
CONTAINER_DIR="/var/lib/postgresql/9.3/main"
|
11
|
+
|
12
|
+
def image; "valley/postgresql" end
|
13
|
+
|
14
|
+
def params
|
15
|
+
["-v #{@home}/#{@name}/#{@app_name}:#{CONTAINER_DIR} -w #{CONTAINER_DIR}",
|
16
|
+
"-e POSTGRESQL_USER=#{@app_name}",
|
17
|
+
"-e POSTGRESQL_PASS=#{@pass=rand(2**64).to_s(36)}",
|
18
|
+
"-e POSTGRESQL_DB=#{@app_name}"
|
19
|
+
].join(" ")
|
20
|
+
end
|
21
|
+
|
22
|
+
def url app_name
|
23
|
+
@app_name = app_name
|
24
|
+
self.class.space.read([@name.to_sym,@app_name,nil,nil],0)[2] rescue nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def create app_name
|
28
|
+
if super(app_name)
|
29
|
+
self.class.space.write([@name.to_sym,@app_name,"postgres://#{@app_name}:#{@pass}@#{self.external_ip}:#{port(app_name)}/#{@app_name}",self.external_ip])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy app_name
|
34
|
+
super app_name
|
35
|
+
tuple = [@name.to_sym,@app_name,nil,nil]
|
36
|
+
(self.class.space.take(tuple,0) rescue nil) while (self.class.space.read(tuple,0) rescue nil)
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'gv/valley'
|
2
|
+
|
3
|
+
USER = ENV['VALLEY_USER'] || "val"
|
4
|
+
HOME = ENV['VALLEY_HOME'] || "/home/#{USER}"
|
5
|
+
CONFIG_DIR = "/etc/greenvalley/config"
|
6
|
+
|
7
|
+
namespace :install do
|
8
|
+
|
9
|
+
def capture cmd
|
10
|
+
`#{cmd}`.chomp rescue nil
|
11
|
+
end
|
12
|
+
|
13
|
+
task :config_dir do
|
14
|
+
mkdir_p CONFIG_DIR
|
15
|
+
end
|
16
|
+
|
17
|
+
task :domain => ['install:config_dir'] do
|
18
|
+
unless File.exists? "#{CONFIG_DIR}/domain"
|
19
|
+
print "Enter Domain: "
|
20
|
+
domain = STDIN.gets.strip
|
21
|
+
if domain.empty?
|
22
|
+
abort "Domain cannot be blank"
|
23
|
+
end
|
24
|
+
sh "echo \"#{domain}\" > #{CONFIG_DIR}/domain"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
task :user => ['install:config_dir'] do
|
29
|
+
sh "useradd #{USER}" rescue nil
|
30
|
+
sh "chown -R #{USER} #{CONFIG_DIR}"
|
31
|
+
sh "echo \"#{USER}\" > #{CONFIG_DIR}/user" unless File.exists? "#{CONFIG_DIR}/user"
|
32
|
+
sh "echo \"#{HOME}\" > #{CONFIG_DIR}/home" unless File.exists? "#{CONFIG_DIR}/home"
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Install Gitreceive"
|
36
|
+
task :gitreceive => ['install:user'] do
|
37
|
+
|
38
|
+
sh "wget -O /usr/local/bin/gitreceive https://raw.githubusercontent.com/progrium/gitreceive/master/gitreceive"
|
39
|
+
sh "chmod +x /usr/local/bin/gitreceive"
|
40
|
+
sh "GITUSER=#{USER} gitreceive init"
|
41
|
+
|
42
|
+
cp "#{GV::Valley.root}/scripts/receiver", "#{HOME}/receiver"
|
43
|
+
sh "chmod +x #{HOME}/receiver"
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
task :aufs do
|
48
|
+
sh "lsmod | grep aufs || modprobe aufs || apt-get install -y linux-image-extra-`uname -r`"
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Install Docker"
|
52
|
+
task :docker => ['install:aufs','install:user'] do
|
53
|
+
if capture('docker -v').nil?
|
54
|
+
sh "egrep -i \"^docker\" /etc/group || groupadd docker"
|
55
|
+
sh "usermod -aG docker #{USER}"
|
56
|
+
sh "curl https://get.docker.io/gpg | apt-key add -"
|
57
|
+
sh "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
|
58
|
+
sh "apt-get update"
|
59
|
+
sh "apt-get install -y lxc-docker"
|
60
|
+
sh "sleep 2" # give docker a moment i guess
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Pull Docker repo"
|
65
|
+
task :pull, [:repo] => ['install:docker'] do |t,args|
|
66
|
+
if capture("docker images | grep #{args.repo}").empty?
|
67
|
+
sh "docker pull #{args.repo}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Pulls flynn/etcd"
|
72
|
+
task :etcd do
|
73
|
+
Rake::Task['install:pull'].invoke("flynn/etcd")
|
74
|
+
end
|
75
|
+
|
76
|
+
desc "Pulls flynn/slugbuilder"
|
77
|
+
task :slugbuilder => ['install:docker'] do
|
78
|
+
Rake::Task['install:pull'].invoke("flynn/slugbuilder")
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "Pulls flynn/slugrunner"
|
82
|
+
task :slugrunner => ['install:docker'] do
|
83
|
+
Rake::Task['install:pull'].invoke("flynn/slugrunner")
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "Install Haproxy"
|
87
|
+
task :haproxy => ['install:user'] do
|
88
|
+
if capture("haproxy -v").nil?
|
89
|
+
sh "add-apt-repository -y ppa:vbernat/haproxy-1.5"
|
90
|
+
sh "apt-get update -y -q"
|
91
|
+
sh "apt-get install haproxy -y -q"
|
92
|
+
sh "echo \"ENABLED=1\" >> /etc/default/haproxy"
|
93
|
+
end
|
94
|
+
cp "#{GV::Valley.root}/scripts/haproxy.cfg", "/etc/haproxy/haproxy.cfg"
|
95
|
+
sh "usermod -aG haproxy #{USER}"
|
96
|
+
chmod 0770, "/etc/haproxy/haproxy.cfg"
|
97
|
+
sh "chgrp haproxy /etc/haproxy/haproxy.cfg"
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
desc "Installs bare host to run apps"
|
102
|
+
task :host do
|
103
|
+
Rake::Task['install:slugrunner'].invoke
|
104
|
+
end
|
105
|
+
|
106
|
+
desc "Installs Green Valley"
|
107
|
+
task :valley => ['install:domain','install:user'] do
|
108
|
+
Rake::Task['install:gitreceive'].invoke
|
109
|
+
Rake::Task['install:slugbuilder'].invoke
|
110
|
+
Rake::Task['install:slugrunner'].invoke
|
111
|
+
Rake::Task['install:haproxy'].invoke
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
task :install => ['install:valley']
|