class Pfm::Settings
TERRAFORM_VERSION: ‘0.8.7’
PACKER_VERSION: ‘1.0.4’
PUBLISH_PREFIX: ‘axp’
PUBLISH_BUCKET: ‘dev-publish’
INF_BASE_DIR: ‘inf’
BUILD_BASE_DIR: ‘builds’
FOODCRITIC_RULES_FILE: ‘.pfm/.foodcritic’
RUBOCOP_RULES_FILE: ‘.pfm/.rubocop.yml’
AWS_REGION: ‘us-east-1’
—
An example .pfm/config
file might look like this:
== Example Configuration File
the .pfm/config
file.
Note that if you change these settings from the default, be sure you commit
* The version of Hashicorp Terraform to use for deploymentsTERRAFORM_VERSION
default -> ‘default from terraform/binary’<br><br>* The version of Hashicorp Packer to use for builds<br><br>PACKER_VERSION
<em>default -> ‘default from packer/binary’<br><br>s3://PUBLISH_BUCKET/PUBLISH_PREFIX/package.name
<br>* The prefix to the deployment package storage location. Ex:<br><br>PUBLISH_PREFIX
<em>default -> ”
* The top level bucket where deployment packages are stored in S3.PUBLISH_BUCKET
default -> ”
│ └── tf
│ ├── tasks
│ ├── env
├── inf
.
* Set the path to the top level infrastructure directory. Ex:INF_BASE_DIR
default -> ‘inf’
│ └── app-axpwa
│ ├── app-axpdb
├── builds
.
* Set the root path to the builds directory. This should be where top level server builds are located. Ex:BUILD_BASE_DIR
default -> ‘builds’
* Set the path to the global .foodcritic
rules file. This file will be used for all server builds when running semantics checks.FOODCRITIC_RULES_FILE
default -> ‘.foodcritic’
* Set the path to the global .rubocop.yml
rules file. This file will be used for all server builds when running syntax checks.RUBOCOP_RULES_FILE
default -> ‘.rubocop.yml’
* The AWS region to work in. This will eventually become the AWS_REGION environment variable and can be used with other AWS API operations.AWS_REGION
default -> ‘us-east-1’
located at .pfm/config
Top level settings defined and loaded here. This class loads the user config file
== PFM
Settings
def config_dir
def config_dir "#{@run_dir}/.pfm" end
def config_exists?
def config_exists? File.exist? config_file end
def config_file
def config_file "#{config_dir}/config" end
def create_config
def create_config return if config_exists? FileUtils.mkdir_p config_dir FileUtils.touch config_file write_config end
def initialize(expand = false)
def initialize(expand = false) @run_dir = Dir.pwd @config_directory = config_dir @expand = expand @settings = {} # Required @settings['AWS_REGION'] = Setting.new(ENV['AWS_REGION'], true) @settings['RUBOCOP_RULES_FILE'] = Setting.new('.rubocop.yml', true) @settings['FOODCRITIC_RULES_FILE'] = Setting.new('.foodcritic', true) @settings['BUILD_BASE_DIR'] = Setting.new('builds', true) @settings['INF_BASE_DIR'] = Setting.new('inf', true) @settings['PACKER_VERSION'] = Setting.new(::Packer::Binary.config.version, true) @settings['TERRAFORM_VERSION'] = Setting.new(::Terraform::Binary.config.version, true) # Optional Defaults @settings['PUBLISH_BUCKET'] = Setting.new('') @settings['PUBLISH_PREFIX'] = Setting.new('') load_config end
def load_config
def load_config if config_exists? require 'yaml' YAML.load_file(config_file).each do |key, value| msg("WARNING: unrecognized config key: '#{key}'") unless @settings.key? key next unless @settings.key? key required = @settings[key].required? @settings[key] = Setting.new(value, required) end # Also load each setting into the environment @settings.each { |key, setting| ENV[key] = setting.value } # Resolve paths if set resolve_paths if @expand else create_config load_config end end
def resolve_paths
def resolve_paths @settings.each do |key, setting| required = @settings[key].required? @settings[key] = Setting.new(File.realpath(setting.value), required) if File.exist? setting.value end end
def save_config(settings)
-
settings
(Map
) -- a new map of Pfm::Settings::Setting objects
def save_config(settings) @settings = settings write_config end
def settings_strings
-
(Map
-)
def settings_strings map = {} @settings.each do |key, setting| map[key] = setting.to_s end map end
def write_config
def write_config config_string = '---' @settings.each do |key, setting| config_string += "\n#{key}: '#{setting.value}'" end config_string += "\n" File.open(config_file, 'w') { |file| file.write(config_string) } end