openbox 0.1.0 → 0.4.0

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: 21387e3425ced629a43bb32997f2c5f8f9cd10647ce9fc75c6353afa53d2c465
4
- data.tar.gz: 565964314f2846373e9e94dcf4bacf096cb0918f42dcf195993fb2b4b5492932
3
+ metadata.gz: c3b2286d2b3b83ce60a50ead93f7f3b293612cd7a9386f21309b2078467acf3e
4
+ data.tar.gz: e1b3b12fe3c36503c9cfe1c72ac38163b1c7850eeda7e4395adf79c665abc19e
5
5
  SHA512:
6
- metadata.gz: c4214b43a54cab99c7331f92082c9716cd2f706081de4513ae57887b3e2fc05478ffa0eb80c92c3365b8710a2ac91a8daa9ae294ca423a6385ae1b9330a7b8c5
7
- data.tar.gz: 306cf0aa7af340df144ed52e9bd85cfe55276397307d54ce77190e7c33aafd2bdcadc3dd03f94813cb5cfd51c908d93dfc0d46dcb90e15cbb91ea78c2a481fa8
6
+ metadata.gz: 741418382ee5a71631d3ff8303ea421091527338f72b6a42cfc441c94acdad51b7ede680b44515724bacd3c715e8878e339ed84b80b16186f14750c2c4f3edb9
7
+ data.tar.gz: ba0bfebc3ed03a62a4321e389202992f7bf988cf00a3a99d6651569fedd46d1496839a35d037f7815e5b336c5ca2af54ae5e60cdd46544b2fdb87d28a128d381
data/.rubocop.yml CHANGED
@@ -12,3 +12,7 @@
12
12
  AllCops:
13
13
  TargetRubyVersion: 2.5
14
14
  NewCops: enable
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - spec/**/*_spec.rb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openbox (0.1.0)
4
+ openbox (0.4.0)
5
5
  thor (~> 1.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Openbox
2
2
 
3
+ ![main branch](https://github.com/elct9620/openbox/actions/workflows/main.yml/badge.svg?branch=main)
4
+
3
5
  The zero-configuration Ruby container entry-point.
4
6
 
5
7
  ## Installation
@@ -29,12 +31,63 @@ ENTRYPOINT ["bin/openbox"]
29
31
  CMD ["server"]
30
32
  ```
31
33
 
34
+ ### Commands
35
+
36
+ The commands are pre-defined for the Rack and Rails applications.
37
+
38
+ | Name | Enabled Condition | Description |
39
+ |-----------|-------------------|--------------------------|
40
+ | `server` | `rails` or `rack` | Start application server |
41
+ | `rake` | `rails` or `rake` | Run rake tasks |
42
+ | `console` | `rails` | Start rails console |
43
+ | `migrate` | `rails` | Run database migration |
44
+ | `seed` | `rails` | Run database seed |
45
+ | `sidekiq` | `sidekiq` | Run sidekiq server |
46
+
47
+ ### Environments
48
+
49
+ | Name | Description |
50
+ |------------------|--------------------------------------------------------------------------------------|
51
+ | `AUTO_MIGRATION` | When present, the `migrate` will run before `server` started |
52
+ | `DATABASE_URL` | When `pg` or `mysql2` gem present, Openbox will use it to ensure database connection |
53
+
54
+ ### Customize Commands
55
+
56
+ When `openbox` execute, the `lib/openbox/commands/*/**.rb` will be scanned and require before started.
57
+ We can register new command by adding files to `lib/openbox/commands` directory.
58
+
59
+ ```ruby
60
+ # lib/openbox/commands/daemon.rb
61
+
62
+ class Daemon < Openbox::Command
63
+ def execute
64
+ exec('bundle exec my-daemon')
65
+ end
66
+ end
67
+
68
+ Openbox::Entrypoint.register Daemon, :daemon, :daemon, 'Run a daemon'
69
+ ```
70
+
71
+ > The Rails are not loaded to speed up bootstrap, if you need Rails please load by yourself.
72
+
32
73
  ## Roadmap
33
74
 
34
75
  * [ ] `config/openbox.rb` config
35
- * [ ] Customize command
36
- * [ ] Rake Task support
37
- * [ ] Rails capability
76
+ * [x] Customize command
77
+ * [x] Database connection check
78
+ * [x] PostgreSQL support
79
+ * [x] MySQL support
80
+ * [x] Run Web Server
81
+ * [x] `rails server`
82
+ * [x] `rackup -o 0.0.0.0`
83
+ * [x] Rake Task support
84
+ * [x] Sidekiq support
85
+ * [x] Rails capability
86
+ * [x] `openbox console` to `rails console`
87
+ * [x] `openbox migrate` to `rails db:migrate`
88
+ * [x] `openbox seed` to `rails db:seed`
89
+ * [x] Use `AUTO_MIGRATION` to run migration before server started
90
+
38
91
 
39
92
  ## Development
40
93
 
data/exe/openbox CHANGED
@@ -4,4 +4,14 @@
4
4
 
5
5
  require 'openbox'
6
6
 
7
- Openbox::Command.start(ARGV)
7
+ CUSTOMIZE_COMMAND_ROOT = if defined?(Bundler)
8
+ Bundler.root.join('lib/openbox/commands')
9
+ else
10
+ Pathname.new(Dir.pwd).join('lib/openbox/commands')
11
+ end
12
+
13
+ CUSTOMIZE_COMMAND_ROOT.glob('**/*.rb') do |command|
14
+ require command
15
+ end
16
+
17
+ Openbox::Entrypoint.start(ARGV)
@@ -1,24 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'thor'
4
- require 'openbox/runtime'
5
4
 
6
5
  module Openbox
7
- # The Container Entrypoint
6
+ # The base command of openbox
8
7
  #
9
8
  # @since 0.1.0
10
- class Command < Thor
9
+ class Command < Thor::Group
10
+ # Execute command
11
+ #
11
12
  # @since 0.1.0
12
- desc 'server', 'Start Application Server'
13
- def server
14
- Openbox.database.ensure_connection!
15
- return exec('bundle exec rails server') if Openbox.runtime.rails?
16
-
17
- exec('bundle exec rackup -o 0.0.0.0')
18
- end
19
-
20
- def self.exit_on_failure?
21
- true
13
+ def execute
14
+ raise NotImplementedError
22
15
  end
23
16
  end
24
17
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openbox
4
+ # :nodoc:
5
+ module Commands
6
+ # The Console Command
7
+ #
8
+ # @since 0.1.0
9
+ class Console < Openbox::Command
10
+ # Run rails console
11
+ #
12
+ # @since 0.1.0
13
+ def execute
14
+ Openbox.database.ensure_connection!
15
+ exec('bundle exec rails console')
16
+ end
17
+ end
18
+
19
+ Openbox::Entrypoint.register(Console, 'console', 'console', 'Run rails console') if Openbox.runtime.has?('rails')
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openbox
4
+ # :nodoc:
5
+ module Commands
6
+ # The Migrate Command
7
+ #
8
+ # @since 0.1.0
9
+ class Migrate < Openbox::Command
10
+ # Run rails migrate
11
+ #
12
+ # @since 0.1.0
13
+ def execute
14
+ Openbox.database.ensure_connection!
15
+ system('bundle exec rails db:migrate')
16
+ end
17
+ end
18
+
19
+ Openbox::Entrypoint.register(Migrate, 'migrate', 'migrate', 'Run rails migrate') if Openbox.runtime.has?('rails')
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openbox
4
+ # :nodoc:
5
+ module Commands
6
+ # The Rake Command
7
+ #
8
+ # @since 0.1.0
9
+ class Rake < Openbox::Command
10
+ # Run rake task with database connection check
11
+ #
12
+ # @since 0.1.0
13
+ def execute
14
+ Openbox.database.ensure_connection!
15
+ exec("bundle exec rake #{args.join(' ')}")
16
+ end
17
+ end
18
+
19
+ Openbox::Entrypoint.register(Rake, 'rake', 'rake', 'Run rake task') if Openbox.runtime.has?('rails', 'rake')
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openbox
4
+ # :nodoc:
5
+ module Commands
6
+ # The Seed Command
7
+ #
8
+ # @since 0.1.0
9
+ class Seed < Openbox::Command
10
+ # Run rails seed
11
+ #
12
+ # @since 0.1.0
13
+ def execute
14
+ Openbox.database.ensure_connection!
15
+ system('bundle exec rails db:seed')
16
+ end
17
+ end
18
+
19
+ Openbox::Entrypoint.register(Seed, 'seed', 'seed', 'Run rails seed') if Openbox.runtime.has?('rails')
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openbox
4
+ # :nodoc:
5
+ module Commands
6
+ # The Server Command
7
+ #
8
+ # @since 0.1.0
9
+ class Server < Openbox::Command
10
+ # Run Application Server
11
+ #
12
+ # @since 0.1.0
13
+ def execute
14
+ Openbox.database.ensure_connection!
15
+ invoke Migrate unless ENV['AUTO_MIGRATION'].nil?
16
+ return exec('bundle exec rails server -b 0.0.0.0') if Openbox.runtime.rails?
17
+
18
+ exec('bundle exec rackup -o 0.0.0.0')
19
+ end
20
+ end
21
+
22
+ if Openbox.runtime.has?('rails', 'rack')
23
+ Openbox::Entrypoint.register(Server, 'server', 'server', 'Start application server')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openbox
4
+ # :nodoc:
5
+ module Commands
6
+ # The Sidekiq Command
7
+ #
8
+ # @since 0.1.0
9
+ class Sidekiq < Openbox::Command
10
+ # Run sidekiq
11
+ #
12
+ # @since 0.1.0
13
+ def execute
14
+ Openbox.database.ensure_connection!
15
+ exec('bundle exec sidekiq')
16
+ end
17
+ end
18
+
19
+ Openbox::Entrypoint.register(Sidekiq, 'sidekiq', 'sidekiq', 'Run rails sidekiq') if Openbox.runtime.has?('sidekiq')
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require 'openbox/runtime'
5
+ require 'openbox/command'
6
+
7
+ module Openbox
8
+ # The Container Entrypoint
9
+ #
10
+ # @since 0.1.0
11
+ class Entrypoint < Thor
12
+ # :nodoc:
13
+ def self.exit_on_failure?
14
+ true
15
+ end
16
+
17
+ require 'openbox/commands/server'
18
+ require 'openbox/commands/rake'
19
+ require 'openbox/commands/migrate'
20
+ require 'openbox/commands/seed'
21
+ require 'openbox/commands/console'
22
+ require 'openbox/commands/sidekiq'
23
+ end
24
+ end
@@ -7,6 +7,13 @@ module Openbox
7
7
  #
8
8
  # @since 0.1.0
9
9
  class Runtime
10
+ # @param dependencies [Array<Bundler::Dependency>]
11
+ #
12
+ # @since 0.1.0
13
+ def initialize(dependencies = [])
14
+ @dependencies = dependencies
15
+ end
16
+
10
17
  # Check for Rails environment
11
18
  #
12
19
  # @return [TrueClass|FalseClass]
@@ -22,9 +29,7 @@ module Openbox
22
29
  #
23
30
  # @since 0.1.0
24
31
  def select(*names)
25
- Bundler
26
- .definition
27
- .current_dependencies
32
+ @dependencies
28
33
  .select { |dep| names.include?(dep.name) && (dep.groups & groups).any? }
29
34
  end
30
35
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Openbox
4
- VERSION = '0.1.0'
4
+ VERSION = '0.4.0'
5
5
  end
data/lib/openbox.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  require_relative 'openbox/version'
4
4
  require_relative 'openbox/database'
5
5
  require_relative 'openbox/runtime'
6
- require_relative 'openbox/command'
7
6
 
8
7
  # The tool to build Ruby container easier
9
8
  #
@@ -20,7 +19,12 @@ module Openbox
20
19
  return @runtime if @runtime
21
20
 
22
21
  LOCK.synchronize do
23
- @runtime ||= Runtime.new
22
+ dependencies = if defined?(Bundler)
23
+ Bundler.definition.current_dependencies
24
+ else
25
+ []
26
+ end
27
+ @runtime ||= Runtime.new(dependencies)
24
28
  end
25
29
  end
26
30
 
@@ -34,4 +38,6 @@ module Openbox
34
38
  @database ||= Database.new
35
39
  end
36
40
  end
41
+
42
+ require_relative 'openbox/entrypoint'
37
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-01 00:00:00.000000000 Z
11
+ date: 2022-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -46,7 +46,14 @@ files:
46
46
  - exe/openbox
47
47
  - lib/openbox.rb
48
48
  - lib/openbox/command.rb
49
+ - lib/openbox/commands/console.rb
50
+ - lib/openbox/commands/migrate.rb
51
+ - lib/openbox/commands/rake.rb
52
+ - lib/openbox/commands/seed.rb
53
+ - lib/openbox/commands/server.rb
54
+ - lib/openbox/commands/sidekiq.rb
49
55
  - lib/openbox/database.rb
56
+ - lib/openbox/entrypoint.rb
50
57
  - lib/openbox/runtime.rb
51
58
  - lib/openbox/version.rb
52
59
  - openbox.gemspec