slnky 0.2.1 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad012b2c490543ade16d3cd04419aa0d14d6f9e0
4
- data.tar.gz: bfd7e4f870db6a0f238a8ef2b44b21028ca02d16
3
+ metadata.gz: 477bf08c5bdd20d0a2abf503ab78f50a70e4e3ad
4
+ data.tar.gz: 1f10dc0f2b82bb25753048de854d9e711a23fc04
5
5
  SHA512:
6
- metadata.gz: d7c5d0cbc44557292dffcb12215ed1e474a188a1c79e47108091fff00b154d1fe549573385965c4d12deb24dab7b70cbbb650c66953d6429d2b8fe3e892e3e27
7
- data.tar.gz: c8455010c8e9456827e6776bf3bf7df237d3cb3aff2d8306ed3d1a55929729822464b2f0b86ce04edd41b2993ec7af135ca9d1e085ed26e50878bcc1d7ab7bd4
6
+ metadata.gz: 6ba8be43abde4f269d305ca5061a0e1f84913f6b68ac97d46b74a3534df8e722c481cb244f5bafa4e9b18492b60d93eb5c7ba65e946da48ac6c7b9a21ffffd5d
7
+ data.tar.gz: 55eea47aafc19ddcf0b232afcafadf1020a04972dd90bc3fd82c5265a12d166ae5eb36c59ff0dfcfcaccba83c12b685567a15536fb3ccc51cafab802166d7b39
@@ -0,0 +1,56 @@
1
+ require 'erb'
2
+
3
+ module Capistrano
4
+ module Slnky
5
+ module Helpers
6
+ # stolen from:
7
+ # https://github.com/capistrano-plugins/capistrano-unicorn-nginx/blob/e2e0dc17766ce6312a27eb5af52d521d9f6fb8ca/lib/capistrano/unicorn_nginx/helpers.rb
8
+ #
9
+ # renders the ERB template specified by template_name to string. Use the locals variable to pass locals to the
10
+ # ERB template
11
+ def template_to_s(template_name, locals = {})
12
+ config_file = "#{fetch(:templates_path)}/#{template_name}"
13
+ # if no customized file, proceed with default
14
+ unless File.exists?(config_file)
15
+ config_file = File.join(File.dirname(__FILE__), "templates/#{template_name}")
16
+ end
17
+
18
+ ERB.new(File.read(config_file), nil, '-').result(ERBNamespace.new(locals).get_binding)
19
+ end
20
+
21
+ # renders the ERB template specified by template_name to a StringIO buffer
22
+ def template(template_name, locals = {})
23
+ StringIO.new(template_to_s(template_name, locals))
24
+ end
25
+
26
+ def file_exists?(path)
27
+ test "[ -e #{path} ]"
28
+ end
29
+
30
+ def deploy_user
31
+ capture :id, '-un'
32
+ end
33
+
34
+ def sudo_upload!(from, to)
35
+ filename = File.basename(to)
36
+ to_dir = File.dirname(to)
37
+ tmp_file = "#{fetch(:tmp_dir)}/#{filename}"
38
+ upload! from, tmp_file
39
+ sudo :mv, tmp_file, to_dir
40
+ end
41
+
42
+ # Helper class to pass local variables to an ERB template
43
+ class ERBNamespace
44
+ def initialize(hash)
45
+ hash.each do |key, value|
46
+ singleton_class.send(:define_method, key) { value }
47
+ end
48
+ end
49
+
50
+ def get_binding
51
+ binding
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,16 @@
1
+ start on started networking
2
+ respawn
3
+
4
+ env SLNKY_SERVICE="<%= fetch(:application) %>"
5
+ export SLNKY_SERVICE
6
+ env SLNKY_DIR="<%= current_path %>"
7
+ export SLNKY_DIR
8
+ env SLNKY_RVM="<%= fetch(:rvm_ruby_version) %>"
9
+ export SLNKY_RVM
10
+ env SLNKY_SCRIPT="service-<%= fetch(:slnky_service) %>"
11
+ export SLNKY_SCRIPT
12
+
13
+ exec start-stop-daemon --start \
14
+ --chdir ${SLNKY_DIR} \
15
+ --make-pidfile --pidfile ${SLNKY_DIR}/tmp/pids/${SLNKY_SERVICE}.pid \
16
+ --exec /usr/local/rvm/bin/rvm -- ${SLNKY_RVM} do bundle exec ./${SLNKY_SCRIPT} production
@@ -1,3 +1,7 @@
1
+ require 'capistrano/slnky/helpers'
2
+
3
+ include Capistrano::Slnky::Helpers
4
+
1
5
  namespace :load do
2
6
  task :defaults do
3
7
  set :slnky_service, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
@@ -7,12 +11,10 @@ namespace :load do
7
11
  end
8
12
 
9
13
  namespace :slnky do
10
- desc 'upload local upstart config from upstart/init.conf'
11
- task :config do
14
+ desc 'upload upstart config'
15
+ task :upstart do
12
16
  on roles :app do
13
- service = fetch(:slnky_service)
14
- upload! "upstart/init.conf", "/tmp/#{service}.conf"
15
- sudo 'mv', "/tmp/#{service}.conf", "/etc/init/#{service}.conf"
17
+ sudo_upload! template('upstart.conf.erb'), "/etc/init/#{fetch(:slnky_service)}.conf"
16
18
  end
17
19
  end
18
20
 
@@ -28,7 +30,7 @@ end
28
30
 
29
31
  desc 'setup task'
30
32
  task :setup do
31
- invoke 'slnky:config'
33
+ invoke 'slnky:upstart'
32
34
  end
33
35
 
34
36
  namespace :deploy do
data/lib/slnky/service.rb CHANGED
@@ -7,8 +7,9 @@ require 'json'
7
7
  module Slnky
8
8
  module Service
9
9
  class Base
10
- def initialize(url)
10
+ def initialize(url, env='development')
11
11
  @server = url
12
+ @environment = env
12
13
  @name = self.class.name.split('::').last.downcase
13
14
  json = open("#{@server}/configs/#{@name}") {|f| f.read }
14
15
  @config = JSON.parse(json)
data/lib/slnky/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slnky
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slnky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Catanzarite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-04 00:00:00.000000000 Z
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,6 +140,8 @@ files:
140
140
  - Rakefile
141
141
  - bin/slnky
142
142
  - lib/capistrano/slnky.rb
143
+ - lib/capistrano/slnky/helpers.rb
144
+ - lib/capistrano/slnky/templates/upstart.conf.erb
143
145
  - lib/capistrano/tasks/slnky.rake
144
146
  - lib/slnky.rb
145
147
  - lib/slnky/cli.rb
@@ -164,10 +166,9 @@ files:
164
166
  - lib/slnky/template/service/lib/capistrano/tasks/NAME.rake.erb
165
167
  - lib/slnky/template/service/lib/slnky/service/NAME.rb.erb
166
168
  - lib/slnky/template/service/log/.keep
167
- - lib/slnky/template/service/service.erb
169
+ - lib/slnky/template/service/service-slnky-NAME.erb
168
170
  - lib/slnky/template/service/spec/slnky/service/NAME_spec.rb.erb
169
171
  - lib/slnky/template/service/spec/spec_helper.rb.erb
170
- - lib/slnky/template/service/upstart/init.conf.erb
171
172
  - lib/slnky/version.rb
172
173
  - slnky.gemspec
173
174
  homepage: https://github.com/shawncatz/slnky
@@ -1,6 +0,0 @@
1
- start on started networking
2
- respawn
3
- script
4
- cd /srv/<%= dir %>/current
5
- /usr/local/rvm/bin/rvm `cat .ruby-version`@`cat .ruby-gemset` do bundle exec ./service run
6
- end script