class Appboost::ChefSoloGenerator

Public Instance Methods

copy_files() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 42
def copy_files
  template "Cheffile.erb",    "chef/Cheffile"
  template "Vagrantfile.erb", "chef/Vagrantfile"
  template "node.json.erb",   "chef/nodes/#{host}.json"
  template "user.json.erb",   "chef/data_bags/users/#{options[:app_user]}.json"

  copy_file "chef.gitignore", "chef/.gitignore"
end

Private Instance Methods

app_name() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 182
def app_name
  Dir.pwd.split('/').last
end
authorization_config() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 115
def authorization_config
  {
    sudo: {
      users: [options[:app_user]],
      passwordless: true
    }
  }
end
common_config() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 124
def common_config
  cfg = {
    nginx: {
      dir: "/etc/nginx",
      log_dir: "/var/log/nginx",
      binary: "/usr/sbin/nginx",
      user: "www-data",
      pid: "/var/run/nginx.pid",
      worker_connections: "1024"
    },
    git: {
      prefix: "/usr/local"
    },
  }
  cfg[:mysql] = mysql_config if mysql?
  cfg[:postgresql] = postgresql_config if postgresql?
  cfg
end
config() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 143
def config
  common_config.merge({
    authorization: authorization_config,
    rbenv: rbenv_config(options[:app_user])
  })
end
config_json() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 150
def config_json
  config.merge({
    run_list: run_list
  })
end
mysql?() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 53
def mysql?
  options[:database] == 'mysql'
end
mysql_config() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 96
def mysql_config
  {
    :server_root_password   => options[:db_password],
    :server_repl_password   => options[:db_password],
    :server_debian_password => options[:db_password],
    :service_name           => "mysql",
    :basedir                => "/usr",
    :data_dir               => "/var/lib/mysql",
    :root_group             => "root",
    :mysqladmin_bin         => "/usr/bin/mysqladmin",
    :mysql_bin              => "/usr/bin/mysql",
    :conf_dir               => "/etc/mysql",
    :confd_dir              => "/etc/mysql/conf.d",
    :socket                 => "/var/run/mysqld/mysqld.sock",
    :pid_file               => "/var/run/mysqld/mysqld.pid",
    :grants_path            => "/etc/mysql/grants.sql"
  }
end
postgresql?() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 57
def postgresql?
  options[:database] == 'postgresql'
end
postgresql_config() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 61
def postgresql_config
  {
    config: {
      listen_addresses: "*",
      port: "5432"
    },
    pg_hba: [
      {
        type:   "local",
        db:     "postgres",
        user:   "postgres",
        addr:   nil,
        method: "trust"
      },
      {
        type:   "host",
        db:     "all",
        user:   "all",
        addr:   "0.0.0.0/0",
        method: "md5"
      },
      {
        type:   "host",
        db:     "all",
        user:   "all",
        addr:   "::1/0",
        method: "md5"
      }
    ],
    password: {
      postgres: options[:db_password]
    }
  }
end
rbenv_config(user) click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 197
def rbenv_config(user) 
  {
    user_installs: [{
      user: user,
      rubies: [ options[:ruby] ],
      global: options[:ruby],
      environment: { CFLAGS: "-march=native -O2 -pipe" },
      gems: {
        options[:ruby] => [{name: "bundler", version: "1.3.5"}]
      }
    }]
  }
end
run_list() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 163
def run_list
  [
    "apt",
    "chef-solo-search",
    "locale",
    "users::sysadmins",
    "sudo",
    "runit",
    mysql? ? "mysql::server" : nil,
    postgresql? ? "postgresql::server" : nil,
    "imagemagick",
    "ruby_build",
    "rbenv::user",
    "nginx::repo",
    "nginx",
    "git"
  ].compact
end
user_json() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 186
def user_json
  {
    id:        options[:app_user],
    comment:   "Application User",
    ssh_keys:  [File.read(options[:ssh_pub_key])],
    groups:    ["sysadmin", "sudo", "staff"],
    shell:     "/bin/bash"
  }
end
vagrant_config() click to toggle source
# File lib/generators/appboost/chef_solo_generator.rb, line 156
def vagrant_config
  # common_config.merge({
  #   rbenv: rbenv_config('vagrant')
  # })
  config
end