openbox 0.3.0 → 0.5.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: 9b7208531d38a833b1fa220eb2efe9f50b12f2e45287e2556db3f85fbb8028b1
4
- data.tar.gz: 8a2f7c98ae40aa2367627d91d1065018dd02af76e7befbe0881fac9f0a131ddc
3
+ metadata.gz: 2c0d83b1900aaf94e908bf6cdca2c74226a6e3634a43e22799b98ec6e7d6b0bc
4
+ data.tar.gz: 5061979673b6b027be1d4926dec24dcd54d0bf1d52b6d862641bd2579f8154bf
5
5
  SHA512:
6
- metadata.gz: d32b9ce88a4f3f1b6047291e91274561c17fed72be4f20e8fae01ce0cc7015b0ea77ddd528b877e48c0a99a3b87e3ecf71f155983ff41e080ebf015832e2bce5
7
- data.tar.gz: c1431901ca2163695024dba1bf7f6e2e7ea310e07c422b4ab8e5a93873bbb7e75431d46cf665d1cbf49fa4004c0c87f3a4f0d6308a8bcea6b54d1619209c566c
6
+ metadata.gz: '09da76c126d5e6b30d27153db1f8ac4415a134b7c427485dd8f740d1aacd186d6311a9bde8a26dabba17ba4a048cf3837367baa2bf0eec6e23094ffd3d986a9a'
7
+ data.tar.gz: 1f2389789c16745950eadb85a69406a95b24a71cd4a54e13568e62c20ab97c24d7b743bdac03dec7e6036681cfc4f802f3f92fee151cf91b1e6f3a259d0e271b
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openbox (0.3.0)
4
+ openbox (0.5.0)
5
+ dotenv
5
6
  thor (~> 1.0)
6
7
 
7
8
  GEM
@@ -14,6 +15,7 @@ GEM
14
15
  childprocess (4.1.0)
15
16
  diff-lcs (1.4.4)
16
17
  docile (1.4.0)
18
+ dotenv (2.7.6)
17
19
  iniparse (1.5.0)
18
20
  overcommit (0.58.0)
19
21
  childprocess (>= 0.6.3, < 5)
data/README.md CHANGED
@@ -44,17 +44,56 @@ The commands are pre-defined for the Rack and Rails applications.
44
44
  | `seed` | `rails` | Run database seed |
45
45
  | `sidekiq` | `sidekiq` | Run sidekiq server |
46
46
 
47
+ #### Customize Commands
48
+
49
+ When `openbox` execute, the `lib/openbox/commands/*/**.rb` will be scanned and require before started.
50
+ We can register new command by adding files to `lib/openbox/commands` directory.
51
+
52
+ ```ruby
53
+ # lib/openbox/commands/daemon.rb
54
+
55
+ class Daemon < Openbox::Command
56
+ def execute
57
+ exec('bundle exec my-daemon')
58
+ end
59
+ end
60
+
61
+ Openbox::Entrypoint.register Daemon, :daemon, :daemon, 'Run a daemon'
62
+ ```
63
+
64
+ > The Rails are not loaded to speed up bootstrap, if you need Rails please load by yourself.
65
+
47
66
  ### Environments
48
67
 
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 |
68
+ | Name | Example | Description |
69
+ |------------------|----------------------------------------|--------------------------------------------------------------------------------------|
70
+ | `AUTO_MIGRATION` | `yes` | When present, the `migrate` will run before `server` started |
71
+ | `DATABASE_URL` | `postgres://user:pass@postgres/dbname` | When `pg` or `mysql2` gem present, Openbox will use it to ensure database connection |
72
+ | `SWARM_SECRETS` | `app-env` | List the Docker Swarm secret names to load as environment file |
73
+
74
+ ## Environment Loader
75
+
76
+ To rotate secrets easier, we may not use Rails credentials but inject secrets via the environment variables.
77
+
78
+ Openbox provides a before hook before the command is executed and load the environments from a security source.
79
+
80
+ ### Docker Swarm
81
+
82
+ When use Docker Swarm, the secret will put into `/run/secrets` directory, you can load these files via Dotenv.
83
+
84
+ ```yaml
85
+ # Docker Swarm Stack
86
+ services:
87
+ application:
88
+ environment:
89
+ - SWARM_SECRETS=sahred-secret,applicate-secret
90
+ # ...
91
+ ```
53
92
 
54
93
  ## Roadmap
55
94
 
56
95
  * [ ] `config/openbox.rb` config
57
- * [ ] Customize command
96
+ * [x] Customize command
58
97
  * [x] Database connection check
59
98
  * [x] PostgreSQL support
60
99
  * [x] MySQL support
@@ -68,7 +107,10 @@ The commands are pre-defined for the Rack and Rails applications.
68
107
  * [x] `openbox migrate` to `rails db:migrate`
69
108
  * [x] `openbox seed` to `rails db:seed`
70
109
  * [x] Use `AUTO_MIGRATION` to run migration before server started
71
-
110
+ * [ ] Load Secrets as Environment
111
+ * [ ] AWS Secrets Manager
112
+ * [ ] Hashicorp Valut
113
+ * [ ] Docker Swarm Secrets
72
114
 
73
115
  ## Development
74
116
 
data/exe/openbox CHANGED
@@ -4,4 +4,14 @@
4
4
 
5
5
  require 'openbox'
6
6
 
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
+
7
17
  Openbox::Entrypoint.start(ARGV)
@@ -1,12 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'thor'
4
+ require 'dotenv'
4
5
 
5
6
  module Openbox
6
7
  # The base command of openbox
7
8
  #
8
9
  # @since 0.1.0
9
10
  class Command < Thor::Group
11
+ # Before execute command
12
+ #
13
+ # @since 0.5.0
14
+ def before_execute
15
+ # TODO: Add AWS KMS, Vault support
16
+ return if ENV['SWARM_SECRETS'].nil?
17
+
18
+ paths = ENV['SWARM_SECRETS'].split(',').map { |name| "/run/secrets/#{name}" }
19
+ Dotenv.load(*paths)
20
+ end
21
+
10
22
  # Execute command
11
23
  #
12
24
  # @since 0.1.0
@@ -13,7 +13,7 @@ module Openbox
13
13
  def execute
14
14
  Openbox.database.ensure_connection!
15
15
  invoke Migrate unless ENV['AUTO_MIGRATION'].nil?
16
- return exec('bundle exec rails server') if Openbox.runtime.rails?
16
+ return exec('bundle exec rails server -b 0.0.0.0') if Openbox.runtime.rails?
17
17
 
18
18
  exec('bundle exec rackup -o 0.0.0.0')
19
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Openbox
4
- VERSION = '0.3.0'
4
+ VERSION = '0.5.0'
5
5
  end
data/openbox.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ['lib']
30
30
 
31
- # Uncomment to register a new dependency of your gem
31
+ spec.add_dependency 'dotenv'
32
32
  spec.add_dependency 'thor', '~> 1.0'
33
33
 
34
34
  # For more information and examples about making a new gem, checkout our
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.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-02 00:00:00.000000000 Z
11
+ date: 2022-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: thor
15
29
  requirement: !ruby/object:Gem::Requirement