diff --git a/.gitignore b/.gitignore index bca33198..7485310b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ tmp database.yml application.yml tps_config.yml -chef_config.yml chef-repo vagrant_work_dir blueprints/jobs/*.json diff --git a/.travis.yml b/.travis.yml index 35f3a686..1748795e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ before_script: - cp config/application.yml.example config/application.yml - cp config/database.yml.example config/database.yml - cp config/tps_config.yml.example config/tps_config.yml - - cp config/chef_config.yml.example config/chef_config.yml - psql -c 'create database barito_test;' -U postgres script: - bundle package --all diff --git a/Gemfile.lock b/Gemfile.lock index 306b4841..b927c4be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,26 +41,22 @@ GEM autoprefixer-rails (8.2.0) execjs bcrypt (3.1.11) - berkshelf (5.2.0) - addressable (~> 2.3, >= 2.3.4) - berkshelf-api-client (>= 2.0.2, < 4.0) + berkshelf (6.3.2) buff-config (~> 2.0) buff-extensions (~> 2.0) - buff-shell_out (~> 1.0) + chef (>= 12.7.2, < 14.0) cleanroom (~> 1.0) + concurrent-ruby (~> 1.0) faraday (~> 0.9) httpclient (~> 2.7) minitar (~> 0.5, >= 0.5.4) - mixlib-archive (~> 0.1) + mixlib-archive (~> 0.4) + mixlib-shellout (~> 2.0) octokit (~> 4.0) retryable (~> 2.0) ridley (~> 5.0) - solve (> 2.0, < 4.0) - thor (~> 0.19) - berkshelf-api-client (3.0.0) - faraday (~> 0.9) - httpclient (~> 2.7) - ridley (>= 4.5, < 6.0) + solve (~> 4.0) + thor (~> 0.19, < 0.19.2) bootstrap (4.0.0) autoprefixer-rails (>= 6.0.3) popper_js (>= 1.12.9, < 2) @@ -146,7 +142,7 @@ GEM railties (>= 3.0.0) faker (1.8.7) i18n (>= 0.7) - faraday (0.15.0) + faraday (0.15.1) multipart-post (>= 1.2, < 3) ffi (1.9.23) ffi-yajl (2.3.1) @@ -193,7 +189,7 @@ GEM mini_portile2 (2.3.0) minitar (0.6.1) minitest (5.11.3) - mixlib-archive (0.4.4) + mixlib-archive (0.4.6) mixlib-log mixlib-authentication (1.4.2) mixlib-cli (1.7.0) @@ -218,7 +214,7 @@ GEM nio4r (2.3.1) nokogiri (1.8.2) mini_portile2 (~> 2.3.0) - octokit (4.8.0) + octokit (4.9.0) sawyer (~> 0.8.0, >= 0.5.3) ohai (8.26.1) chef-config (>= 12.5.0.alpha.1, < 14) @@ -352,8 +348,8 @@ GEM actionpack (>= 3.1) railties (>= 3.1) slim (~> 3.0) - solve (3.1.1) - molinillo (>= 0.5) + solve (4.0.0) + molinillo (~> 0.6) semverse (>= 1.1, < 3.0) specinfra (2.73.3) net-scp @@ -378,7 +374,7 @@ GEM therubyracer (0.12.3) libv8 (~> 3.16.14.15) ref - thor (0.20.0) + thor (0.19.1) thread_safe (0.3.6) tilt (2.0.8) timers (4.0.4) diff --git a/app/controllers/apps_controller.rb b/app/controllers/apps_controller.rb index 5a0db7d2..caf26d30 100644 --- a/app/controllers/apps_controller.rb +++ b/app/controllers/apps_controller.rb @@ -29,7 +29,7 @@ def create respond_to do |format| if @app.save - blueprint = Blueprint.new(@app, @tps_config, @chef_configs) + blueprint = Blueprint.new(@app, @tps_config) blueprint.to_file @app.set_cluster_name(blueprint.cluster_name) format.html { redirect_to controller: 'apps', action: 'infra_setup', id: @app.id , notice: 'App was successfully created.' } @@ -86,6 +86,5 @@ def app_params def set_config @tps_config = TpsConfig.new(TPS_CONFIG) - @chef_configs = ChefConfigs.new(CHEF_CONFIG) end end diff --git a/app/models/blueprint.rb b/app/models/blueprint.rb index fffafe30..60947d4e 100644 --- a/app/models/blueprint.rb +++ b/app/models/blueprint.rb @@ -1,8 +1,20 @@ require 'faker' class Blueprint - # attr_accessor :provisioning, :vagrant, :chef_repo, :nodes - attr_accessor :blueprint, :application, :tps_config, :chef_config, :nodes, :cluster_name + attr_accessor :blueprint, :application, :tps_config, :nodes, :cluster_name + + def initialize(application, tps_config) + @application = application + @tps_config = tps_config.get(application.tps_config_id) + @cluster_name = generate_cluster_name + + create_nodes + create_blueprint + end + + def generate_cluster_name + Faker::Internet.user_name(4..4) + end def blueprint_hash { @@ -14,46 +26,14 @@ def blueprint_hash } end - def node_hash(node_name, node_type, run_list, chef_repo, container_config) + def node_hash(node_name, node_type, container_config) { "name": node_name, "type": node_type, - "run_list": run_list, - "chef_repo": chef_repo, "node_container_config": container_config } end - # def initialize args - # @provisioning = args['provisioning'] - # @chef_repo = args['chef_repo'] - # @vagrant = BlueprintVagrant.new(args['vagrant']) - # @nodes = [] - # args['nodes'].each do |node| - # @nodes << BlueprintNode.new(node) - # end - # end - def initialize(application, tps_config, chef_config) - @application = application - @tps_config = tps_config.get(application.tps_config_id) - @chef_config = chef_config - @cluster_name = generate_cluster_name - - create_nodes - create_blueprint - end - - # def self.create_from_file(path) - # file = File.read(path) - # hash = JSON.parse(file) - # - # Blueprint.new(hash) - # end - - def generate_cluster_name - Faker::Internet.user_name(4..4) - end - def create_blueprint @blueprint = blueprint_hash end @@ -64,11 +44,8 @@ def create_nodes available_instances.each do |instance| number_of_instance = @tps_config[instance + '_instances'] unless not number_of_instance.present? - chef_config = @chef_config.get(instance) - run_list = chef_config['run_list'] - chef_repo = chef_config['chef_repo'] (1..number_of_instance).each do |number| - nodes << node_hash(generate_node_name(instance, number), instance, run_list, chef_repo, @application.tps_config_id) + nodes << node_hash(generate_node_name(instance, number), instance, @application.tps_config_id) end end end diff --git a/app/models/chef_configs.rb b/app/models/chef_configs.rb deleted file mode 100644 index 74f06438..00000000 --- a/app/models/chef_configs.rb +++ /dev/null @@ -1,12 +0,0 @@ -class ChefConfigs - - attr_accessor :config - - def initialize(config) - @config = config - end - - def get(instance_name) - @config[instance_name] - end -end \ No newline at end of file diff --git a/bin/bundle b/bin/bundle index 524dfd3f..66e9889e 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,105 +1,3 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'bundle' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "rubygems" - -m = Module.new do - module_function - - def invoked_as_script? - File.expand_path($0) == File.expand_path(__FILE__) - end - - def env_var_version - ENV["BUNDLER_VERSION"] - end - - def cli_arg_version - return unless invoked_as_script? # don't want to hijack other binstubs - return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` - bundler_version = nil - update_index = nil - ARGV.each_with_index do |a, i| - if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN - bundler_version = a - end - next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ - bundler_version = $1 || ">= 0.a" - update_index = i - end - bundler_version - end - - def gemfile - gemfile = ENV["BUNDLE_GEMFILE"] - return gemfile if gemfile && !gemfile.empty? - - File.expand_path("../../Gemfile", __FILE__) - end - - def lockfile - lockfile = - case File.basename(gemfile) - when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) - else "#{gemfile}.lock" - end - File.expand_path(lockfile) - end - - def lockfile_version - return unless File.file?(lockfile) - lockfile_contents = File.read(lockfile) - return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ - Regexp.last_match(1) - end - - def bundler_version - @bundler_version ||= begin - env_var_version || cli_arg_version || - lockfile_version || "#{Gem::Requirement.default}.a" - end - end - - def load_bundler! - ENV["BUNDLE_GEMFILE"] ||= gemfile - - # must dup string for RG < 1.8 compatibility - activate_bundler(bundler_version.dup) - end - - def activate_bundler(bundler_version) - if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0") - bundler_version = "< 2" - end - gem_error = activation_error_handling do - gem "bundler", bundler_version - end - return if gem_error.nil? - require_error = activation_error_handling do - require "bundler/version" - end - return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION)) - warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`" - exit 42 - end - - def activation_error_handling - yield - nil - rescue StandardError, LoadError => e - e - end -end - -m.load_bundler! - -if m.invoked_as_script? - load Gem.bin_path("bundler", "bundle") -end +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index 6065ef07..5191e692 100755 --- a/bin/rails +++ b/bin/rails @@ -1,29 +1,4 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'rails' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("railties", "rails") +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake index ea0e2936..17240489 100755 --- a/bin/rake +++ b/bin/rake @@ -1,29 +1,4 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'rake' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) - -bundle_binstub = File.expand_path("../bundle", __FILE__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/ - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rake", "rake") +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/config/application.yml.example b/config/application.yml.example index 95fd3752..5ff01580 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -14,7 +14,6 @@ development: ENABLE_CAS_INTEGRATION: 'false' test: - DB_NAME: 'barito_test' RAILS_ENV: 'test' RACK_ENV: 'test' - + DB_NAME: 'barito_test' diff --git a/config/chef_config.yml.example b/config/chef_config.yml.example deleted file mode 100644 index d779a6ce..00000000 --- a/config/chef_config.yml.example +++ /dev/null @@ -1,25 +0,0 @@ -development: - kafka: - chef_repo: 'https://github.com/kafka/cookbooks' - run_list: 'kafka' - zookeeper: - chef_repo: 'https://github.com/zookeeper/cookbooks' - run_list: 'zookeeper' - consul: - chef_repo: 'https://github.com/consul/cookbooks' - run_list: 'consul' - yggdrasil: - chef_repo: 'https://github.com/yggdrasil/cookbooks' - run_list: 'yggdrasil' - barito-flow-receiver: - chef_repo: 'https://github.com/barito-flow-receiver/cookbooks' - run_list: 'barito-flow-receiver' - barito-flow-forwarder: - chef_repo: 'https://github.com/barito-flow-forwarder/cookbooks' - run_list: 'barito-flow-forwarder' - elasticsearch: - chef_repo: 'https://github.com/elasticsearch/cookbooks' - run_list: 'elasticsearch' - kibana: - chef_repo: 'https://github.com/kibana/cookbooks' - run_list: 'kibana' \ No newline at end of file diff --git a/config/initializers/chef_config.rb b/config/initializers/chef_config.rb deleted file mode 100644 index 8c85d3a3..00000000 --- a/config/initializers/chef_config.rb +++ /dev/null @@ -1 +0,0 @@ -CHEF_CONFIG = YAML.load_file("#{Rails.root.to_s}/config/chef_config.yml")[Rails.env] \ No newline at end of file diff --git a/spec/factories/chef_configs.rb b/spec/factories/chef_configs.rb deleted file mode 100644 index 085a700f..00000000 --- a/spec/factories/chef_configs.rb +++ /dev/null @@ -1,12 +0,0 @@ -FactoryBot.define do - factory :chef_configs do - initialize_with { new({ - "some-instance" => - { - "run_list"=>"some-instance", - "chef_repo"=>"some-url" - } - }) - } - end -end diff --git a/spec/models/app_spec.rb b/spec/models/app_spec.rb index 33a2cfa3..1ef2fd9a 100644 --- a/spec/models/app_spec.rb +++ b/spec/models/app_spec.rb @@ -50,8 +50,7 @@ it 'has cluster name after blueprint creation' do app = FactoryBot.create(:app, cluster_name: '') tps_config = FactoryBot.build(:tps_config) - chef_configs = FactoryBot.build(:chef_configs) - blueprint = Blueprint.new(app, tps_config, chef_configs) + blueprint = Blueprint.new(app, tps_config) app.set_cluster_name(blueprint.cluster_name) expect(app.cluster_name).to eq(blueprint.cluster_name) end diff --git a/spec/models/blueprint_spec.rb b/spec/models/blueprint_spec.rb index 50a79b13..63145f63 100644 --- a/spec/models/blueprint_spec.rb +++ b/spec/models/blueprint_spec.rb @@ -4,38 +4,37 @@ let (:app) {build :app} let (:tps_config) {build :tps_config} - let (:chef_configs) {build :chef_configs} context 'blueprint creation' do it 'has application' do - blueprint = Blueprint.new(app, tps_config, chef_configs) + blueprint = Blueprint.new(app, tps_config) expect(blueprint.application).to eq(app) end it 'has tps_config' do - blueprint = Blueprint.new(app, tps_config, chef_configs) + blueprint = Blueprint.new(app, tps_config) expect(blueprint.tps_config['name']).to eq('Small') end it 'generate cluster name' do - blueprint = Blueprint.new(app, tps_config, chef_configs) + blueprint = Blueprint.new(app, tps_config) expect(blueprint.cluster_name).to_not be_empty end it 'has cluster name not longer than 4 chars' do - blueprint = Blueprint.new(app, tps_config, chef_configs) + blueprint = Blueprint.new(app, tps_config) expect(blueprint.cluster_name.length).to eq(4) end it 'has blueprint hash' do - blueprint = Blueprint.new(app, tps_config, chef_configs) + blueprint = Blueprint.new(app, tps_config) blueprint.create_blueprint expect(blueprint.blueprint).to_not be_nil end it 'has nodes hash' do - blueprint = Blueprint.new(app, tps_config, chef_configs) + blueprint = Blueprint.new(app, tps_config) expect(blueprint.nodes).to_not be_nil end diff --git a/spec/models/chef_configs_spec.rb b/spec/models/chef_configs_spec.rb deleted file mode 100644 index 27e11a21..00000000 --- a/spec/models/chef_configs_spec.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'rails_helper' - -RSpec.describe ChefConfigs, type: :model do - context 'config' do - it 'must be presence' do - chef_configs = FactoryBot.build(:chef_configs) - expect(chef_configs.config).to_not be_nil - end - - it 'fetch by id' do - chef_configs = FactoryBot.build(:chef_configs) - expect(chef_configs.get('some-instance')).to_not be_nil - end - end - -end