Skip to content

Commit

Permalink
KBP-122 #time 1h 30m - Paperclip was integrated.
Browse files Browse the repository at this point in the history
  • Loading branch information
esref.viduslu committed Oct 30, 2017
1 parent 8434185 commit 8b5a94b
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
require 'cybele/helpers/show_for'
require 'cybele/helpers/recipient_interceptor'
require 'cybele/helpers/locale_language'
require 'cybele/helpers/paperclip'
require 'cybele/app_builder'
1 change: 1 addition & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AppBuilder < Rails::AppBuilder
include Cybele::Helpers::RecipientInterceptor
include Cybele::Helpers::ShowFor
include Cybele::Helpers::LocaleLanguage
include Cybele::Helpers::Paperclip

def readme
template 'README.md.erb',
Expand Down
5 changes: 5 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ def add_staging_secret_key
build :add_staging_secret_key_to_secrets_yml
end

def setup_paperclip_and_add_aws
say 'Setting up paperclip, editing settings.yml and env files', :green
build :configure_paperclip
end

def goodbye
say 'Congratulations! That\'s all...', :green
end
Expand Down
34 changes: 34 additions & 0 deletions lib/cybele/helpers/paperclip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module Cybele
module Helpers
module Paperclip
def configure_paperclip
# Add gems
append_file('Gemfile', template_content('paperclip/paperclip_Gemfile.erb'))
run_bundle

create_paperclip_files
end

private

def create_paperclip_files
# Initialize file
template 'paperclip/paperclip.rb.erb',
'config/initializers/paperclip.rb',
force: true

# Add paperclip settings to the config/settings.yml file
append_file 'config/settings.yml',
template_content('paperclip/paperclip_settings.yml.erb')

# Add paperclip env to the all env files
append_file('env.sample', template_content('paperclip/paperclip_env_sample.erb'))
append_file('.env.local', template_content('paperclip/paperclip_env_local.erb'))
append_file('.env.staging', template_content('paperclip/paperclip_env_staging.erb'))
append_file('.env.production', template_content('paperclip/paperclip_env_production.erb'))
end
end
end
end
30 changes: 30 additions & 0 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,34 @@
secret_file = content('config/secrets.yml')
expect(secret_file).to match('staging')
end

it 'uses paperclip' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem "paperclip"/)
expect(gemfile_file).to match(/^gem 'aws-sdk'/)

env_sample_file = content('env.sample')
expect(env_sample_file).to match('S3_BUCKET_NAME=')
expect(env_sample_file).to match('AWS_RAW_URL=')
expect(env_sample_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_sample_file).to match('AWS_SECRET_ACCESS_KEY=')

env_local_file = content('.env.local')
expect(env_local_file).to match('S3_BUCKET_NAME=dummy_app-development')
expect(env_local_file).to match('AWS_RAW_URL=dummy_app-development.s3.amazonaws.com')
expect(env_local_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_local_file).to match('AWS_SECRET_ACCESS_KEY=')

env_staging_file = content('.env.staging')
expect(env_staging_file).to match('S3_BUCKET_NAME=dummy_app-staging')
expect(env_staging_file).to match('AWS_RAW_URL=dummy_app-staging.s3.amazonaws.com')
expect(env_staging_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_staging_file).to match('AWS_SECRET_ACCESS_KEY=')

env_production_file = content('.env.production')
expect(env_production_file).to match('S3_BUCKET_NAME=dummy_app')
expect(env_production_file).to match('AWS_RAW_URL=dummy_app.s3.amazonaws.com')
expect(env_production_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_production_file).to match('AWS_SECRET_ACCESS_KEY=')
end
end
31 changes: 30 additions & 1 deletion spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
expect(locale_file).to match('view:')
end


it 'uses recipient_interceptor' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'recipient_interceptor'/)
Expand All @@ -191,4 +190,34 @@
secret_file = content('config/secrets.yml')
expect(secret_file).to match('staging')
end

it 'uses paperclip' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem "paperclip"/)
expect(gemfile_file).to match(/^gem 'aws-sdk'/)

env_sample_file = content('env.sample')
expect(env_sample_file).to match('S3_BUCKET_NAME=')
expect(env_sample_file).to match('AWS_RAW_URL=')
expect(env_sample_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_sample_file).to match('AWS_SECRET_ACCESS_KEY=')

env_local_file = content('.env.local')
expect(env_local_file).to match('S3_BUCKET_NAME=dummy_app-development')
expect(env_local_file).to match('AWS_RAW_URL=dummy_app-development.s3.amazonaws.com')
expect(env_local_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_local_file).to match('AWS_SECRET_ACCESS_KEY=')

env_staging_file = content('.env.staging')
expect(env_staging_file).to match('S3_BUCKET_NAME=dummy_app-staging')
expect(env_staging_file).to match('AWS_RAW_URL=dummy_app-staging.s3.amazonaws.com')
expect(env_staging_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_staging_file).to match('AWS_SECRET_ACCESS_KEY=')

env_production_file = content('.env.production')
expect(env_production_file).to match('S3_BUCKET_NAME=dummy_app')
expect(env_production_file).to match('AWS_RAW_URL=dummy_app.s3.amazonaws.com')
expect(env_production_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_production_file).to match('AWS_SECRET_ACCESS_KEY=')
end
end
11 changes: 11 additions & 0 deletions templates/paperclip/paperclip.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#Remove command lines

# Paperclip::Attachment.default_options[:storage] = :s3
# Paperclip::Attachment.default_options[:s3_host_name] = Settings.AWS.S3.end_point
# Paperclip::Attachment.default_options[:s3_host_alias] = Settings.AWS.S3.aws_raw_url
# Paperclip::Attachment.default_options[:bucket] = Settings.AWS.S3.bucket
# Paperclip::Attachment.default_options[:s3_protocol] = 'https'
# Paperclip::Attachment.default_options[:s3_credentials] = {
# access_key_id: Settings.AWS.S3.access_key_id,
# secret_access_key: Settings.AWS.S3.secret_access_key
# }
4 changes: 4 additions & 0 deletions templates/paperclip/paperclip_Gemfile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# Easy file attachment management for ActiveRecord. Amazon's S3 storage adapter.
gem "paperclip", "~> 5.0.0"
gem 'aws-sdk', '~> 2.3.0'
5 changes: 5 additions & 0 deletions templates/paperclip/paperclip_env_local.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

S3_BUCKET_NAME=<%= app_name %>-development
AWS_RAW_URL=<%= app_name %>-development.s3.amazonaws.com
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
5 changes: 5 additions & 0 deletions templates/paperclip/paperclip_env_production.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

S3_BUCKET_NAME=<%= app_name %>
AWS_RAW_URL=<%= app_name %>.s3.amazonaws.com
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
5 changes: 5 additions & 0 deletions templates/paperclip/paperclip_env_sample.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

S3_BUCKET_NAME=
AWS_RAW_URL=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
5 changes: 5 additions & 0 deletions templates/paperclip/paperclip_env_staging.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

S3_BUCKET_NAME=<%= app_name %>-staging
AWS_RAW_URL=<%= app_name %>-staging.s3.amazonaws.com
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
10 changes: 10 additions & 0 deletions templates/paperclip/paperclip_settings.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

AWS:
S3:
bucket: <%= ENV['S3_BUCKET_NAME'] %>
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
aws_url: http://<%= ENV['AWS_RAW_URL'] %>
aws_raw_url: <%= ENV['AWS_RAW_URL'] %>
# Bucket region should be ireland for this setting
end_point: s3-eu-west-1.amazonaws.com

0 comments on commit 8b5a94b

Please sign in to comment.