Skip to content

Commit

Permalink
Merge pull request #6 from giosakti/master
Browse files Browse the repository at this point in the history
[gio/tara] Refactor chef configuration for provisioning
  • Loading branch information
giosakti authored May 15, 2018
2 parents d021e36 + d8c1360 commit 5ace95b
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 297 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ tmp
database.yml
application.yml
tps_config.yml
chef_config.yml
chef-repo
vagrant_work_dir
blueprints/jobs/*.json
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 13 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/apps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.' }
Expand Down Expand Up @@ -86,6 +86,5 @@ def app_params

def set_config
@tps_config = TpsConfig.new(TPS_CONFIG)
@chef_configs = ChefConfigs.new(CHEF_CONFIG)
end
end
55 changes: 16 additions & 39 deletions app/models/blueprint.rb
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions app/models/chef_configs.rb

This file was deleted.

106 changes: 2 additions & 104 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -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')
31 changes: 3 additions & 28 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -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'
31 changes: 3 additions & 28 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions config/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ development:
ENABLE_CAS_INTEGRATION: 'false'

test:
DB_NAME: 'barito_test'
RAILS_ENV: 'test'
RACK_ENV: 'test'

DB_NAME: 'barito_test'
Loading

0 comments on commit 5ace95b

Please sign in to comment.