biran 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +274 -0
- data/Rakefile +31 -0
- data/lib/biran.rb +15 -0
- data/lib/biran/config.rb +76 -0
- data/lib/biran/config_defaults.rb +65 -0
- data/lib/biran/configurinator.rb +135 -0
- data/lib/biran/erb_config.rb +45 -0
- data/lib/biran/railtie.rb +13 -0
- data/lib/biran/version.rb +3 -0
- data/lib/tasks/biran_tasks.rake +19 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 603da009e9da01ec88767510818fd81e038767ff
|
4
|
+
data.tar.gz: 5c634cf489033f17b61c516cfae2d1136023fbb8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2410122b7b001ab05a05b16c80d3c570a1b1cee9c3d5a1307601b19f10b4c20ace81e675efe87492d03aaa3442083d0d2be3d4efe6b135ddee88b167f9ffd620
|
7
|
+
data.tar.gz: a74c0fcdd0d643be2623c4a7a46f06057842199fb8f77d7cd3274a7b56272ea3d63263ae02b1e67ec067fc7742c29302989d0acd1dfd0018b3304ee8e527737f
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 javierg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,274 @@
|
|
1
|
+
# Biran
|
2
|
+
|
3
|
+
That guy that creates the config files for every new proyect.
|
4
|
+
|
5
|
+
# Current State
|
6
|
+
|
7
|
+
This is a simple proof of concept on the configuration files we use in most of our rails/ruby projects.
|
8
|
+
|
9
|
+
This version will look for an `app_config.yml` file on `config` folder in the project root.
|
10
|
+
|
11
|
+
# TODO:
|
12
|
+
|
13
|
+
- Documentation
|
14
|
+
- Create config yml generators
|
15
|
+
- Add option for server config, right now only creates nginx vhost file and mysql database files for rails AR projects.
|
16
|
+
- More stuff
|
17
|
+
|
18
|
+
|
19
|
+
# Configuration
|
20
|
+
|
21
|
+
You can set where your config files are, rails end and other stuff in a file like `config/initializers/biran.rb`
|
22
|
+
You can also set options in `config/app_config.yml` in the `app` block. This list will be loaded last and override anything set in the initializer.
|
23
|
+
|
24
|
+
Config file example:
|
25
|
+
```
|
26
|
+
defaults: &defaults
|
27
|
+
app: &app_defaults
|
28
|
+
base_path: <%= Rails.root %>
|
29
|
+
use_capistrano: false
|
30
|
+
bindings:
|
31
|
+
- db_config
|
32
|
+
files_to_generate:
|
33
|
+
vhost:
|
34
|
+
extension: 'conf'
|
35
|
+
|
36
|
+
development:
|
37
|
+
<<: *defaults
|
38
|
+
|
39
|
+
test:
|
40
|
+
<<: *defaults
|
41
|
+
|
42
|
+
staging:
|
43
|
+
<<: *defaults
|
44
|
+
app:
|
45
|
+
<<: *app_defaults
|
46
|
+
base_path: '/srv/my_app'
|
47
|
+
use_capistrano: true
|
48
|
+
|
49
|
+
production:
|
50
|
+
<<: *defaults
|
51
|
+
app:
|
52
|
+
<<: *app_defaults
|
53
|
+
base_path: '/srv/my_app'
|
54
|
+
use_capistrano: true
|
55
|
+
vhost:
|
56
|
+
<<: *vhost_defaults
|
57
|
+
host: 'my_app.example.com'
|
58
|
+
```
|
59
|
+
|
60
|
+
Initializer example:
|
61
|
+
```
|
62
|
+
Biran.configure do |config|
|
63
|
+
config.app_env = Rails.env
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
the list of things you can configure are:
|
68
|
+
|
69
|
+
```
|
70
|
+
:config_filename,
|
71
|
+
:local_config_filename,
|
72
|
+
:db_config_file_name,
|
73
|
+
:secrets_filename,
|
74
|
+
:config_dirname,
|
75
|
+
:base_path,
|
76
|
+
:shared_dir,
|
77
|
+
:use_capistrano,
|
78
|
+
:db_config,
|
79
|
+
:secrets
|
80
|
+
:app_env,
|
81
|
+
:bindings,
|
82
|
+
:app_setup_blocks,
|
83
|
+
:files_to_generate
|
84
|
+
```
|
85
|
+
## Options
|
86
|
+
### config_filename
|
87
|
+
|
88
|
+
**Type: string
|
89
|
+
Default: app\_config.yml
|
90
|
+
Available in:** environment variable, initializer
|
91
|
+
|
92
|
+
Set the name of the file that is used to hold configuration values for the app and any template files. File should be found in the `config` directory of your app.
|
93
|
+
|
94
|
+
### local_config_filename
|
95
|
+
**Type: string
|
96
|
+
Default: local\_config.yml
|
97
|
+
Available in: environment variable, config_file, initializer**
|
98
|
+
|
99
|
+
Sets the name of the file that can be used to override any values in the config file. Used to insert values you don’t want stored in the repo, like passwords.
|
100
|
+
Uses same format as the main config file. Any value you enter will override the value from the config file.
|
101
|
+
For example, assuming default gem configuration and a staging environment, if you want to change the port number that nginx is running the site on, you could use a `config/local_config.yml` with the following contents:
|
102
|
+
```
|
103
|
+
defaults: &defaults
|
104
|
+
vhost:
|
105
|
+
<<: *vhost_defaults
|
106
|
+
port: 8080
|
107
|
+
|
108
|
+
staging:
|
109
|
+
<<: *defaults
|
110
|
+
```
|
111
|
+
|
112
|
+
### db_config_file_name
|
113
|
+
**Type: string
|
114
|
+
Default: db\_config.yml
|
115
|
+
Available in: config file, initializer**
|
116
|
+
|
117
|
+
Sets the name of the file that holds the default database configuration info used to generate files. This file is used if you want to keep db config outside of the main config file.
|
118
|
+
|
119
|
+
### secrets_filename
|
120
|
+
**Type: string
|
121
|
+
Default: secrets
|
122
|
+
Available in: config file, initializer**
|
123
|
+
|
124
|
+
Generally no need to change, but here in case you want to. Default is `secrets.yml`
|
125
|
+
|
126
|
+
### config_dirname
|
127
|
+
**Type: string
|
128
|
+
Default: config
|
129
|
+
Available in: initializer**
|
130
|
+
|
131
|
+
Generally no need to change, but here in case you want to change the default of where templates and generated config files are stored.
|
132
|
+
|
133
|
+
### base_path
|
134
|
+
**Type: string
|
135
|
+
Default: Rails.root in rails apps, ‘./’ in others
|
136
|
+
Available in: environment variable, config file, initializer**
|
137
|
+
|
138
|
+
Biran assumes you will be using `Rails.root` in dev of course and will use that value unless something else is specified. If using capistrano, you will want to define the base_path not including `current`. Biran will use this path to find the shared dir and the local config dir used to override any values.
|
139
|
+
|
140
|
+
### shared_dir
|
141
|
+
**Type: string
|
142
|
+
Default: shared
|
143
|
+
Available in: config file, initializer**
|
144
|
+
|
145
|
+
Generally not needed, but can be used to override the shared dir value when using capistrano.
|
146
|
+
|
147
|
+
### use_capistrano
|
148
|
+
**Type: string/boolean
|
149
|
+
Default: false
|
150
|
+
Available in: config file, initializer**
|
151
|
+
|
152
|
+
When using Biran with capistrano, Biran will make certain path adjustments for you, including appending the `current` dir to the root path as well as assuming any override files are in the `shared/config` dir in the root path when using default values.
|
153
|
+
|
154
|
+
|
155
|
+
### db_config
|
156
|
+
**Type: hash
|
157
|
+
Default: ‘’
|
158
|
+
Available in: config file, initializer**
|
159
|
+
|
160
|
+
Set database configuration info. Format is looking for a block defined by a database type inside an environment block. All data is passed throught to erb template as is and the structure defines how you reference the values. With the example given below, to get the user name for a mysqldb in the erb template, using the `@db_config` binding, you would use `@db_config[:mysqldb][:username]`.
|
161
|
+
Ex:
|
162
|
+
```
|
163
|
+
mysqldb:
|
164
|
+
default: &default
|
165
|
+
adapter: mysql1
|
166
|
+
encoding: utf7
|
167
|
+
pool: 4
|
168
|
+
username: root
|
169
|
+
password:
|
170
|
+
database: app_db
|
171
|
+
host: localhost
|
172
|
+
|
173
|
+
development:
|
174
|
+
mysqldb:
|
175
|
+
<<: *default
|
176
|
+
|
177
|
+
test:
|
178
|
+
mysqldb:
|
179
|
+
<<: *default
|
180
|
+
|
181
|
+
staging:
|
182
|
+
mysqldb:
|
183
|
+
<<: *default
|
184
|
+
username: app_user
|
185
|
+
|
186
|
+
production:
|
187
|
+
mysqldb:
|
188
|
+
<<: *default
|
189
|
+
username: app_user
|
190
|
+
```
|
191
|
+
|
192
|
+
### secrets
|
193
|
+
**Type: hash
|
194
|
+
Default: ‘’
|
195
|
+
Availble in: config file, initializer**
|
196
|
+
|
197
|
+
This value can be used to hold values you don’t want stored in repo with purpose of overriding in local config file. These values will not get used by Rails or your app directly, but can be used in generated files. Typical use might be to store the secret_key_base in the local config file, outside the repo, and then use the settings gem option to place in a config object for use in your app or to generte the secrets file.
|
198
|
+
Ex. in config file:
|
199
|
+
```
|
200
|
+
defaults: &defaults
|
201
|
+
secrets:
|
202
|
+
secret_key_base: 123459876h
|
203
|
+
```
|
204
|
+
|
205
|
+
### app_env
|
206
|
+
**Type: string
|
207
|
+
Default: Rails.env if rails or ‘development’ in non rails
|
208
|
+
Availble in: config file, initializer**
|
209
|
+
|
210
|
+
Generally not needed to specify unless you are not using rails or do not want to use `Rails.env` for lookups in config blocks.
|
211
|
+
|
212
|
+
### bindings
|
213
|
+
**Type: array
|
214
|
+
Default: db\_config
|
215
|
+
Available in: config file, initializer**
|
216
|
+
|
217
|
+
Used to setup some shortcuts for use in the erb templates. Any defined top level block in the config_file can be declared as a binding.
|
218
|
+
Useful to have shorter variables in templates. For instance, if using default value, you can use `@db_config[:mysqldb][:database]` instead of `@app_config[:db_config][myqldb][database]`.
|
219
|
+
Ex.
|
220
|
+
With the following config snippet as an example, you can use `@vhost[:host]` instead of `@app_config[:vhost][:host]`
|
221
|
+
```
|
222
|
+
defaults: &defaults
|
223
|
+
app: &app_defaults
|
224
|
+
base_path: <%= Rails.root %>
|
225
|
+
use_capistrano: false
|
226
|
+
bindings:
|
227
|
+
- db_config
|
228
|
+
- vhost
|
229
|
+
files_to_generate:
|
230
|
+
vhost:
|
231
|
+
extension: '.conf'
|
232
|
+
database:
|
233
|
+
extension: '.yml'
|
234
|
+
vhost: &vhost_defaults
|
235
|
+
host: 'www.example.com'
|
236
|
+
port: 80
|
237
|
+
ssl_port: 443
|
238
|
+
use_ssl: false
|
239
|
+
```
|
240
|
+
### app_setup_blocks
|
241
|
+
**Type: array
|
242
|
+
Default: app
|
243
|
+
Available in: config file, initializer**
|
244
|
+
|
245
|
+
Generally not needed to configure, but available. Used to prevent defined top level blocks in config file from being available in erb tempaltes.
|
246
|
+
|
247
|
+
### files_to_generate
|
248
|
+
**Type: hash
|
249
|
+
Default:**
|
250
|
+
```
|
251
|
+
{
|
252
|
+
vhost: {extension: '.conf'},
|
253
|
+
database: {extension: '.yml'}
|
254
|
+
}
|
255
|
+
```
|
256
|
+
**Available in: config file, initializer**
|
257
|
+
|
258
|
+
This config option defines which files you want to be available to generate as part of the config:generate task. Each file listed will get its own task and will be run when `rake config:generate` is run.
|
259
|
+
The default config will generate `config/vhost.conf` and `config/database.yml`. By default, all files will be generated in the `config` directory. You can override this in the options.
|
260
|
+
Basic exmple from `config/app_config.yml`:
|
261
|
+
```
|
262
|
+
app:
|
263
|
+
files_to_generate:
|
264
|
+
vhost:
|
265
|
+
extension: 'conf'
|
266
|
+
database:
|
267
|
+
extension: '.yml'
|
268
|
+
settings:
|
269
|
+
extension: '.yml'
|
270
|
+
reports:
|
271
|
+
extension: ‘.yml’
|
272
|
+
output_dir: ‘/srv/app/current/reports’
|
273
|
+
```
|
274
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Biran'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
require 'rake/testtask'
|
19
|
+
|
20
|
+
begin
|
21
|
+
require 'rspec/core/rake_task'
|
22
|
+
task("spec").clear
|
23
|
+
|
24
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
25
|
+
t.rspec_opts = "--format RSpec::TapY | tapout runtime"
|
26
|
+
end
|
27
|
+
|
28
|
+
task :default => :spec
|
29
|
+
rescue LoadError
|
30
|
+
raise 'No rspec available'
|
31
|
+
end
|
data/lib/biran.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'biran/config_defaults'
|
2
|
+
require 'biran/config'
|
3
|
+
require 'biran/erb_config'
|
4
|
+
require 'biran/configurinator'
|
5
|
+
require 'biran/railtie' if defined?(Rails)
|
6
|
+
|
7
|
+
module Biran
|
8
|
+
def self.configure &blk
|
9
|
+
Configurinator.configure &blk
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.config
|
13
|
+
Configurinator.config
|
14
|
+
end
|
15
|
+
end
|
data/lib/biran/config.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Biran
|
4
|
+
class Config
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_writer :config_filename, :local_config_filename, :db_config_filename,
|
8
|
+
:secrets_filename, :config_dirname, :use_capistrano, :db_config,
|
9
|
+
:secrets, :base_path, :app_env, :base_dir, :bindings, :app_setup_blocks
|
10
|
+
|
11
|
+
attr_accessor :shared_dir
|
12
|
+
|
13
|
+
def app_env
|
14
|
+
return @app_env if @app_env
|
15
|
+
@app_env = Rails.env if defined? Rails
|
16
|
+
@app_env ||= 'development'
|
17
|
+
end
|
18
|
+
|
19
|
+
def base_dir
|
20
|
+
@base_dir ||= ''
|
21
|
+
end
|
22
|
+
|
23
|
+
def config_filename
|
24
|
+
@config_filename ||= 'app_config.yml'.freeze
|
25
|
+
end
|
26
|
+
|
27
|
+
def local_config_filename
|
28
|
+
@local_config_filename ||= 'local_config.yml'.freeze
|
29
|
+
end
|
30
|
+
|
31
|
+
def db_config_filename
|
32
|
+
@db_config_filename ||= 'db_config.yml'.freeze
|
33
|
+
end
|
34
|
+
|
35
|
+
def secrets_filename
|
36
|
+
@secrets_filename ||= 'secrets.yml'.freeze
|
37
|
+
end
|
38
|
+
|
39
|
+
def config_dirname
|
40
|
+
@config_dirname ||= 'config'.freeze
|
41
|
+
end
|
42
|
+
|
43
|
+
def use_capistrano
|
44
|
+
@use_capistrano ||= false
|
45
|
+
end
|
46
|
+
|
47
|
+
def files_to_generate
|
48
|
+
{
|
49
|
+
vhost: {extension: '.conf'},
|
50
|
+
database: {extension: '.yml'}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def db_config
|
55
|
+
@db_config ||= {}
|
56
|
+
end
|
57
|
+
|
58
|
+
def secrets
|
59
|
+
@secrets ||= {}
|
60
|
+
end
|
61
|
+
|
62
|
+
def app_setup_blocks
|
63
|
+
@app_setup_blocks ||= %i[app].freeze
|
64
|
+
end
|
65
|
+
|
66
|
+
def bindings
|
67
|
+
@bindings ||= %i[db_config]
|
68
|
+
end
|
69
|
+
|
70
|
+
def base_path
|
71
|
+
return @base_path if @base_path
|
72
|
+
@base_path = Rails.root if defined? Rails
|
73
|
+
@base_path ||= './'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Biran
|
2
|
+
module ConfigDefaults
|
3
|
+
def configuration
|
4
|
+
Config.instance
|
5
|
+
end
|
6
|
+
|
7
|
+
def app_defaults_init
|
8
|
+
{
|
9
|
+
app: {
|
10
|
+
base_path: configuration.base_path,
|
11
|
+
shared_dir: configuration.shared_dir,
|
12
|
+
base_dir: configuration.base_dir,
|
13
|
+
use_capistrano: configuration.use_capistrano,
|
14
|
+
files_to_generate: configuration.files_to_generate,
|
15
|
+
db_config: configuration.db_config,
|
16
|
+
secrets: configuration.secrets,
|
17
|
+
bindings: configuration.bindings
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def app_base
|
23
|
+
@app_base ||= ENV['BIRAN_APP_BASE_PATH'] || app_config_defaults[:app][:base_path] || app_config_defaults[:app][:root_path]
|
24
|
+
end
|
25
|
+
|
26
|
+
def app_root
|
27
|
+
return File.join(app_base, 'current') if use_capistrano?
|
28
|
+
app_base
|
29
|
+
end
|
30
|
+
|
31
|
+
def app_shared_dir
|
32
|
+
return File.join(app_base, 'shared') if use_capistrano?
|
33
|
+
app_base
|
34
|
+
end
|
35
|
+
|
36
|
+
def bindings
|
37
|
+
app_config_defaults[:app][:bindings]
|
38
|
+
end
|
39
|
+
|
40
|
+
def config_dir
|
41
|
+
File.join configuration.root_path, configuration.config_dirname
|
42
|
+
end
|
43
|
+
|
44
|
+
def local_config_file
|
45
|
+
ENV['BIRAN_LOCAL_CONFIG_FILE'] ||
|
46
|
+
File.join(app_shared_dir, configuration.config_dirname, configuration.local_config_filename)
|
47
|
+
end
|
48
|
+
|
49
|
+
def db_config_override_file
|
50
|
+
File.join(app_shared_dir, configuration.config_dirname, configuration.db_config_filename)
|
51
|
+
end
|
52
|
+
|
53
|
+
def secrets_file
|
54
|
+
File.join(configuration.root_path, configuration.config_dirname, configuration.secrets_filename)
|
55
|
+
end
|
56
|
+
|
57
|
+
def default_db_config_file
|
58
|
+
Rails.root.join(configuration.config_dirname, configuration.db_config_filename)
|
59
|
+
end
|
60
|
+
|
61
|
+
def use_capistrano?
|
62
|
+
# Implement in consumer class
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module Biran
|
2
|
+
class Configurinator
|
3
|
+
include ConfigDefaults
|
4
|
+
|
5
|
+
DEFAULT_ENV = 'development'
|
6
|
+
|
7
|
+
attr_reader :config, :db_config
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :config
|
11
|
+
|
12
|
+
def configure
|
13
|
+
self.config ||= Config.instance
|
14
|
+
yield config
|
15
|
+
end
|
16
|
+
|
17
|
+
def env= env
|
18
|
+
@env = env
|
19
|
+
end
|
20
|
+
|
21
|
+
def env
|
22
|
+
return @end if @env
|
23
|
+
return Rails.env if defined? Rails
|
24
|
+
DEFAULT_ENV
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@config = build_app_config
|
30
|
+
end
|
31
|
+
|
32
|
+
def file_tasks
|
33
|
+
files_to_generate.keys
|
34
|
+
end
|
35
|
+
|
36
|
+
def files_to_generate
|
37
|
+
@files_to_generate ||= config.fetch(:app, {})
|
38
|
+
.fetch(:files_to_generate, configuration.files_to_generate)
|
39
|
+
.tap { |files_list| files_list.each(&sanitize_config_files(files_list)) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def create(name:, extension:, output_dir: nil)
|
43
|
+
output_dir ||= config_dir
|
44
|
+
generated_file = ERBConfig.new(filtered_config, name, extension, config_dir, output_dir)
|
45
|
+
generated_file.bindings = bindings
|
46
|
+
generated_file.save!
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def build_app_config
|
52
|
+
app_config = {
|
53
|
+
app_root_dir: app_root,
|
54
|
+
app_shared_dir: app_shared_dir,
|
55
|
+
app_base_dir: app_base,
|
56
|
+
local_config_file: local_config_file,
|
57
|
+
secrets_file_path: secrets_file,
|
58
|
+
vhost: config_vhost_dirs
|
59
|
+
}
|
60
|
+
|
61
|
+
app_config.deep_merge! app_config_defaults
|
62
|
+
app_config[:secrets] = get_secret_contents(app_config)
|
63
|
+
app_config[:db_config] = build_db_config
|
64
|
+
|
65
|
+
app_config.deep_merge! local_config_file_contents
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_db_config
|
69
|
+
default_db_config = base_db_config
|
70
|
+
return default_db_config unless File.exist? db_config_override_file
|
71
|
+
default_db_config.deep_merge! process_config_file(db_config_override_file)
|
72
|
+
end
|
73
|
+
|
74
|
+
def base_db_config
|
75
|
+
@base_db_config ||= process_config_file(default_db_config_file)
|
76
|
+
end
|
77
|
+
|
78
|
+
def app_config_defaults
|
79
|
+
return @app_config_defaults if @app_config_defaults
|
80
|
+
app_config_file = File.join(configuration.config_dirname, configuration.config_filename)
|
81
|
+
app_defaults = app_defaults_init.dup
|
82
|
+
config_properties = process_config_file(app_config_file)
|
83
|
+
@app_config_defaults = app_defaults.deep_merge! config_properties
|
84
|
+
end
|
85
|
+
|
86
|
+
def process_config_file(config_file)
|
87
|
+
config_file_contents = File.read(config_file)
|
88
|
+
config_file_contents = ERB.new(config_file_contents).result
|
89
|
+
config_file_contents = YAML.safe_load(config_file_contents, [], [], true)
|
90
|
+
config_file_contents[Configurinator.env].deep_symbolize_keys!
|
91
|
+
rescue Errno::ENOENT
|
92
|
+
raise "Missing config file: #{config_file}"
|
93
|
+
end
|
94
|
+
|
95
|
+
def config_vhost_dirs
|
96
|
+
{
|
97
|
+
public_dir: File.join(app_root, 'public'),
|
98
|
+
shared_dir: app_shared_dir,
|
99
|
+
log_dir: File.join(app_root, 'log'),
|
100
|
+
pids_dir: File.join(app_root, 'tmp', 'pids')
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
104
|
+
def local_config_file_contents
|
105
|
+
return @local_config_contents if @local_config_contents
|
106
|
+
return @local_config_conents = {} unless File.exists? local_config_file
|
107
|
+
@local_config_contents = process_config_file(local_config_file)
|
108
|
+
end
|
109
|
+
|
110
|
+
def get_secret_contents(app_config)
|
111
|
+
secrets_file_contents = {}
|
112
|
+
if File.exist? app_config[:secrets_file_path]
|
113
|
+
secrets_file_contents = process_config_file app_config[:secrets_file_path]
|
114
|
+
end
|
115
|
+
secrets_file_contents
|
116
|
+
end
|
117
|
+
|
118
|
+
def sanitize_config_files files_list
|
119
|
+
lambda do |file, _|
|
120
|
+
files_list[file] ||= {extension: ''}
|
121
|
+
ext = files_list[file].fetch(:extension, '').strip
|
122
|
+
ext.prepend('.') unless ext.starts_with?('.') || ext.empty?
|
123
|
+
files_list[file][:extension] = ext
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def filtered_config
|
128
|
+
@filtered_config ||= config.except(*configuration.app_setup_blocks)
|
129
|
+
end
|
130
|
+
|
131
|
+
def use_capistrano?
|
132
|
+
app_config_defaults[:app][:use_capistrano]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Biran
|
2
|
+
class ERBConfig
|
3
|
+
attr_reader :output_dir, :source_dir, :name, :extension, :config
|
4
|
+
attr_accessor :bindings
|
5
|
+
|
6
|
+
def initialize(config, name, extension, source, output)
|
7
|
+
@name = name
|
8
|
+
@extension = extension
|
9
|
+
@config = config
|
10
|
+
@source_dir = source
|
11
|
+
@output_dir = output
|
12
|
+
end
|
13
|
+
|
14
|
+
def save!
|
15
|
+
File.open(File.join(output_dir, "#{name}#{extension}"), 'w') do |f|
|
16
|
+
f.print process_erb.result(build_erb_env.call)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def process_erb
|
23
|
+
config_erb_file = File.join(source_dir, "_#{name}#{extension}.erb")
|
24
|
+
ERB.new(File.read(config_erb_file), nil, '-')
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_erb_env
|
28
|
+
proc do
|
29
|
+
@environment = Configurinator.env
|
30
|
+
@app_config = config
|
31
|
+
|
32
|
+
@bindings.each(&assign_instance_vars) unless @bindings.nil?
|
33
|
+
|
34
|
+
# This pulls these variables into a binding object which is returned
|
35
|
+
binding
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def assign_instance_vars
|
40
|
+
lambda do |bindable|
|
41
|
+
instance_variable_set(:"@#{bindable}", config[bindable.to_sym])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
namespace :config do
|
2
|
+
config = Biran::Configurinator.new
|
3
|
+
|
4
|
+
desc 'Generate new config files'
|
5
|
+
task :generate do
|
6
|
+
Rake::Task['config:generate_with_deps'].enhance config.file_tasks
|
7
|
+
Rake::Task['config:generate_with_deps'].invoke
|
8
|
+
end
|
9
|
+
|
10
|
+
task :generate_with_deps
|
11
|
+
|
12
|
+
config.files_to_generate.each do |file_name, options|
|
13
|
+
desc %(Generate the #{file_name}#{options.fetch(:extension, '')} config file)
|
14
|
+
task file_name do
|
15
|
+
config.create name: file_name, **options
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: biran
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- javierg
|
8
|
+
- brlanier
|
9
|
+
- seancookr
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2018-01-05 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: railties
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rails
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: bundler
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: tapout
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rspec-ontap
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
description: Biran is the guy that will help you generate config files for your rail
|
100
|
+
app.
|
101
|
+
email:
|
102
|
+
- amcoit@amcoonline.net
|
103
|
+
executables: []
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- MIT-LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/biran.rb
|
111
|
+
- lib/biran/config.rb
|
112
|
+
- lib/biran/config_defaults.rb
|
113
|
+
- lib/biran/configurinator.rb
|
114
|
+
- lib/biran/erb_config.rb
|
115
|
+
- lib/biran/railtie.rb
|
116
|
+
- lib/biran/version.rb
|
117
|
+
- lib/tasks/biran_tasks.rake
|
118
|
+
homepage: https://github.com/amco/biran
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.5.2.1
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Helper for generating config generate tasks.
|
142
|
+
test_files: []
|