openbox 0.3.1 → 0.5.1

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: 2f762f3449027a69d3c8767f0a27a9c667b0acc9f0bfe7b155e722d5233e75d9
4
- data.tar.gz: d8b5d859d5064a79c4a9d42f7caa684ae6545b651a1e905fff4cdf162a16459c
3
+ metadata.gz: 193964bfb04deca2d74fd24bc1810d2095b09e9b279e058f4446f796c1faaa14
4
+ data.tar.gz: 6cc1a4cf09dbabf1c070ef76125a927ac52dd09a99504cc4d433252e05003f5e
5
5
  SHA512:
6
- metadata.gz: df324b78ad61005016eb683c4f8f39db97ca6f7bcc46257c955addda99694f6af98448055ebc8a7f4816fedcb2d827df3c5ceee00c6e803b0c2f602f9adb51ee
7
- data.tar.gz: 1ee33165c70fa5a7aeed31247813636597230042b26473292b862ff9e93eba6e8be060c142dada10cf920831db20f83fdeae83cc1dc8eba87c6eead7033a96a0
6
+ metadata.gz: 285293c86ef04c7580ca3287ab26ae08110ec3e8221f271ca2b85576101516dea1907addb128711853b3a56058b4443aed777f1214d8597e01d52ecf2c3cee07
7
+ data.tar.gz: 03a9ad693a7a10f9e095672c65b8c5bdf3d0a2e407028d14aa2878e6358e975605b3e9354ad193ac97e24a00adedc27d124603a6a3f4328d0ac70ad6af159f33
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openbox (0.3.1)
4
+ openbox (0.5.1)
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
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'timeout'
4
+ require 'uri'
4
5
 
5
6
  module Openbox
6
7
  # The database helper
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Openbox
4
- VERSION = '0.3.1'
4
+ VERSION = '0.5.1'
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.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-18 00:00:00.000000000 Z
11
+ date: 2022-04-07 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