Benchmark nginx upload module and save docs/configs. Turn off upload module temporary. Replace passenger to unicron, tune. Remove compass dependency to avoid deprecation message. Remove rake deprecation message. Tune import script. Refs #2261

This commit is contained in:
Pavel Chipiga 2011-12-05 20:22:20 +02:00
parent 2f5ce7cebe
commit 37e7f757d9
10 changed files with 100 additions and 48 deletions

View File

@ -12,7 +12,7 @@ gem 'cancan', '~> 1.6.7'
#gem 'bitmask_attributes' #gem 'bitmask_attributes'
gem "haml-rails", '~> 0.3.4' gem "haml-rails", '~> 0.3.4'
gem "compass", '~> 0.11.5' # gem "compass", '~> 0.11.5' # update when it will be needed
gem 'jammit' gem 'jammit'
gem "yui-compressor", "0.9.5" # Higher versions depends on Platform gem which conflicts with Platform model gem "yui-compressor", "0.9.5" # Higher versions depends on Platform gem which conflicts with Platform model
gem 'rails3-jquery-autocomplete' gem 'rails3-jquery-autocomplete'
@ -33,7 +33,7 @@ gem 'delayed_job'
# gem 'actionwebservice' #, :git => 'git://github.com/ywen/actionwebservice.git' # gem 'actionwebservice' #, :git => 'git://github.com/ywen/actionwebservice.git'
gem "rails-xmlrpc", '~> 0.3.6' # :git => 'git://github.com/chipiga/rails-xmlrpc.git' gem "rails-xmlrpc", '~> 0.3.6' # :git => 'git://github.com/chipiga/rails-xmlrpc.git'
gem 'passenger', '~> 3.0.11' # gem 'passenger', '~> 3.0.11'
gem 'unicorn', '~> 4.1.1' gem 'unicorn', '~> 4.1.1'
group :production do group :production do

View File

@ -53,13 +53,8 @@ GEM
capistrano (>= 1.0.0) capistrano (>= 1.0.0)
capistrano_colors (0.5.5) capistrano_colors (0.5.5)
chronic (0.6.6) chronic (0.6.6)
chunky_png (1.2.5)
cocaine (0.2.0) cocaine (0.2.0)
columnize (0.3.5) columnize (0.3.5)
compass (0.11.5)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
daemon_controller (0.2.6) daemon_controller (0.2.6)
daemons (1.1.4) daemons (1.1.4)
delayed_job (2.1.4) delayed_job (2.1.4)
@ -78,7 +73,6 @@ GEM
factory_girl (~> 2.3.0) factory_girl (~> 2.3.0)
railties (>= 3.0.0) railties (>= 3.0.0)
fastthread (1.0.7) fastthread (1.0.7)
fssm (0.2.7)
grit (2.4.1) grit (2.4.1)
diff-lcs (~> 1.1) diff-lcs (~> 1.1)
mime-types (~> 1.15) mime-types (~> 1.15)
@ -190,7 +184,6 @@ GEM
sexp_processor (~> 3.0) sexp_processor (~> 3.0)
russian (0.6.0) russian (0.6.0)
i18n (>= 0.5.0) i18n (>= 0.5.0)
sass (3.1.11)
sexp_processor (3.0.8) sexp_processor (3.0.8)
silent-postgres (0.1.1) silent-postgres (0.1.1)
thor (0.14.6) thor (0.14.6)
@ -221,7 +214,6 @@ DEPENDENCIES
capistrano capistrano
capistrano-ext capistrano-ext
capistrano_colors capistrano_colors
compass (~> 0.11.5)
delayed_job delayed_job
devise (~> 1.5.2) devise (~> 1.5.2)
factory_girl_rails (~> 1.4.0) factory_girl_rails (~> 1.4.0)

View File

@ -8,14 +8,13 @@ working_directory File.expand_path(File.join(File.dirname(__FILE__), "..")) # a
# listen '/tmp/rosa_build.sock', :backlog => 2048 # listen '/tmp/rosa_build.sock', :backlog => 2048
# listen "/tmp/.sock", :backlog => 64 # listen "/tmp/.sock", :backlog => 64
listen 8080, :tcp_nopush => true listen 8080, :tcp_nopush => true
#
# nuke workers after 30 seconds instead of 60 seconds (the default) # nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 1200 timeout 1200
#
# feel free to point this anywhere accessible on the filesystem # feel free to point this anywhere accessible on the filesystem
pid File.expand_path(File.join(File.dirname(__FILE__), "..")) + '/tmp/pids/unicorn.pid' pid File.expand_path(File.join(File.dirname(__FILE__), "..")) + '/tmp/pids/unicorn.pid'
#
# REE # REE
# http://www.rubyenterpriseedition.com/faq.html#adapt_apps_for_cow # http://www.rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
if GC.respond_to?(:copy_on_write_friendly=) if GC.respond_to?(:copy_on_write_friendly=)

View File

@ -1,5 +1,3 @@
=== Basic bootstrap === Basic bootstrap
* rake db:drop db:setup * rake db:drop db:setup
== ==
rvmsudo passenger-install-nginx-module --nginx-source-dir=/opt/src/nginx-1.0.10 --extra-configure-flags=--add-module=/opt/src/nginx_upload_module-2.2.0

View File

@ -0,0 +1,62 @@
===================== Nginx compile
rvmsudo passenger-install-nginx-module --nginx-source-dir=/opt/src/nginx-1.0.10 --extra-configure-flags=--add-module=/opt/src/nginx_upload_module-2.2.0
===================== Nginx config
server {
listen 80;
server_name rosa-build.local www.rosa-build.local;
# server_name rosa-build.rosalab.ru;
# server_name npp-build.rosalab.ru;
client_max_body_size 1G;
root /Users/pasha/Sites/rosa-build/public;
# Match this location for the upload module
location ~* ^\/platforms\/([0-9]+)\/products/([0-9]+)$ {
error_page 405 = @rails; # fallback to rails
# pass request body to rails
# upload_pass @rails;
upload_pass @upload;
# Store files to this directory
# The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
# i.e. make sure to create /u/apps/bugle/shared/uploads_tmp/0 /u/apps/bugle/shared/uploads_tmp/1 etc.
# upload_store /u/apps/bugle/shared/uploads_tmp 1;
upload_store /tmp; # /srv/rosa_build/shared/tmp
# set permissions on the uploaded files
upload_store_access user:rw group:rw all:r;
# Set specified fields in request body this puts the original filename, new path+filename and content type in the requests params
upload_set_form_field $upload_field_name[name] "$upload_file_name";
upload_set_form_field $upload_field_name[content_type] "$upload_content_type";
upload_set_form_field $upload_field_name[path] "$upload_tmp_path";
upload_aggregate_form_field $upload_field_name[size] "$upload_file_size";
upload_pass_form_field "^.+$"; # "^theme_id$|^blog_id$|^authenticity_token$|^format$"
upload_cleanup 400 404 499 500-505;
}
location / {
try_files /system/maintenance.html $uri $uri/index.html $uri.html @rails;
}
location @rails {
passenger_enabled on;
passenger_use_global_queue on;
# rails_env production;
# proxy_pass http://localhost:8080;
# proxy_pass http://unix:/tmp/rosa_build.sock;
# proxy_redirect http://localhost/ http://$host:$server_port/;
# proxy_read_timeout 1200;
}
location @upload {
proxy_pass http://localhost:8080;
# proxy_pass http://unix:/tmp/rosa_build.sock;
# proxy_redirect http://localhost/ http://$host:$server_port/;
}
}

View File

@ -1,28 +1,29 @@
module Paperclip # Patch to use paperclip with nginx upload module
class Attachment # module Paperclip
class UploadedPath # class Attachment
attr_reader :original_filename, :content_type, :size, :path # class UploadedPath
def initialize(uploaded_file) # attr_reader :original_filename, :content_type, :size, :path
@original_filename = uploaded_file["name"].downcase # def initialize(uploaded_file)
@content_type = uploaded_file["content_type"].to_s.strip # @original_filename = uploaded_file["name"].downcase
@file_size = uploaded_file["size"].to_i # @content_type = uploaded_file["content_type"].to_s.strip
@path = uploaded_file["path"] # @file_size = uploaded_file["size"].to_i
end # @path = uploaded_file["path"]
# end
# TODO remove failed files #
# # TODO remove failed files
def to_tempfile; self; end #
# def to_tempfile; self; end
def size; @file_size; end #
# def size; @file_size; end
def close; end #
def closed?; true; end # def close; end
end # def closed?; true; end
# end
def assign_with_upload(uploaded_file) #
uploaded_file = UploadedPath.new(uploaded_file) if uploaded_file.is_a?(Hash) # def assign_with_upload(uploaded_file)
assign_without_upload(uploaded_file) # uploaded_file = UploadedPath.new(uploaded_file) if uploaded_file.is_a?(Hash)
end # assign_without_upload(uploaded_file)
alias_method_chain :assign, :upload # end
end # alias_method_chain :assign, :upload
end # end
# end

View File

@ -9,7 +9,7 @@ namespace :import do
print "Import #{name}..." print "Import #{name}..."
owner = User.find(1) # I am owner = User.find(1) # I am
# owner = Group.find(1) # Core Team # owner = Group.find(1) # Core Team
p = Project.find_or_create_by_name_and_name(name, name) {|p| p.owner = owner} p = Project.find_or_create_by_name(name) {|p| p.owner = owner}
puts p.persisted? ? "Ok!" : "Fail!" puts p.persisted? ? "Ok!" : "Fail!"
end end
puts 'DONE' puts 'DONE'