config_kit 0.0.11 → 0.0.16

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
- SHA1:
3
- metadata.gz: d87686cf24927b1e2bfb70a50dfb58e2cde955e5
4
- data.tar.gz: 1635b8f74554c97e702ec4261846cde10435a6c8
2
+ SHA256:
3
+ metadata.gz: 323821610943389f9f2d36e3645a23f7b18d0dc7849f51b8f247b96c2a21c14e
4
+ data.tar.gz: 584a932bf10f6e30d8ae41426656e8e6bb50eb27b879a10d1f51ced10f53281c
5
5
  SHA512:
6
- metadata.gz: f7965a88abcbbddaa6e0437f0fd7c61f371702c87b0beadf85074639548420d09132f1bff27a91a0a5be7570bd3a54b4169c4185d58ee7fb7bb8cccc0a39a55f
7
- data.tar.gz: b51369d2c72f7c65c85b75eef778663a3c10794bcf1afb54ebc996e595f17403948f49563fcb392dfccbb2279b50324992527a732264e12babe14e0ce0aeda77
6
+ metadata.gz: 0210022a7402273430635769d4ea402cdd79e535f8277077daf135a7e6f182aced9fddeb6585a75a6024bac1c3d778ad6e9f2bd484410972cd9fdc0afa3ce94b
7
+ data.tar.gz: 94449467374b3ea571f410df0a0e007acd2afdb31ef047530b3ba09179423822253774c1af46078b556aaed04420507e5b1eb97550e7322c6acd85626144276b
data/.gitignore CHANGED
@@ -1,35 +1,50 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- coverage
6
- InstalledFiles
7
- lib/bundler/man
8
- pkg
9
- rdoc
10
- spec/reports
11
- test/tmp
12
- test/version_tmp
13
- tmp
14
-
15
- # YARD artifacts
16
- .yardoc
17
- _yardoc
18
- doc/
19
-
20
- # Vim
21
- *.swp
22
- *.swo
23
-
24
- # ctags
25
- tags
26
-
27
- #Mac
28
- .DS_Store
29
- tmp/
1
+ # These are some examples of commonly ignored file patterns.
2
+ # You should customize this list as applicable to your project.
3
+ # Learn more about .gitignore:
4
+ # https://www.atlassian.com/git/tutorials/saving-changes/gitignore
5
+
6
+ # Node artifact files
7
+ node_modules/
8
+ dist/
9
+
10
+ # Compiled Java class files
11
+ *.class
12
+
13
+ # Compiled Python bytecode
14
+ *.py[cod]
30
15
 
31
- .idea
32
- reports/
16
+ # Log files
17
+ *.log
18
+
19
+ # Package files
20
+ *.jar
21
+
22
+ # Maven
33
23
  target/
34
- log
35
- migrations/*.db
24
+ dist/
25
+
26
+ # JetBrains IDE
27
+ .idea/
28
+
29
+ # Unit test reports
30
+ TEST*.xml
31
+
32
+ # Generated by MacOS
33
+ .DS_Store
34
+
35
+ # Generated by Windows
36
+ Thumbs.db
37
+
38
+ # Applications
39
+ *.app
40
+ *.exe
41
+ *.war
42
+
43
+ # Large media files
44
+ *.mp4
45
+ *.tiff
46
+ *.avi
47
+ *.flv
48
+ *.mov
49
+ *.wmv
50
+
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'http://gems.sd.laxino.com'
2
2
 
3
- gem 'diplomat', '1.4.1'
4
- gem 'git', '1.3.0'
3
+ gemspec
5
4
  group :test do
6
5
  gem 'simplecov', '0.12.0'
7
6
  gem 'rspec'
data/README.md CHANGED
@@ -14,6 +14,10 @@ config_kit provides command line(ck) to init, bootstrap, deploy, rollout, rollba
14
14
 
15
15
  * init: init is to initialize metadata for specific data center, which will including the informaction of data center name and entitled environment for the data center
16
16
 
17
+ ```bash
18
+ ck init -n 'moidc' -e 'Laxino.MO.Staging' -c 'stg0'
19
+ ```
20
+
17
21
  * describe: retrieve inforamation about all configuration or app configuration
18
22
 
19
23
  >describe all information of configuration
data/config_kit.gemspec CHANGED
@@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
31
 
32
32
  spec.add_dependency "bundler", "~> 1.12"
33
- spec.add_dependency "diplomat", "1.4.1"
33
+ spec.add_dependency "diplomat", "2.0.2"
34
34
  spec.add_dependency "git", "1.3.0"
35
- end
35
+ end
data/docker/Dockerfile ADDED
@@ -0,0 +1,16 @@
1
+ FROM cheokman/lax-base:latest
2
+
3
+ ENV DEPLOY_PATH=/opt/deploy
4
+ ENV APP_PATH=$DEPLOY_PATH/application
5
+ ENV REL_PATH=$APP_PATH/release
6
+ ENV SHARE_PATH=$APP_PATH/shared
7
+
8
+ RUN mkdir -p $APP_PATH
9
+
10
+ WORKDIR $REL_PATH
11
+ COPY .ruby-version $REL_PATH/.ruby-version
12
+
13
+ RUN /bin/bash -l -c "rvm install $(cat .ruby-version); gem install bundler; rvm cleanup all"
14
+
15
+ RUN /bin/bash -l -c "gem install config_kit --version '>=0.0.15' --source http://gems.sd.laxino.com"
16
+ ENV CK_URL='http://consul:8500'
@@ -11,7 +11,7 @@ module ConfigKit::Cli
11
11
  begin
12
12
  raise ConfigKit::Cli::Command::CommandFailure.new 'Missing name options' if @name.nil?
13
13
  raise ConfigKit::Cli::Command::CommandFailure.new 'Missing environment options' if @env.nil?
14
- @output = ConfigKit::Manager.init(@name, @env)
14
+ @output = ConfigKit::Manager.init(@name, @env, @codename)
15
15
  pp @output.to_h.to_json
16
16
  rescue ConfigKit::Cli::Command::CommandFailure
17
17
  raise
@@ -35,6 +35,11 @@ module ConfigKit::Cli
35
35
  opts.on('-e ENV', '--env', 'Specify a environment of IDC to config') do |env|
36
36
  @env = env
37
37
  end
38
+
39
+ opts.on('-c CODENAME', '--codename', 'Specify a codename of IDC to config') do |codename|
40
+ @codename = codename
41
+ end
42
+
38
43
  end
39
44
  end
40
45
  end
@@ -13,8 +13,9 @@ module ConfigKit
13
13
 
14
14
  extend Forwardable
15
15
  def_delegators :@connection, :put, :get, :delete, :txn
16
- def initialize(url, acl_token)
16
+ def initialize(url, acl_token, txn_limit=64)
17
17
  setup_consul(url, acl_token)
18
+ @txn_limit = txn_limit
18
19
  end
19
20
 
20
21
  def setup_consul(url, acl_token)
@@ -57,7 +58,19 @@ module ConfigKit
57
58
 
58
59
  def perform_txn
59
60
  begin
60
- txn(@txn_data)
61
+ txn_length = @txn_data.length
62
+ current_index = 1
63
+ start_index = 0
64
+ end_index = 0
65
+ while @txn_limit * current_index < txn_length
66
+ start_index = @txn_limit * (current_index - 1)
67
+ end_index = @txn_limit * current_index - 1
68
+ txn(@txn_data[start_index..end_index])
69
+ current_index += 1
70
+ end
71
+ start_index = @txn_limit * (current_index - 1)
72
+ end_index = txn_length - 1
73
+ txn(@txn_data[start_index..end_index])
61
74
  rescue => e
62
75
  raise ConfigKitTxnError.new "perform txn error:#{e.message}"
63
76
  ensure
@@ -29,10 +29,10 @@ module ConfigKit
29
29
  ldrs = ldrs = File.expand_path(File.join(File.dirname(__FILE__), 'loaders', '*.rb'))
30
30
  Dir[ldrs].each {|loader| require loader}
31
31
 
32
- def self.load(app, from, uri_kls, env, version, &block)
32
+ def self.load(app, from, uri_kls, env, codename, version, &block)
33
33
  @loader_names = @loaders.map{ |l| l.loader}
34
34
 
35
- @uri_kls, @env, @app, @version = uri_kls, env, app, version
35
+ @uri_kls, @env, @app, @version, @codename = uri_kls, env, app, version, codename
36
36
 
37
37
  loader = from
38
38
 
@@ -40,12 +40,12 @@ module ConfigKit
40
40
  if loader.nil?
41
41
  ConfigKit.logger.error "from empty source with #{@uri_kls.to_s}"
42
42
  elsif !@loader_names.include?(loader)
43
- ConfigKit.logger.error "Unrecognize loader: #{loader} for #{@uri}"
43
+ ConfigKit.logger.error "Unrecognize loader: #{loader} for #{@uri}(#{@codename})"
44
44
  else
45
45
  loader_class = @loaders.find{ |c| c.loader == loader}
46
- ConfigKit.logger.debug "#{loader_class.loader} is loading env(#{@env}) app(#{app}) data(#{@version}) from #{uri_kls.to_s}"
47
- loader_class.new(@uri_kls, @env, @app, @version).run(&block)
48
- ConfigKit.logger.debug "#{loader_class.loader} is loaded env(#{@env}) app(#{app}) data(#{@version}) from #{uri_kls.to_s}"
46
+ ConfigKit.logger.debug "#{loader_class.loader} is loading env(#{@env}) app(#{app}) data(#{@version}) codename(#{codename}) from #{uri_kls.to_s}"
47
+ loader_class.new(@uri_kls, @env, @codename, @app, @version).run(&block)
48
+ ConfigKit.logger.debug "#{loader_class.loader} is loaded env(#{@env}) app(#{app}) data(#{@version}) codename(#{codename}) from #{uri_kls.to_s}"
49
49
  end
50
50
  rescue => e
51
51
  raise ConfigKit::Data::Loader::LoaderFailure.new e.message
@@ -4,9 +4,9 @@ module ConfigKit::Data
4
4
  def self.loader; "file"; end
5
5
 
6
6
  attr_reader :files
7
- def initialize(uri_kls, env, app, branch)
8
- @uri_kls, @env, @app, @branch = uri_kls, env, app, branch
9
- @path = File.expand_path('.',File.join(retrieve_path(@uri_kls.path),env))
7
+ def initialize(uri_kls, env, codename, app, branch)
8
+ @uri_kls, @env, @codename, @app, @branch = uri_kls, env, codename, app, branch
9
+ @path = File.expand_path('.',File.join(retrieve_path(@uri_kls.path),@codename))
10
10
  super()
11
11
  end
12
12
 
@@ -36,9 +36,9 @@ module ConfigKit::Data
36
36
 
37
37
  def retrieve_files
38
38
  files = if @app == 'all'
39
- Dir["#{@path}/**/*.yml"].select { |f| match_for?(f, @env) }
39
+ Dir["#{@path}/**/*.yml"].select { |f| match_for?(f, @codename) }
40
40
  else
41
- Dir["#{@path}/**/*.yml"].select {|f| match_for?(f, @app) && match_for?(f, @env)}
41
+ Dir["#{@path}/**/*.yml"].select {|f| match_for?(f, @app) && match_for?(f, @codename)}
42
42
  end
43
43
  raise ConfigKit::Data::Loader::LoaderFailure.new('No data file found.') if files.empty?
44
44
  files
@@ -51,13 +51,13 @@ private
51
51
  path
52
52
  end
53
53
 
54
- def env_app_for(f)
54
+ def codename_app_for(f)
55
55
  File.basename(f).split('.')[0..1]
56
56
  end
57
57
 
58
58
  def load_one(f)
59
- env, app = env_app_for(f)
60
- raise ConfigKit::Data::Loader::LoaderFailure.new("Wrong data file env(#{env}) for loaded #{@env}") unless env == @env
59
+ codename, app = codename_app_for(f)
60
+ raise ConfigKit::Data::Loader::LoaderFailure.new("Wrong data file codename(#{codename}) for loaded #{@codename}") unless codename == @codename
61
61
  {app => YAML.load_file(f)}
62
62
  end
63
63
 
@@ -4,8 +4,8 @@ module ConfigKit::Data
4
4
  class GitLoaderError < ConfigKit::Error; end
5
5
  def self.loader; "git"; end
6
6
  attr_reader :clone_path
7
- def initialize(uri_kls, env, app, version)
8
- @uri_kls, @env, @app, @version = uri_kls, env, app, version
7
+ def initialize(uri_kls, env, codename, app, version)
8
+ @uri_kls, @env, @codename, @app, @version = uri_kls, env, codename, app, version
9
9
  @clone_path = Dir.mktmpdir
10
10
  @file_path = "file://#{@clone_path}"
11
11
  @file_kls = URI.parse(@file_path)
@@ -15,7 +15,7 @@ module ConfigKit::Data
15
15
  def run(&block)
16
16
  ConfigKit.logger.debug "Git is loading env(#{@env}) #{@app} from #{@uri_kls.to_s}"
17
17
  begin
18
- FileLoader.new(@file_kls, @env, @app, @version).run(&block)
18
+ FileLoader.new(@file_kls, @env, @codename, @app, @version).run(&block)
19
19
  ensure
20
20
  FileUtils.rm_rf @clone_path
21
21
  end
@@ -23,7 +23,7 @@ module ConfigKit::Data
23
23
 
24
24
  private
25
25
  def clone
26
- ConfigKit.logger.debug "Git is cloning env(#{@env}) #{@app} from #{@uri_kls.to_s}"
26
+ ConfigKit.logger.debug "Git is cloning env(#{@env}) #{@app} codename(#{@codename}) from #{@uri_kls.to_s}"
27
27
  begin
28
28
  g = Git.clone(@uri_kls.to_s, @clone_path)
29
29
  tags = g.tags.map { |t| t.name }
@@ -2,8 +2,8 @@ require 'config_kit/ext/slashed_hash'
2
2
 
3
3
  module ConfigKit
4
4
  class IDCData < SlashedHash
5
- def initialize(name, env, opts)
6
- @name, @env = name, env
5
+ def initialize(name, env, codename, opts)
6
+ @name, @env, @codename = name, env, codename
7
7
  @api_version = opts.fetch(:api_version, '1.0')
8
8
  @kind = opts.fetch(:kind, 'config_kit')
9
9
  @bind_data = binding_data
@@ -13,7 +13,8 @@ module ConfigKit
13
13
  def data
14
14
  {
15
15
  'name' => @name,
16
- 'env' => @env
16
+ 'env' => @env,
17
+ 'codename' => @codename
17
18
  }
18
19
  end
19
20
 
@@ -25,11 +25,12 @@ module ConfigKit
25
25
  new(app, opts).deploy
26
26
  end
27
27
 
28
- def self.init(name, env='int0', opts={})
28
+ def self.init(name, env='int0', codename='int0', opts={})
29
29
  app = 'idc'
30
30
  opts['name'] = name
31
31
  opts['env'] = env
32
- opts['skip_env_check'] = true
32
+ opts['codename'] = codename
33
+ opts['skip_codename_check'] = true
33
34
  new(app,opts).init
34
35
  end
35
36
 
@@ -41,19 +42,21 @@ module ConfigKit
41
42
  @app = app
42
43
  @opts = opts
43
44
  @tool = ConfigKit::Tool.new
44
- unless opts['skip_env_check'] == true
45
- env = @tool.get_idc_env
46
- raise ConfigKit::Manager::IDCEnvMissing.new 'IDC environment missing, pls init it first!' if env.nil?
45
+ unless opts['skip_codename_check'] == true
46
+ codename = @tool.get_idc_codename
47
+ env = @tool.get_idc_env
48
+ raise ConfigKit::Manager::IDCEnvMissing.new 'IDC environment/codename missing, pls init it first!' if codename.nil? && env.nil?
49
+ @opts['codename'] = codename
47
50
  @opts['env'] = env
48
51
  end
49
-
50
52
  end
51
53
 
52
54
  def init
53
55
  name = @opts.delete('name')
54
56
  env = @opts.delete('env')
57
+ codename = @opts.delete('codename')
55
58
  @tool.init_txn
56
- @tool.idc_init_txn(name, env, @opts)
59
+ @tool.idc_init_txn(name, env, codename, @opts)
57
60
  @tool.perform_txn
58
61
  end
59
62
 
@@ -68,7 +71,7 @@ module ConfigKit
68
71
  end
69
72
 
70
73
  def create(extra=:no_default)
71
- ConfigKit::Data::Loader.load(@app, @opts['from'], @opts['uri_kls'], @opts['env'], @opts['version']) do |data|
74
+ ConfigKit::Data::Loader.load(@app, @opts['from'], @opts['uri_kls'], @opts['env'], @opts['codename'], @opts['version']) do |data|
72
75
  @tool.init_txn
73
76
  data.each_pair do |k,v|
74
77
  @tool.bootstrap_txn(v, k)
@@ -45,12 +45,12 @@ module ConfigKit
45
45
  @client.read(path).nil?
46
46
  end
47
47
 
48
- def idc_config(name, env, opts)
49
- ConfigKit::IDCData.new(name, env, opts)
48
+ def idc_config(name, env, codename, opts)
49
+ ConfigKit::IDCData.new(name, env, codename, opts)
50
50
  end
51
51
 
52
- def idc_init_txn(name, env, opts={})
53
- @idc_data = idc_config(name, env, opts)
52
+ def idc_init_txn(name, env, codename, opts={})
53
+ @idc_data = idc_config(name, env, codename, opts)
54
54
  @client.create_txn(@idc_data)
55
55
  end
56
56
 
@@ -66,6 +66,12 @@ module ConfigKit
66
66
  data['config_kit']['idc']['env']
67
67
  end
68
68
 
69
+ def get_idc_codename
70
+ data = @client.read(idc_path)
71
+ return nil if data.nil?
72
+ data['config_kit']['idc']['codename']
73
+ end
74
+
69
75
  def describe(app, version)
70
76
  @content = {}
71
77
  data = @client.read(idc_path)
@@ -124,8 +130,6 @@ module ConfigKit
124
130
  raise MissingDefaultVersionError.new "Missing default version for app(#{app}), pls set default version first.\n"
125
131
  end
126
132
  app_path = path_for(app, version)
127
- pp app_path
128
- pp @client.read(app_path)
129
133
  app_version = @client.read(app_path)[kind]
130
134
  app_data = {}
131
135
  app_data[app] = app_version[app][version]
@@ -153,16 +157,16 @@ module ConfigKit
153
157
  end
154
158
 
155
159
  def deploy_path
156
- "/#{kind}/deploy"
160
+ "#{kind}/deploy"
157
161
  end
158
162
 
159
163
  def path_for(app, version=nil)
160
- return "/#{kind}/#{app}" if version.nil?
161
- "/#{kind}/#{app}/#{version}"
164
+ return "#{kind}/#{app}" if version.nil?
165
+ "#{kind}/#{app}/#{version}"
162
166
  end
163
167
 
164
168
  def idc_path
165
- "/#{kind}/idc"
169
+ "#{kind}/idc"
166
170
  end
167
171
  end
168
172
  end
@@ -1,3 +1,3 @@
1
1
  module ConfigKit
2
- VERSION = '0.0.11'
3
- end
2
+ VERSION = '0.0.16'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Wu
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-19 00:00:00.000000000 Z
11
+ date: 2024-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.4.1
47
+ version: 2.0.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 1.4.1
54
+ version: 2.0.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: git
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +86,7 @@ files:
86
86
  - config/stg0/stg0.axle.yml
87
87
  - config/stg0/stg0.infra.yml
88
88
  - config_kit.gemspec
89
+ - docker/Dockerfile
89
90
  - lib/config_kit.rb
90
91
  - lib/config_kit/cli/command.rb
91
92
  - lib/config_kit/cli/commands/bootstrap.rb
@@ -116,7 +117,7 @@ licenses:
116
117
  - Ruby
117
118
  metadata:
118
119
  allowed_push_host: https://rubygems.org
119
- post_install_message:
120
+ post_install_message:
120
121
  rdoc_options: []
121
122
  require_paths:
122
123
  - lib
@@ -131,9 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  - !ruby/object:Gem::Version
132
133
  version: '0'
133
134
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.6.8
136
- signing_key:
135
+ rubygems_version: 3.1.6
136
+ signing_key:
137
137
  specification_version: 4
138
138
  summary: Write a short summary, because Rubygems requires one.
139
139
  test_files: []