redde 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +1 -0
  2. data/README.md +6 -0
  3. data/lib/generators/redde/layout/templates/assets/stylesheets/admin/layouts/page-header.sass +4 -1
  4. data/lib/generators/redde/photo/photo_generator.rb +35 -0
  5. data/lib/generators/redde/photo/templates/controller.rb +30 -0
  6. data/lib/generators/redde/photo/templates/create_photos.rb +13 -0
  7. data/lib/generators/redde/photo/templates/photo.rb +7 -0
  8. data/lib/generators/redde/photo/templates/photos/_photo.haml +5 -0
  9. data/lib/generators/redde/photo/templates/photos/_photos.haml +22 -0
  10. data/lib/generators/redde/photo/templates/photos/create.js.erb +1 -0
  11. data/lib/generators/redde/photo/templates/photos/destroy.js.erb +1 -0
  12. data/lib/generators/redde/photo/templates/uploader.rb +60 -0
  13. data/lib/redde/version.rb +1 -1
  14. data/lib/redde.rb +1 -1
  15. data/spec/generators/photo_generator_spec.rb +33 -0
  16. metadata +15 -35
  17. data/lib/generators/redde/deploy/deploy_generator.rb +0 -34
  18. data/lib/generators/redde/deploy/templates/Capfile +0 -4
  19. data/lib/generators/redde/deploy/templates/deploy.rb +0 -33
  20. data/lib/generators/redde/deploy/templates/recipes/base.rb +0 -16
  21. data/lib/generators/redde/deploy/templates/recipes/check.rb +0 -13
  22. data/lib/generators/redde/deploy/templates/recipes/database.rb +0 -66
  23. data/lib/generators/redde/deploy/templates/recipes/imagemagick.rb +0 -8
  24. data/lib/generators/redde/deploy/templates/recipes/memcached.rb +0 -10
  25. data/lib/generators/redde/deploy/templates/recipes/monit.rb +0 -35
  26. data/lib/generators/redde/deploy/templates/recipes/nginx.rb +0 -26
  27. data/lib/generators/redde/deploy/templates/recipes/nodejs.rb +0 -10
  28. data/lib/generators/redde/deploy/templates/recipes/postfix.rb +0 -37
  29. data/lib/generators/redde/deploy/templates/recipes/rbenv.rb +0 -17
  30. data/lib/generators/redde/deploy/templates/recipes/templates/database.yml.erb +0 -8
  31. data/lib/generators/redde/deploy/templates/recipes/templates/dkim-filter.conf.erb +0 -57
  32. data/lib/generators/redde/deploy/templates/recipes/templates/dkim-filter.defaults.erb +0 -11
  33. data/lib/generators/redde/deploy/templates/recipes/templates/dkim-keys.conf.erb +0 -2
  34. data/lib/generators/redde/deploy/templates/recipes/templates/gemrc.erb +0 -1
  35. data/lib/generators/redde/deploy/templates/recipes/templates/main.cf.erb +0 -43
  36. data/lib/generators/redde/deploy/templates/recipes/templates/memcached.erb +0 -47
  37. data/lib/generators/redde/deploy/templates/recipes/templates/monit_monitrc.erb +0 -21
  38. data/lib/generators/redde/deploy/templates/recipes/templates/monit_nginx.erb +0 -5
  39. data/lib/generators/redde/deploy/templates/recipes/templates/monit_unicorn.erb +0 -14
  40. data/lib/generators/redde/deploy/templates/recipes/templates/nginx_unicorn.erb +0 -28
  41. data/lib/generators/redde/deploy/templates/recipes/templates/unicorn.rb.erb +0 -36
  42. data/lib/generators/redde/deploy/templates/recipes/templates/unicorn_init.erb +0 -84
  43. data/lib/generators/redde/deploy/templates/recipes/unicorn.rb +0 -27
  44. data/spec/dummy/log/test.log +0 -53411
  45. data/spec/generators/deploy_generator_spec.rb +0 -29
data/.gitignore CHANGED
@@ -21,4 +21,5 @@ tmp
21
21
 
22
22
  /spec/dummy/public/uploads
23
23
  /spec/dummy/log
24
+ /spec/dummy/log/test.log
24
25
  /spec/dummy/db/*sqlite3
data/README.md CHANGED
@@ -43,6 +43,12 @@ To generate admin views and controller for a model, enter:
43
43
  Add `admin.scss` and `admin.js` to assets precompilation in config/production.rb:
44
44
 
45
45
  config.assets.precompile += %w( admin.js admin.css )
46
+
47
+ ## Добавление фотографий
48
+
49
+ rails g redde:photo
50
+
51
+ создаст scaffold для модели Photo с полиморфной связью
46
52
 
47
53
  ## Gemset dependenсies
48
54
 
@@ -1,11 +1,14 @@
1
1
  .page-header
2
- overflow: hidden
3
2
  background: #F1F5F9
4
3
  border-bottom: 1px solid #DADEE5
5
4
  padding: 15px 30px
6
5
  margin: 0
7
6
  border-top-right-radius: 5px
8
7
  border-top-left-radius: 5px
8
+ &:after
9
+ content: ''
10
+ display: table
11
+ clear: both
9
12
  h1
10
13
  font-size: 16px
11
14
  float: left
@@ -0,0 +1,35 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/generated_attribute'
3
+
4
+ module Redde
5
+ module Generators
6
+ class PhotoGenerator < ::Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ def self.next_migration_number(path)
11
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
12
+ end
13
+
14
+ def copy_controller
15
+ template "controller.rb", "app/controllers/admin/photos_controller.rb"
16
+ end
17
+
18
+ def copy_views
19
+ directory "photos", "app/views/admin/photos"
20
+ end
21
+
22
+ def copy_model
23
+ template "photo.rb", "app/models/photo.rb"
24
+ end
25
+
26
+ def copy_uploader
27
+ template "uploader.rb", "app/uploaders/photo_uploader.rb"
28
+ end
29
+
30
+ def copy_migration
31
+ migration_template "create_photos.rb", "db/migrate/create_photos.rb"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,30 @@
1
+ class Admin::PhotosController < ActionController::Base
2
+
3
+ def sort
4
+ params[:photo].each_with_index do |id, idx|
5
+ p = Photo.find(id)
6
+ p.position = idx
7
+ p.save
8
+ end
9
+ render :nothing => true
10
+ end
11
+
12
+ def create
13
+ if params[:product_id].present?
14
+ @product = Product.find(params[:product_id])
15
+ @photo = @product.photos.build(src: params[:file])
16
+ end
17
+ if @photo.save
18
+ render layout: false
19
+ else
20
+ render js: 'alert("Ошибка! Фото не загружено")'
21
+ end
22
+ end
23
+
24
+ def destroy
25
+ @photo = Photo.find(params[:id])
26
+ @photo.destroy
27
+ render 'admin/photos/destroy'
28
+ end
29
+
30
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePhotos < ActiveRecord::Migration
2
+ def change
3
+ create_table :photos do |t|
4
+ t.integer :imageable_id
5
+ t.string :imageable_type
6
+ t.integer :position
7
+ t.string :src
8
+
9
+ t.timestamps
10
+ end
11
+ add_index :photos, :imageable_id
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ class Photo < ActiveRecord::Base
2
+ belongs_to :imageable, polymorphic: true
3
+
4
+ default_scope { order(:position) }
5
+
6
+ mount_uploader :src, PhotoUploader
7
+ end
@@ -0,0 +1,5 @@
1
+ %li{class: "handle", :id => "photo_#{photo.id}"}
2
+ = link_to photo.src.url do
3
+ = image_tag photo.src.admin
4
+ %em= photo.src.to_s.gsub(/.*\/(.*)\z/,'\1')
5
+ = link_to "удалить", url_for([:admin,parent,photo]), :method => :delete, :confirm => "Точно удалить?", :remote => true, :title => "Удалить", :class => "del"
@@ -0,0 +1,22 @@
1
+ - unless parent.new_record?
2
+ =content_for(:page_sidebar) do
3
+ %h5
4
+ Фотографии
5
+ - if editable ||= false
6
+ = link_to "ред.", [:admin,parent]
7
+ .product-photos
8
+ %ul.photos#photo-list
9
+ = render :partial => "admin/photos/photo", :collection => eval("parent.#{photos.to_s}"), :as => :photo, :locals => {:parent => parent}
10
+
11
+ #preview
12
+ #drag-n-drop{:style => "display: none; margin-top: 5px;"}
13
+ #drop-zone.b-dropzone{style: 'height: 100px;', data: {"upload-url" => url_for([:admin, parent, :photos])}}
14
+ .b-dropzone__bg
15
+ .b-dropzone__txt Перетащите файлы сюда
16
+
17
+
18
+ #buttons-panel{style: 'margin-bottom: 10px;'}
19
+ .b-button.js-fileapi-wrapper
20
+ .b-button__text Загрузить файлы
21
+ %input.b-button__input.js-fileapi{:name => "files", :type => "file", :multiple => true, data: {"upload-url" => url_for([:admin, parent, :photos])}}
22
+ = photo_sortable url_for([:sort,:admin,parent,photos])
@@ -0,0 +1 @@
1
+ $("ul.photos").append('<%= escape_javascript(render "admin/photos/photo", { :photo => @photo, :parent => @parent }) %>');
@@ -0,0 +1 @@
1
+ $("li#photo_<%= @photo.id%>").remove();
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ class PhotoUploader < CarrierWave::Uploader::Base
4
+
5
+ # Include RMagick or MiniMagick support:
6
+ include CarrierWave::RMagick
7
+ # include CarrierWave::MiniMagick
8
+
9
+ # Choose what kind of storage to use for this uploader:
10
+ storage :file
11
+ # storage :fog
12
+
13
+ # Override the directory where uploaded files will be stored.
14
+ # This is a sensible default for uploaders that are meant to be mounted:
15
+ def store_dir
16
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
17
+ end
18
+
19
+ # Provide a default URL as a default if there hasn't been a file uploaded:
20
+ # def default_url
21
+ # # For Rails 3.1+ asset pipeline compatibility:
22
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
23
+ #
24
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
25
+ # end
26
+
27
+ def default_url
28
+ ActionController::Base.helpers.asset_path "missing/#{model.class.to_s.tableize}/#{version_name}.png"
29
+ end
30
+
31
+
32
+ # Process files as they are uploaded:
33
+ # process :scale => [200, 300]
34
+ #
35
+ # def scale(width, height)
36
+ # # do something
37
+ # end
38
+
39
+ # Create different versions of your uploaded files:
40
+ # version :thumb do
41
+ # process :scale => [50, 50]
42
+ # end
43
+
44
+ # Add a white list of extensions which are allowed to be uploaded.
45
+ # For images you might use something like this:
46
+ # def extension_white_list
47
+ # %w(jpg jpeg gif png)
48
+ # end
49
+
50
+ version :admin do
51
+ process :resize_and_pad => [119, 119, :transparent, ::Magick::CenterGravity]
52
+ end
53
+
54
+ # Override the filename of the uploaded files:
55
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
56
+ # def filename
57
+ # "something.jpg" if original_filename
58
+ # end
59
+
60
+ end
data/lib/redde/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Redde
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/redde.rb CHANGED
@@ -2,6 +2,6 @@ require "redde/version"
2
2
  module Redde
3
3
  require 'generators/redde/layout/layout_generator'
4
4
  require 'generators/redde/scaffold/scaffold_generator'
5
- require 'generators/redde/deploy/deploy_generator'
5
+ require 'generators/redde/photo/photo_generator'
6
6
  # Your code goes here...
7
7
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Redde::Generators::PhotoGenerator do
4
+ include GeneratorSpec::TestCase
5
+ destination File.expand_path("../../../tmp", __FILE__)
6
+
7
+ before(:all) do
8
+ prepare_destination
9
+ run_generator
10
+ end
11
+
12
+ after(:all) do
13
+ FileUtils.rm_rf 'tmp'
14
+ end
15
+
16
+ it "Generates controller" do
17
+ assert_file "app/controllers/admin/photos_controller.rb"
18
+ end
19
+
20
+ it "Generates views" do
21
+ assert_file "app/views/admin/photos/index.html.haml"
22
+ end
23
+
24
+ it "Generates model" do
25
+ assert_file "app/models/photo.rb"
26
+ end
27
+
28
+ it "Generates migration" do
29
+ files = Dir["tmp/db/migrate/*.rb"]
30
+ expect(files.map(&:to_s).join(" ").index("create_photos")).to eq 30
31
+ end
32
+
33
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-02-11 00:00:00.000000000 Z
13
+ date: 2014-02-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jquery-rails
@@ -157,33 +157,6 @@ files:
157
157
  - LICIENSE.md
158
158
  - README.md
159
159
  - Rakefile
160
- - lib/generators/redde/deploy/deploy_generator.rb
161
- - lib/generators/redde/deploy/templates/Capfile
162
- - lib/generators/redde/deploy/templates/deploy.rb
163
- - lib/generators/redde/deploy/templates/recipes/base.rb
164
- - lib/generators/redde/deploy/templates/recipes/check.rb
165
- - lib/generators/redde/deploy/templates/recipes/database.rb
166
- - lib/generators/redde/deploy/templates/recipes/imagemagick.rb
167
- - lib/generators/redde/deploy/templates/recipes/memcached.rb
168
- - lib/generators/redde/deploy/templates/recipes/monit.rb
169
- - lib/generators/redde/deploy/templates/recipes/nginx.rb
170
- - lib/generators/redde/deploy/templates/recipes/nodejs.rb
171
- - lib/generators/redde/deploy/templates/recipes/postfix.rb
172
- - lib/generators/redde/deploy/templates/recipes/rbenv.rb
173
- - lib/generators/redde/deploy/templates/recipes/templates/database.yml.erb
174
- - lib/generators/redde/deploy/templates/recipes/templates/dkim-filter.conf.erb
175
- - lib/generators/redde/deploy/templates/recipes/templates/dkim-filter.defaults.erb
176
- - lib/generators/redde/deploy/templates/recipes/templates/dkim-keys.conf.erb
177
- - lib/generators/redde/deploy/templates/recipes/templates/gemrc.erb
178
- - lib/generators/redde/deploy/templates/recipes/templates/main.cf.erb
179
- - lib/generators/redde/deploy/templates/recipes/templates/memcached.erb
180
- - lib/generators/redde/deploy/templates/recipes/templates/monit_monitrc.erb
181
- - lib/generators/redde/deploy/templates/recipes/templates/monit_nginx.erb
182
- - lib/generators/redde/deploy/templates/recipes/templates/monit_unicorn.erb
183
- - lib/generators/redde/deploy/templates/recipes/templates/nginx_unicorn.erb
184
- - lib/generators/redde/deploy/templates/recipes/templates/unicorn.rb.erb
185
- - lib/generators/redde/deploy/templates/recipes/templates/unicorn_init.erb
186
- - lib/generators/redde/deploy/templates/recipes/unicorn.rb
187
160
  - lib/generators/redde/layout/layout_generator.rb
188
161
  - lib/generators/redde/layout/templates/assets/images/admin/addphoto.png
189
162
  - lib/generators/redde/layout/templates/assets/images/admin/ajaxloader2.gif
@@ -274,6 +247,15 @@ files:
274
247
  - lib/generators/redde/layout/templates/helpers/admin_helper.rb
275
248
  - lib/generators/redde/layout/templates/layouts/admin.html.haml
276
249
  - lib/generators/redde/layout/templates/layouts/login.html.haml
250
+ - lib/generators/redde/photo/photo_generator.rb
251
+ - lib/generators/redde/photo/templates/controller.rb
252
+ - lib/generators/redde/photo/templates/create_photos.rb
253
+ - lib/generators/redde/photo/templates/photo.rb
254
+ - lib/generators/redde/photo/templates/photos/_photo.haml
255
+ - lib/generators/redde/photo/templates/photos/_photos.haml
256
+ - lib/generators/redde/photo/templates/photos/create.js.erb
257
+ - lib/generators/redde/photo/templates/photos/destroy.js.erb
258
+ - lib/generators/redde/photo/templates/uploader.rb
277
259
  - lib/generators/redde/scaffold/scaffold_generator.rb
278
260
  - lib/generators/redde/scaffold/templates/controllers/controller.rb
279
261
  - lib/generators/redde/scaffold/templates/edit.html.haml
@@ -323,13 +305,12 @@ files:
323
305
  - spec/dummy/lib/assets/.keep
324
306
  - spec/dummy/log/.keep
325
307
  - spec/dummy/log/development.log
326
- - spec/dummy/log/test.log
327
308
  - spec/dummy/public/404.html
328
309
  - spec/dummy/public/422.html
329
310
  - spec/dummy/public/500.html
330
311
  - spec/dummy/public/favicon.ico
331
- - spec/generators/deploy_generator_spec.rb
332
312
  - spec/generators/layout_generator_spec.rb
313
+ - spec/generators/photo_generator_spec.rb
333
314
  - spec/generators/scaffold_generator_spec.rb
334
315
  - spec/spec_helper.rb
335
316
  homepage: http://github.com/redde/redde
@@ -347,7 +328,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
347
328
  version: '0'
348
329
  segments:
349
330
  - 0
350
- hash: -3579218802794049855
331
+ hash: -159252183115178573
351
332
  required_rubygems_version: !ruby/object:Gem::Requirement
352
333
  none: false
353
334
  requirements:
@@ -356,7 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
356
337
  version: '0'
357
338
  segments:
358
339
  - 0
359
- hash: -3579218802794049855
340
+ hash: -159252183115178573
360
341
  requirements: []
361
342
  rubyforge_project:
362
343
  rubygems_version: 1.8.24
@@ -405,12 +386,11 @@ test_files:
405
386
  - spec/dummy/lib/assets/.keep
406
387
  - spec/dummy/log/.keep
407
388
  - spec/dummy/log/development.log
408
- - spec/dummy/log/test.log
409
389
  - spec/dummy/public/404.html
410
390
  - spec/dummy/public/422.html
411
391
  - spec/dummy/public/500.html
412
392
  - spec/dummy/public/favicon.ico
413
- - spec/generators/deploy_generator_spec.rb
414
393
  - spec/generators/layout_generator_spec.rb
394
+ - spec/generators/photo_generator_spec.rb
415
395
  - spec/generators/scaffold_generator_spec.rb
416
396
  - spec/spec_helper.rb
@@ -1,34 +0,0 @@
1
- require 'rails/generators'
2
-
3
- module Redde
4
- module Generators
5
- class DeployGenerator < ::Rails::Generators::Base
6
- source_root File.expand_path("../templates", __FILE__)
7
- desc "Redde deploy recipes generator"
8
-
9
- attr_reader :app_name, :ip, :domain
10
-
11
- argument :ip, :type => :string, :required => true, :banner => "Enter ip addres of the host"
12
-
13
- argument :domain, :type => :string, :required => false, :banner => "Enter domain name for postfix config"
14
-
15
- def generate_layout
16
- # copy Capfile
17
- template "Capfile", "Capfile"
18
-
19
- # copy deploy.rb
20
- template "deploy.rb", "config/deploy.rb"
21
-
22
- # copy capistrano recipes
23
- directory "recipes", "config/recipes"
24
- end
25
-
26
- private
27
-
28
- def app_name
29
- Rails.application.class.to_s.split("::").first.downcase || "TestApp"
30
- end
31
- end
32
-
33
- end
34
- end
@@ -1,4 +0,0 @@
1
- load 'deploy'
2
- # Uncomment if you are using Rails' asset pipeline
3
- load 'deploy/assets'
4
- load 'config/deploy' # remove this line to skip loading any of the default tasks
@@ -1,33 +0,0 @@
1
- require "bundler/capistrano"
2
-
3
- load "config/recipes/base"
4
- load "config/recipes/nginx"
5
- load "config/recipes/unicorn"
6
- load "config/recipes/database"
7
- load "config/recipes/imagemagick"
8
- load "config/recipes/nodejs"
9
- load "config/recipes/rbenv"
10
- load "config/recipes/check"
11
- load "config/recipes/monit"
12
- load "config/recipes/memcached"
13
- <% if domain.present? %>
14
- load "config/recipes/postfix"
15
- set :fqdn, "<%= domain %>"
16
- <% end %>
17
-
18
- server "<%= ip %>", :web, :app, :db, primary: true
19
-
20
- set :user, "webmaster"
21
- set :application, "<%= app_name %>"
22
- set :deploy_to, "/home/#{user}/projects/#{application}"
23
- set :deploy_via, :remote_cache
24
- set :use_sudo, false
25
-
26
- set :scm, "git"
27
- set :repository, "webmaster@<%= ip %>:<%= app_name %>"
28
- set :branch, "master"
29
-
30
- default_run_options[:pty] = true
31
- ssh_options[:forward_agent] = true
32
-
33
- after "deploy", "deploy:cleanup" # keep only the last 5 releases
@@ -1,16 +0,0 @@
1
- def template(from, to)
2
- erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
3
- put ERB.new(erb).result(binding), to
4
- end
5
-
6
- def set_default(name, *args, &block)
7
- set(name, *args, &block) unless exists?(name)
8
- end
9
-
10
- namespace :deploy do
11
- desc "Install base requirements"
12
- task :install do
13
- run "#{sudo} apt-get -y update"
14
- run "#{sudo} apt-get -y install python-software-properties build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison"
15
- end
16
- end
@@ -1,13 +0,0 @@
1
- namespace :check do
2
- desc "Make sure local git is in sync with remote."
3
- task :revision, roles: :web do
4
- unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}`
5
- puts "WARNING: HEAD is not the same as origin/#{branch}"
6
- puts "Run `git push` to sync changes."
7
- exit
8
- end
9
- end
10
- before "deploy", "check:revision"
11
- before "deploy:migrations", "check:revision"
12
- before "deploy:cold", "check:revision"
13
- end
@@ -1,66 +0,0 @@
1
- #coding: utf-8
2
- set_default(:database_host, "localhost")
3
- set_default(:database_user, "root")
4
- set_default(:database_database) { "#{application}_production" }
5
-
6
- namespace :database do
7
- desc "Install MySQL-Server with non-interactive mode"
8
- task :install, roles: :db do
9
- begin
10
- put %Q{
11
- Name: mysql-server/root_password
12
- Template: mysql-server/root_password
13
- Value:
14
- Owners: mysql-server-5.1
15
- Flags: seen
16
-
17
- Name: mysql-server/root_password_again
18
- Template: mysql-server/root_password_again
19
- Value:
20
- Owners: mysql-server-5.1
21
- Flags: seen
22
-
23
- Name: mysql-server/root_password
24
- Template: mysql-server/root_password
25
- Value:
26
- Owners: mysql-server-5.0
27
- Flags: seen
28
-
29
- Name: mysql-server/root_password_again
30
- Template: mysql-server/root_password_again
31
- Value:
32
- Owners: mysql-server-5.0
33
- Flags: seen
34
- }, "non-interactive.txt"
35
- sudo "DEBIAN_FRONTEND=noninteractive DEBCONF_DB_FALLBACK=Pipe apt-get -qq -y install mysql-server < non-interactive.txt"
36
- rescue
37
- raise
38
- ensure
39
- sudo "rm non-interactive.txt"
40
- end
41
-
42
- run "#{sudo} apt-get -y install libmysql-ruby libmysqlclient-dev"
43
- end
44
- after "deploy:install", "database:install"
45
-
46
- desc "Create a database for the app if not exists"
47
- task :create_database, roles: :db, only: {primary: true} do
48
- run "#{sudo} mysql -u #{database_user} -h #{database_host} -e 'CREATE DATABASE IF NOT EXISTS #{database_database} '"
49
- end
50
- after "deploy:setup", "database:create_database"
51
-
52
- desc "Generate the database.yml config"
53
- task :setup, roles: :app do
54
- run "mkdir -p #{shared_path}/config"
55
- template "database.yml.erb", "#{shared_path}/config/database.yml"
56
- end
57
- after "deploy:setup", "database:setup"
58
-
59
- desc "Symlink shared files and folders"
60
- task :symlink, roles: :app do
61
- run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
62
- run "rm -Rf #{release_path}/public/uploads"
63
- run "ln -s #{shared_path}/uploads #{release_path}/public/uploads"
64
- end
65
- after "deploy:finalize_update", "database:symlink"
66
- end
@@ -1,8 +0,0 @@
1
- namespace :imagemagick do
2
- desc "Install latest imagemagick"
3
- task :install, roles: :web do
4
- run "#{sudo} apt-get install -y imagemagick libmagickcore-dev libmagickwand-dev"
5
- end
6
- after "deploy:install", "imagemagick:install"
7
-
8
- end
@@ -1,10 +0,0 @@
1
- namespace :memcached do
2
- desc "Install memcached"
3
- task :install, roles: :app do
4
- run "#{sudo} apt-get -y install memcached"
5
- template "memcached.erb", "/tmp/memcached_conf"
6
- run "#{sudo} mv /tmp/memcached_conf /etc/memcached.conf"
7
- run "#{sudo} service memcached restart"
8
- end
9
- after "deploy:install", "memcached:install"
10
- end
@@ -1,35 +0,0 @@
1
- namespace :monit do
2
- desc "Install Monit"
3
- task :install do
4
- run "#{sudo} apt-get -y install monit"
5
- end
6
- after "deploy:install", "monit:install"
7
-
8
- desc "Setup all Monit configuration"
9
- task :setup do
10
- monit_config "monitrc", "/etc/monit/monitrc"
11
- nginx
12
- unicorn
13
- syntax
14
- restart
15
- end
16
- after "deploy:setup", "monit:setup"
17
-
18
- task(:nginx, roles: :web) { monit_config "nginx" }
19
- task(:unicorn, roles: :app) { monit_config "unicorn" }
20
-
21
- %w[start stop restart syntax reload].each do |command|
22
- desc "Run Monit #{command} script"
23
- task command do
24
- run "#{sudo} service monit #{command}"
25
- end
26
- end
27
- end
28
-
29
- def monit_config(name, destination = nil)
30
- destination ||= "/etc/monit/conf.d/#{name}.conf"
31
- template "monit_#{name}.erb", "/tmp/monit_#{name}"
32
- run "#{sudo} mv /tmp/monit_#{name} #{destination}"
33
- run "#{sudo} chown root #{destination}"
34
- run "#{sudo} chmod 600 #{destination}"
35
- end
@@ -1,26 +0,0 @@
1
- namespace :nginx do
2
- desc "Install Ngnix"
3
- task :install, roles: :web do
4
- run "#{sudo} sh -c 'echo \"deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main\" > /etc/apt/sources.list.d/nginx-stable-lucid.list'"
5
- run "#{sudo} apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C"
6
- run "#{sudo} apt-get -y update"
7
- run "#{sudo} apt-get -y install nginx"
8
- end
9
- after "deploy:install", "nginx:install"
10
-
11
- desc "Setup Nginx"
12
- task :setup, roles: :web do
13
- template "nginx_unicorn.erb", "/tmp/nginx_conf"
14
- run "#{sudo} mv /tmp/nginx_conf /etc/nginx/sites-enabled/#{application}"
15
- run "#{sudo} rm -f /etc/nginx/sites-enabled/default"
16
- restart
17
- end
18
- after "deploy:setup", "nginx:setup"
19
-
20
- %w[start stop restart].each do |command|
21
- desc "#{command} nginx"
22
- task command, roles: :web do
23
- run "#{sudo} service nginx #{command}"
24
- end
25
- end
26
- end
@@ -1,10 +0,0 @@
1
- namespace :nodejs do
2
- desc "Install Node.js"
3
- task :install, roles: :app do
4
- run "#{sudo} sh -c 'echo \"deb http://ppa.launchpad.net/chris-lea/node.js/ubuntu lucid main\" > /etc/apt/sources.list.d/chris-lea-node.js-lucid.list'"
5
- run "#{sudo} apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C"
6
- run "#{sudo} apt-get -y update"
7
- run "#{sudo} apt-get -y --force-yes install nodejs"
8
- end
9
- after "deploy:install", "nodejs:install"
10
- end