-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#321 #314 #302 should implement project specific config support feature #326
Conversation
@phuonglm please add config for https://github.com/acme101 because it's having the latest best practices. make sure the spec specified here should be implemented #315 I'd like to see unit tests to reflect the spec and use cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please see my comments to update.
I can only review when unit tests are provided to reflect all types of use cases and specification. @phuonglm please update asap. |
I'd like to see how this works with many projects at https://github.com/teracyhq organization |
23c46cc
to
7e27157
Compare
7e27157
to
d95d38e
Compare
@hoale please check new update with config
with related repository |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phuonglm please check my comments.
Vagrantfile
Outdated
@@ -12,14 +14,36 @@ override_hash = nil | |||
# Check and override if exist any match JSON object from vagrant_config_override.json | |||
if File.exist? (File.dirname(__FILE__) + '/vagrant_config_override.json') | |||
override_file = File.read(File.dirname(__FILE__) + '/vagrant_config_override.json') | |||
|
|||
parsing_file = File.dirname(__FILE__) + '/vagrant_config_override.json' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why we need this var here? move into the "begin" block instead? and why use that initial value? I don't see the relevance of the initial value.
Vagrantfile
Outdated
if data_hash.key?('config_paths') | ||
data_hash['config_paths'].each do |default_config_file_path, value| | ||
overide_config_file_path = default_config_file_path.gsub(/default\.json$/, "overide.json") | ||
if File.exist? (default_config_file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't add a white space after ?, please fix all this style issue throughout this file.
Vagrantfile
Outdated
options[:bridge] = vm_network['bridge'] unless vm_network['bridge'].nil? or vm_network['bridge'].empty? | ||
bridge_interface = "" | ||
bridge_interface = vm_network['bridge'] unless vm_network['bridge'].nil? or vm_network['bridge'].empty? | ||
bridge_interface = get_default_nic() if bridge_interface.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not related to this issue, move to another branch instead.
Don't ever ever ever ever combine code from different issues into one branch, on PR, I hate that. Split please.
lib/os.rb
Outdated
@@ -0,0 +1,298 @@ | |||
require 'rbconfig' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not related to this issue, please move out.
lib/utility.rb
Outdated
end | ||
|
||
if obj1.has_key?(key) | ||
if value.class.name == 'Hash' | ||
obj1[key] = overrides(obj1[key], obj2[key]) | ||
elsif value.class.name == 'Array' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 2 new lines added here?
spec/utility_spec.rb
Outdated
@@ -287,5 +287,86 @@ | |||
expect(new_provisioners[0]['run_list']).to eql(obj2['provisioners'][0]['run_list']) | |||
end | |||
end | |||
context "given a object then override it with another object contain array" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given an object ... with another object containing an array
obj2 = { | ||
"provisioners" => [{ | ||
"_id" => "0", | ||
"_a_run_list" => [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the case why we need _a_ here? Please provide real use case (use fixture as a real data). By the way, the test failed with this:
it "all array name in new and old array must be normalize" do
obj1 = {}
obj2 = {
"provisioners" => [{
"_id" => "0",
"_a_run_list" => ["hi", "there"]
}]
}
new_provisioners = overrides(obj1, obj2)['provisioners']
expect(new_provisioners[0]['run_list']).to eql(obj2['provisioners'][0]['_a_run_list'])
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see the cases of:
- organization A + project 1
- organization A + project 2
- oroganization A + project 1 + project 2
With the same data from the project configs (acme101) to see how the final config should look like.
spec/utility_spec.rb
Outdated
new_provisioners = overrides(obj1, obj2)['provisioners'] | ||
expect(new_provisioners[0]['run_list']).to eql(obj2['provisioners'][0]['run_list']) | ||
end | ||
it "all array name in new and old array must be normalize and value must be append" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
must be normalized and ... must be appended
Vagrantfile
Outdated
rescue Exception => msg | ||
puts red(msg) | ||
puts red('from vagrant_config_override.json') | ||
ans = prompt yellow("some errors have occured and 'vagrant_config_override.json' file will not be used, do you want to continue? [y/N]: ") | ||
puts red('from ' + parsing_file ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
red('from ' + parsing_file ) => red('from ' + parsing_file)
Vagrantfile
Outdated
if data_hash.key?('config_paths') | ||
data_hash['config_paths'].each do |default_config_file_path, value| | ||
overide_config_file_path = default_config_file_path.gsub(/default\.json$/, "overide.json") | ||
if File.exist? (default_config_file_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the default config file does not exist => print the error message + exit immediately. This is considered a fatal error to be fixed by users immediately.
@phuonglm btw, please sign the CLA. |
@phuonglm notice that the spec specified
|
@phuonglm please implement the auto discovery path for organization config, implement this similarly to #246
This is used so that users don't have to create any _override.json files if the default always works for them. Users don't have to configure anything if the default works (this works most of the time). Just git update and the new default config will be updated, users don't have to adjust anything. Later on, users will know what to do after these kinds of config update, see #318 |
d95d38e
to
8576641
Compare
@phuonglm your commit message is messy, please update. |
Vagrantfile
Outdated
|
||
if File.exist?(File.dirname(__FILE__) + '/workspace/dev-setuo/vagrant_config_default.json') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dev-setup
Vagrantfile
Outdated
@@ -125,7 +183,6 @@ Vagrant.configure("2") do |config| | |||
end | |||
when 'public_network' | |||
options[:ip] = vm_network['ip'] unless vm_network['ip'].nil? or vm_network['ip'].strip().empty? | |||
options[:bridge] = vm_network['bridge'] unless vm_network['bridge'].nil? or vm_network['bridge'].empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this
spec/fixture/config_overide.json
Outdated
} | ||
] | ||
}, | ||
"config_paths": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not include config_paths here for best practices
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, "config_paths" should be on the same group with "extension_paths" (under "vagrant")
@@ -0,0 +1,46 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should add "config_paths" for org_project here
spec/fixture/org_project.json
Outdated
}, | ||
"provisioners": [{ | ||
"_id": "0", | ||
"_ua_cookbooks_path": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use a here with "workspace/dev-setup/chef/main-cookbooks" element only, this show the use case of _a_
spec/fixture/project1.json
Outdated
@@ -0,0 +1,64 @@ | |||
{ | |||
"vm": { | |||
"hostname": "acme.dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove hostname
@@ -139,9 +139,20 @@ | |||
"action": "add" // one of add, remove. Default: add. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to add default config_paths:
{
"vagrant": {
"extension_paths": [ // add paths of Vagrantfile-ext.rb files to be loaded
// the path must be relative to the Vagrantfile
"Vagrantfile-ext.rb"
],
"config_paths": [ // add paths of config files to be loaded
// the path must be relative to the Vagrantfile
"workspace/dev-setup/vagrant_config_default.json"
]
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the default config paths are found => load them, otherwise, ignore.
If the default config paths are overridden => load them; if not found => exit with error message.
This is the same behavior with the extension_paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quite inconsistent for data_hash['vagrant']['config_paths'] that dev-setup entry is ignoreable while other entry is fatal error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the point due to the way we introduce "_a_" and "_ua_", let's make it consistent for both config_paths and extension_paths, I'll update extensions_path behavior after when this is merged.
spec/fixture/project1.json
Outdated
"provisioners": [{ | ||
"_id": "0", | ||
"_ua_cookbooks_path": [ | ||
"workspace/angular-hello-world/chef/main-cookbooks" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's best practices to have "dev-setup" on the project => "workspace/angular-hello-world/dev-setup/chef/main-cookbooks"
spec/fixture/project2.json
Outdated
@@ -0,0 +1,62 @@ | |||
{ | |||
"vm": { | |||
"hostname": "acme.dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this
spec/fixture/project2.json
Outdated
"provisioners": [{ | ||
"_id": "0", | ||
"_ua_cookbooks_path": [ | ||
"workspace/nextjs-hello-world/chef/main-cookbooks" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"workspace/nextjs-hello-world/dev-setup/chef/main-cookbooks"
…fic config support feature teracyhq#326
8576641
to
c6aecec
Compare
…fic config support feature teracyhq#326
c6aecec
to
47e4dfa
Compare
I updated the PR, please check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good enough to be merged, there are minor things that will be improved after this merge and some testing for real usage cases.
connect #321
please check with this project
https://github.com/phuonglm/iorad/tree/support-project-base-config
https://github.com/phuonglm/iorad-extension/tree/support-project-base-config
vagrant_config_override.json :