This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished database support in recipes
- Loading branch information
Igor Rzegocki
committed
Apr 10, 2016
1 parent
e23f2d4
commit cf955a0
Showing
10 changed files
with
143 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal: true | ||
libdir = File.expand_path('..', __FILE__) | ||
require File.join(libdir, 'core_ext') | ||
require File.join(libdir, 'helpers') | ||
Dir[File.join(libdir, 'drivers', 'dsl', '**', '*.rb')].each { |f| require f } | ||
Dir[File.join(libdir, '*', '**', 'base.rb')].each { |f| require f } | ||
Dir[File.join(libdir, '*', '**', '*.rb')].each { |f| require f } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
def applications | ||
if Chef::Config[:solo] | ||
Chef::Log.warn('This recipe uses search. Chef Solo does not support search.') | ||
end | ||
search(:aws_opsworks_app) | ||
end | ||
|
||
def rdses | ||
if Chef::Config[:solo] | ||
Chef::Log.warn('This recipe uses search. Chef Solo does not support search.') | ||
end | ||
search(:aws_opsworks_rds_db_instance) | ||
end | ||
|
||
def www_group | ||
value_for_platform_family( | ||
'debian' => 'www-data' | ||
) | ||
end | ||
|
||
def create_deploy_dir(application, subdir = '/') | ||
dir = File.join('/', 'srv', 'www', application['shortname'], subdir) | ||
directory dir do | ||
mode '0755' | ||
recursive true | ||
owner node['deployer']['user'] || 'root' | ||
group www_group | ||
|
||
action :create | ||
not_if { File.directory?(dir) } | ||
end | ||
dir | ||
end | ||
|
||
def deploy_dir(application) | ||
create_deploy_dir(application) | ||
end | ||
|
||
def every_enabled_application | ||
node['deploy'].each do |deploy_app_shortname, deploy| | ||
application = applications.detect { |app| app['shortname'] == deploy_app_shortname } | ||
next unless application | ||
deploy = deploy[application['shortname']] | ||
yield application, deploy | ||
end | ||
end | ||
|
||
def every_enabled_rds | ||
rdses.each do |rds| | ||
yield rds | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
# | ||
# Cookbook Name:: opsworks_ruby | ||
# Recipe:: configure | ||
# | ||
|
||
every_enabled_application do |application, _deploy| | ||
every_enabled_rds do |rds| | ||
database = Drivers::Db::Factory.build(application, node, rds: rds) | ||
template File.join(create_deploy_dir(application, File.join('shared', 'config')), 'database.yml') do | ||
source 'database.yml.erb' | ||
mode '0660' | ||
owner node['deployer']['user'] || 'root' | ||
group www_group | ||
variables(database: database.out, environment: application['attributes']['rails_env']) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
# | ||
# Cookbook Name:: opsworks_ruby | ||
# Spec:: default | ||
# | ||
# Copyright (c) 2016 The Authors, All Rights Reserved. | ||
|
||
require 'spec_helper' | ||
|
||
describe 'opsworks_ruby::configure' do | ||
let(:chef_run) do | ||
ChefSpec::SoloRunner.new do |solo_node| | ||
solo_node.set['deploy'] = node['deploy'] | ||
end.converge(described_recipe) | ||
end | ||
before do | ||
stub_search(:aws_opsworks_app, '*:*').and_return([aws_opsworks_app]) | ||
stub_search(:aws_opsworks_rds_db_instance, '*:*').and_return([aws_opsworks_rds_db_instance]) | ||
stub_node { |n| n.merge(node) } | ||
end | ||
|
||
context 'Database' do | ||
context 'Postgresql' do | ||
it 'creates proper database.yml template' do | ||
db_config = Drivers::Db::Postgresql.new(aws_opsworks_app, node, rds: aws_opsworks_rds_db_instance).out | ||
expect(chef_run) | ||
.to render_file("/srv/www/#{aws_opsworks_app['shortname']}/shared/config/database.yml").with_content( | ||
JSON.parse({ development: db_config, production: db_config }.to_json).to_yaml | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<%= | ||
config = {} | ||
(['development', 'production'] + Array.wrap(@environment)).select(&:present?).uniq.each do |env| | ||
config[env] = @database | ||
end | ||
JSON.parse(config.to_json).to_yaml | ||
-%> |