Commit 46a1cb0
Changed files (6)
recipes
templates
default
recipes/capistrano.rb
@@ -0,0 +1,32 @@
+configuration = node['capistrano']
+root_path = configuration['root_path']
+shared_path = File.join(root_path, "shared")
+directories = [
+ configuration['root_path'],
+ shared_path,
+ "#{shared_path}/backups",
+ "#{shared_path}/bundle",
+ "#{shared_path}/config",
+ "#{shared_path}/log",
+ "#{shared_path}/pids",
+ "#{shared_path}/sockets",
+ "#{root_path}/releases",
+]
+
+directories.each do |dir_name|
+ directory dir_name do
+ owner configuration['username']
+ group configuration['username']
+ mode "0755"
+ recursive true
+ action :create
+ end
+end
+
+template "#{shared_path}/.env" do
+ source "env.erb"
+ owner configuration['username']
+ group configuration['username']
+ mode "0600"
+ variables(configuration['env'])
+end
spec/capistrano_spec.rb
@@ -0,0 +1,53 @@
+describe 'mokhan-myface::capistrano' do
+ subject do
+ ChefSpec::SoloRunner.new do |node|
+ node.set['capistrano']['root_path'] = root_path
+ node.set['capistrano']['username'] = username
+ node.set['capistrano']['env'] = environment_variables
+ end.converge(described_recipe)
+ end
+ let(:root_path) { "/var/www/#{FFaker::Internet.domain_name}" }
+ let(:shared_path) { "#{root_path}/shared" }
+ let(:username) { 'deployer' }
+ let(:environment_variables) { Hash.new }
+
+ it 'creates the root directory for the application' do
+ expect(subject).to create_directory(root_path)
+ .with_owner(username)
+ .with_group(username)
+ .with_mode("0755")
+ end
+
+ it 'creates the shared directory for the application' do
+ expect(subject).to create_directory("#{root_path}/shared")
+ .with_owner(username)
+ .with_group(username)
+ .with_mode("0755")
+ end
+
+ it 'creates all the shared folders' do
+ directories = [
+ "#{shared_path}/backups",
+ "#{shared_path}/bundle",
+ "#{shared_path}/config",
+ "#{shared_path}/log",
+ "#{shared_path}/pids",
+ "#{shared_path}/sockets",
+ "#{root_path}/releases"
+ ]
+ directories.each do |directory|
+ expect(subject).to create_directory(directory)
+ .with_owner(username)
+ .with_group(username)
+ .with_mode("0755")
+ end
+ end
+
+ it 'lays down the .env template' do
+ expect(subject).to create_template("#{shared_path}/.env")
+ .with_owner(username)
+ .with_group(username)
+ .with_mode("0600")
+ .with_variables(environment_variables)
+ end
+end
spec/spec_helper.rb
@@ -12,6 +12,7 @@
# the additional setup, and require it from the spec files that actually need
# it.
require 'chefspec'
+require 'ffaker'
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
templates/default/env.erb
@@ -0,0 +1,32 @@
+AWS_ACCESS_KEY_ID=<%= @aws[:access_key] %>
+AWS_SECRET_ACCESS_KEY=<%= @aws[:secret_access_key] %>
+AWS_PRODUCT_KEY=<%= @aws[:product_key] %>
+AWS_PRODUCT_SECRET=<%= @aws[:product_secret] %>
+AWS_PRODUCT_ASSOCIATE_ID=<%= @aws[:associate_id] %>
+AWS_S3_BACKUPS_BUCKET=<%= @aws[:s3_backup_bucket] %>
+FOG_DIRECTORY=<%= @aws[:s3_bucket] %>
+ASSET_SYNC_GZIP_COMPRESSION=true
+ASSET_SYNC_EXISTING_REMOTE_FILES=keep
+ASSET_HOST=<%= @asset_host %>
+SMTP_HOST=<%= @smtp[:host] %>
+SMTP_PORT=<%= @smtp[:port] %>
+SMTP_DOMAIN=<%= @smtp[:domain] %>
+SMTP_USERNAME=<%= @smtp[:username] %>
+SMTP_PASSWORD=<%= @smtp[:password] %>
+MIXPANEL_API_KEY=<%= @mix_panel_api_key %>
+SECRET_TOKEN=<%= @secret_token %>
+SECRET_KEY_BASE=<%= @secret_token %>
+GOOGLE_ANALYTICS=<%= @google_analytics %>
+EMBEDLY_KEY=<%= @embedly_key %>
+FACEBOOK_APP_ID=<%= @facebook_app_id %>
+DISQUS_API_KEY=<%= @disqus[:api_key] %>
+DISQUS_SECRET_KEY=<%= @disqus[:secret_key] %>
+DISQUS_SHORTNAME=<%= @disqus[:short_name] %>
+EXCEPTION_EMAIL_ADDRESS=<%= @exception_email_address %>
+MAILCHIMP_API_KEY=<%= @mailchimp[:api_key] %>
+MAILCHIMP_LIST_ID=<%= @mailchimp[:list_id] %>
+TWITTER_CONSUMER_KEY=<%= @twitter[:consumer_key] %>
+TWITTER_CONSUMER_SECRET=<%= @twitter[:consumer_secret] %>
+TWITTER_ACCESS_TOKEN=<%= @twitter[:access_token] %>
+TWITTER_ACCESS_SECRET=<%= @twitter[:access_secret] %>
+NEWRELIC_KEY=<%= @newrelic_key %>
Gemfile
@@ -14,4 +14,6 @@ group :test do
gem 'guard'
gem 'guard-rspec'
gem 'guard-shell'
+
+ gem 'ffaker'
end
Gemfile.lock
@@ -91,6 +91,7 @@ GEM
fauxhai (2.3.0)
net-ssh
ohai
+ ffaker (2.0.0)
ffi (1.9.8)
ffi-yajl (2.2.0)
libyajl2 (~> 1.2)
@@ -301,6 +302,7 @@ PLATFORMS
DEPENDENCIES
chefspec
+ ffaker
foodcritic
guard
guard-rspec