openbox 0.3.1 → 0.5.1
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 +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +48 -6
- data/exe/openbox +10 -0
- data/lib/openbox/command.rb +12 -0
- data/lib/openbox/database.rb +1 -0
- data/lib/openbox/version.rb +1 -1
- data/openbox.gemspec +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 193964bfb04deca2d74fd24bc1810d2095b09e9b279e058f4446f796c1faaa14
|
4
|
+
data.tar.gz: 6cc1a4cf09dbabf1c070ef76125a927ac52dd09a99504cc4d433252e05003f5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
* [
|
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)
|
data/lib/openbox/command.rb
CHANGED
@@ -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
|
data/lib/openbox/database.rb
CHANGED
data/lib/openbox/version.rb
CHANGED
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
|
-
|
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.
|
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:
|
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
|