Skip to content
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

Merged
merged 1 commit into from
Jul 17, 2017

Conversation

phuonglm
Copy link
Contributor

@phuonglm phuonglm commented Jun 15, 2017

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 :

{
  "vm":{
    "synced_folders":[{ //see: http://docs.vagrantup.com/v2/synced-folders/index.html
      "_id": "0",
      "_op": "d"
    }, { // Disable /workspace sync, use project config only
      "_id": "1",
      "_op": "d"
    }]
  },
  "config_paths": [
    "workspace/iorad/iorad-dev/vagrant_config.default.json",
    "workspace/iorad-extension/iorad-dev/vagrant_config.default.json"
  ]
}

@hoatle
Copy link
Member

hoatle commented Jun 18, 2017

@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.

@hoatle hoatle assigned phuonglm and unassigned datphan Jun 18, 2017
Copy link
Member

@hoatle hoatle left a 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.

@hoatle
Copy link
Member

hoatle commented Jun 18, 2017

I can only review when unit tests are provided to reflect all types of use cases and specification. @phuonglm please update asap.

@hoatle
Copy link
Member

hoatle commented Jun 18, 2017

I'd like to see how this works with many projects at https://github.com/teracyhq organization

@phuonglm phuonglm force-pushed the support-project-base-config branch from 23c46cc to 7e27157 Compare July 12, 2017 22:05
@CLAassistant
Copy link

CLAassistant commented Jul 12, 2017

CLA assistant check
All committers have signed the CLA.

@phuonglm phuonglm force-pushed the support-project-base-config branch from 7e27157 to d95d38e Compare July 12, 2017 22:12
@phuonglm
Copy link
Contributor Author

@hoale please check new update with config

{
  "vm":{
    "synced_folders":[{ //see: http://docs.vagrantup.com/v2/synced-folders/index.html
      "_id": "0",
      "_op": "d"
    }, {
      "_id": "1",
      "_op": "d"
    }
  ]
  },
  "config_paths": [
    "workspace/dev-setup/vagrant_config.default.json",
    "workspace/angular-hello-world/vagrant_config.default.json",
    "workspace/nextjs-hello-world/vagrant_config.default.json"
  ]
}

with related repository
https://github.com/phuonglm/dev-setup/tree/project-base-config
https://github.com/phuonglm/angular-hello-world/tree/project-base-config
https://github.com/phuonglm/nextjs-hello-world/tree/project-base-config
Those are just example change for example project base config. Will submit other PR after this merged.

Copy link
Member

@hoatle hoatle left a 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'
Copy link
Member

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)
Copy link
Member

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?
Copy link
Member

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'
Copy link
Member

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'

Copy link
Member

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?

@@ -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
Copy link
Member

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" => []
Copy link
Member

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

Copy link
Member

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.

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
Copy link
Member

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 )
Copy link
Member

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)
Copy link
Member

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.

@hoatle
Copy link
Member

hoatle commented Jul 13, 2017

@phuonglm btw, please sign the CLA.

@hoatle
Copy link
Member

hoatle commented Jul 13, 2017

@phuonglm notice that the spec specified vagrant_config_default.json and vagrant_config_override.json convention. It's closer to vagrant_config.json and vagrant_config_override.json current convention.

vagrant_config.default.json, we should avoid using . for file names to avoid some confusion to editors (mistaken as file extensions sometimes)

@hoatle
Copy link
Member

hoatle commented Jul 13, 2017

@phuonglm please implement the auto discovery path for organization config, implement this similarly to #246

  • By default, load workspace/dev-setup/vagrant_config_default.json if it exists (added to config_paths by default. The configuration path is: vagrant.config_paths.

  • Users can override this config_paths (of course), see how extension_paths work.

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

@phuonglm phuonglm force-pushed the support-project-base-config branch from d95d38e to 8576641 Compare July 14, 2017 07:42
@hoatle
Copy link
Member

hoatle commented Jul 14, 2017

@phuonglm your commit message is messy, please update.

Vagrantfile Outdated

if File.exist?(File.dirname(__FILE__) + '/workspace/dev-setuo/vagrant_config_default.json')
Copy link
Member

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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this

}
]
},
"config_paths": [
Copy link
Member

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

Copy link
Member

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 @@
{
Copy link
Member

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

},
"provisioners": [{
"_id": "0",
"_ua_cookbooks_path": [
Copy link
Member

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_

@@ -0,0 +1,64 @@
{
"vm": {
"hostname": "acme.dev",
Copy link
Member

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.
Copy link
Member

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"
    ]
  }
}

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@hoatle hoatle Jul 15, 2017

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.

"provisioners": [{
"_id": "0",
"_ua_cookbooks_path": [
"workspace/angular-hello-world/chef/main-cookbooks"
Copy link
Member

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"

@@ -0,0 +1,62 @@
{
"vm": {
"hostname": "acme.dev",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

"provisioners": [{
"_id": "0",
"_ua_cookbooks_path": [
"workspace/nextjs-hello-world/chef/main-cookbooks"
Copy link
Member

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"

phuonglm added a commit to phuonglm/dev that referenced this pull request Jul 15, 2017
@phuonglm phuonglm force-pushed the support-project-base-config branch from 8576641 to c6aecec Compare July 15, 2017 18:39
@phuonglm phuonglm force-pushed the support-project-base-config branch from c6aecec to 47e4dfa Compare July 17, 2017 01:54
@phuonglm
Copy link
Contributor Author

I updated the PR, please check.

@hoatle hoatle assigned hoatle and unassigned phuonglm Jul 17, 2017
Copy link
Member

@hoatle hoatle left a 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.

@hoatle hoatle merged commit bd538d8 into teracyhq:develop Jul 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants