Module: Codebuild::Core

Extended by:
Memoist
Included in:
Codebuild
Defined in:
lib/codebuild/core.rb

Instance Method Summary collapse

Instance Method Details

#check_codebuild_project!Object



46
47
48
49
50
51
52
53
54
# File 'lib/codebuild/core.rb', line 46

def check_codebuild_project!
  check_path = "#{Codebuild.root}/.codebuild/settings.yml"
  unless File.exist?(check_path)
    puts "ERROR: No settings file at #{check_path}.  Are you sure you are in a project with codebuild setup?".color(:red)
    puts "Current directory: #{Dir.pwd}"
    puts "If you want to set up codebuild for this prjoect, please create a settings file via: codebuild init"
    exit 1 unless ENV['TEST']
  end
end

#envObject



13
14
15
16
17
18
# File 'lib/codebuild/core.rb', line 13

def env
  # 2-way binding
  cb_env = env_from_profile || 'development'
  cb_env = ENV['CB_ENV'] if ENV['CB_ENV'] # highest precedence
  cb_env
end

#env_extraObject



21
22
23
24
25
# File 'lib/codebuild/core.rb', line 21

def env_extra
  env_extra = ENV['CB_ENV_EXTRA'] if ENV['CB_ENV_EXTRA'] # highest precedence
  return if env_extra&.empty?
  env_extra
end

#rootObject



8
9
10
11
# File 'lib/codebuild/core.rb', line 8

def root
  path = ENV['CB_ROOT'] || '.'
  Pathname.new(path)
end

#set_aws_profile!Object

Overrides AWS_PROFILE based on the Codebuild.env if set in configs/settings.yml 2-way binding.



30
31
32
33
34
35
36
37
38
39
# File 'lib/codebuild/core.rb', line 30

def set_aws_profile!
  return if ENV['TEST']
  return unless File.exist?("#{Codebuild.root}/.codebuild/settings.yml") # for rake docs
  return unless settings # Only load if within Codebuild project and there's a settings.yml
  data = settings[Codebuild.env] || {}
  if data["aws_profile"]
    puts "Using AWS_PROFILE=#{data["aws_profile"]} from CB_ENV=#{Codebuild.env} in config/settings.yml"
    ENV['AWS_PROFILE'] = data["aws_profile"]
  end
end

#settingsObject



41
42
43
# File 'lib/codebuild/core.rb', line 41

def settings
  Setting.new.data
end