oye 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bf6d345d21055ee57c371e5edbb3e0d2ae58bb171188f73734eaaf2b3cdeefb
4
- data.tar.gz: '07916a6ebf7239bda4fdf453ac9faf5b276108abd0a76a5fb2f14d32fe3f0057'
3
+ metadata.gz: db235ec5368219133e4a2c3b13de51ca4fc021a584ba625828c1584da3b8c2c1
4
+ data.tar.gz: f0336786603d0f76352ed08230b514da02ab816fc0da825f4f5c5e308f9a8e04
5
5
  SHA512:
6
- metadata.gz: b5905be5887d49815da7d694d148007d79707ba9df85a8c0a16579e6bc31231ead94436654151311132ba09a9d45a15e32e00265178ca6cab3bc631c8b77ca8d
7
- data.tar.gz: 6428d90426de619373b8ef4098ce650020db92235b1002f7f91dfb16eac7bfb5601d9c5d46f1595d85c5f14b35a1f1a3009c59f28d8d46fac8a5f4b44e5339f7
6
+ metadata.gz: e7c8c761835d0cd0398cb6c629be42843ea7266f8b641f9ecb4bbaa0de12d35bda0fa4e39bce0cdf451d694ed31981a0a16fc7d0c4e1005ed03cd934756b1750
7
+ data.tar.gz: 8883d0b11278ea7e5b8f898e887d910554b4da4c3fa46c8ee7506e64454c801cc00be98545cb4db757d43173cb48bf3a656eb30dd9a7b2dedf08515458a86aa5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oye (0.1.8)
4
+ oye (0.1.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -13,3 +13,6 @@ A continuous monitoring tool that does a few things:
13
13
  [ ] why is the trap with `FileUtils.rm_f(oye_pidfile)` not removing the PID file
14
14
  [ ] make a website for 'oye' where you provide better documentation. e.g.
15
15
  - how to set up oye.yml
16
+ [ ] create a git brach called 'oye' and pull from that one instead of 'origin'.
17
+ [ ] suport remote branches via 'ssh'. e.g. you can use `Net::SSH` as i use in '~/.ruby/req'
18
+ [ ] support 'jekyll serve' for people that dont want to use a web server for jekyll
data/lib/oye/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Oye
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
data/lib/oye.rb CHANGED
@@ -2,9 +2,9 @@ $LOAD_PATH.unshift __dir__
2
2
 
3
3
  require "oye/version"
4
4
  require 'fileutils'
5
- require 'yaml'
6
5
  require 'socket'
7
6
  require 'timeout'
7
+ require 'yaml'
8
8
 
9
9
  module Oye
10
10
  class Error < StandardError; end
@@ -100,6 +100,7 @@ module Oye
100
100
  trap(signal) do
101
101
  stop_oye
102
102
  FileUtils.rm_f(oye_pidfile)
103
+ log(oye_pidfile, status: :info, message: "Stopped oye")
103
104
  exit
104
105
  end
105
106
  end
@@ -112,25 +113,16 @@ module Oye
112
113
 
113
114
  pid = fork do
114
115
  begin
115
- # initialize apps if they are not running
116
- # TODO i dont like this loop
117
116
  @repos.values.flatten.each do |app|
118
117
  app['clones'].each do |clone|
119
-
120
118
  if !File.exists?(clone)
121
119
  log(clone, status: :warn, message: "Could not find repo")
122
120
  next
123
- elsif !File.exists?(app_pid_dir(clone))
124
- log(clone, status: :warn, message: "Could not find pids directory")
125
- next
126
- elsif File.exists?(app_pid_file(clone))
127
- # if pid fle exists, the app should be running and there's no need to be initialize it
128
- next
129
121
  end
130
122
 
131
- initialize_clone(clone)
123
+ build_app(clone)
132
124
 
133
- rescue Errno::ESRCH
125
+ serve_app(clone)
134
126
  end
135
127
  end
136
128
 
@@ -150,9 +142,10 @@ module Oye
150
142
 
151
143
  unless @repos[origin]['stat'] == File.stat(origin).ctime
152
144
  @repos[origin]['stat'] = File.stat(origin).ctime
153
- stop_clone(clone) if File.exists?(app_pid_file(clone))
154
- update_clone(clone)
155
- initialize_clone(clone)
145
+ stop_app(clone) if File.exists?(app_pid_file(clone))
146
+ update_app(clone)
147
+ build_app(clone)
148
+ serve_app(clone)
156
149
  end
157
150
  end
158
151
  end
@@ -181,31 +174,43 @@ module Oye
181
174
  end
182
175
  end
183
176
 
184
- def initialize_clone(dir)
177
+ def build_app(dir)
185
178
  Dir.chdir(dir) do
186
179
  %x(bundle)
187
180
 
188
- %x(RAILS_ENV=#{@environment} rails db:migrate)
181
+ if rails_app?(dir)
182
+ %x(RAILS_ENV=#{@environment} rails db:migrate)
189
183
 
190
- if @environment == 'production'
191
- %x(RAILS_ENV=production rails assets:{clean,precompile})
184
+ if @environment == 'production'
185
+ %x(RAILS_ENV=production rails assets:{clean,precompile})
186
+ end
187
+ elsif jekyll_app?(dir)
188
+ %x{jekyll build}
192
189
  end
193
190
  end
194
191
 
195
- unicorn_options = @unicorn_default_options << " -c #{unicorn_file(dir)}"
192
+ log(dir, status: :info, message: "Built app")
193
+ rescue => e
194
+ log(dir, status: :warn, message: "#{__method__.to_s} (#{e.message})")
195
+ end
196
196
 
197
- %x{unicorn_rails #{unicorn_options}}
197
+ def serve_app(dir)
198
+ if rails_app?(dir)
199
+ unicorn_options = @unicorn_default_options << " -c #{unicorn_file(dir)}"
198
200
 
199
- log(dir, status: :info, message: "Started app server")
201
+ %x{unicorn_rails #{unicorn_options}}
202
+
203
+ log(dir, status: :info, message: "Started app")
204
+ end
200
205
  rescue => e
201
206
  log(dir, status: :warn, message: "#{__method__.to_s} (#{e.message})")
202
207
  end
203
208
 
204
- def stop_clone(dir)
209
+ def stop_app(dir)
205
210
  Process.kill 'TERM', app_pid(dir)
206
211
  end
207
212
 
208
- def update_clone(dir)
213
+ def update_app(dir)
209
214
  system("git -C #{dir} pull", [:out, :err] => File::NULL)
210
215
 
211
216
  log(dir, status: :info, message: "Pulled from origin")
@@ -273,6 +278,21 @@ module Oye
273
278
 
274
279
  private
275
280
 
281
+ # rails_app?, jekyll_app?
282
+ %w(rails jekyll).each do |app_type|
283
+ define_method("#{app_type}_app?") do |dir|
284
+ if File.exist?(gemfile(dir)) && File.read(gemfile(dir)).match?(/^\s*#{app_type}\b/)
285
+ true
286
+ else
287
+ false
288
+ end
289
+ end
290
+ end
291
+
292
+ def gemfile(dir)
293
+ File.join(dir, "Gemfile.lock")
294
+ end
295
+
276
296
  def port_open?(port)
277
297
  begin
278
298
  Timeout::timeout(1) do
data/oye.gemspec CHANGED
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "ronn", "~> 0.7"
29
29
  spec.add_development_dependency "ruby-prof", ">= 0"
30
30
 
31
- #spec.add_runtime_dependency "SOME_GEM", "~> VERSION"
31
+ #spec.add_runtime_dependency "bundler", "~> 2.1.2"
32
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oye
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergioro
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-22 00:00:00.000000000 Z
11
+ date: 2020-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips