Permalink
Browse files

Use nginx upload module for blobstore

Testing Done:
Verified that nginx upload of files work
Verified that the old direct way of uploading files work
Deployed release 36 and ran BVTs against it.

Change-Id: I36481224884ddd8cf44feb4f0bc56e4d20673a56
  • Loading branch information...
1 parent 776f525 commit f930004d558cadd7990b736536b903c348eaabf3 @mahpat mahpat committed Sep 17, 2011
@@ -2,6 +2,7 @@
default[:blobstore][:tmp] = "/var/vcap/deploy/tmp"
default[:blobstore][:repos_path] = "/var/vcap/deploy/repos"
default[:blobstore][:storage] = "/var/vcap/storage/blobstore"
+default[:blobstore][:nginx_storage] = "/var/vcap/storage/nginx_upload"
default[:blobstore][:runner] = "vcap"
default[:blobstore][:port] = 25250
default[:blobstore][:backend_port] = 25251
@@ -11,21 +11,29 @@
package "git-core"
if node[:blobstore][:nginx]
- template "#{node[:nginx][:path]}/sites/blobstore.conf" do
+ directory node[:blobstore][:nginx_storage] do
+ owner node[:blobstore][:runner]
+ group node[:blobstore][:runner]
+ mode "0755"
+ recursive true
+ action :create
+ end
+
+ template File.join(node[:nginx][:path], "sites/blobstore.conf") do
source "nginx.conf.erb"
owner node[:nginx][:runner]
group node[:nginx][:runner]
mode "0644"
notifies :restart, "service[nginx]"
end
else
- file "#{node[:nginx][:path]}/sites/blobstore.conf" do
+ file File.join(node[:nginx][:path], "sites/blobstore.conf") do
action :delete
notifies :restart, "service[nginx]", :immediately
end
end
-directory "#{node[:blobstore][:path]}/shared" do
+directory File.join(node[:blobstore][:path], "shared") do
owner node[:blobstore][:runner]
group node[:blobstore][:runner]
mode "0755"
@@ -40,23 +48,23 @@
end
%w{config gems logs}.each do |dir|
- directory "#{node[:blobstore][:path]}/shared/#{dir}" do
+ directory File.join(node[:blobstore][:path], "shared", dir) do
owner node[:blobstore][:runner]
group node[:blobstore][:runner]
mode "0755"
action :create
end
end
-template "#{node[:blobstore][:path]}/shared/config/simple_blobstore_server.yml" do
+template File.join(node[:blobstore][:path], "shared/config/simple_blobstore_server.yml") do
source "simple_blobstore_server.yml.erb"
owner node[:blobstore][:runner]
group node[:blobstore][:runner]
notifies :restart, "service[blobstore]"
end
deploy_revision node[:blobstore][:path] do
- repo "#{node[:blobstore][:repos_path]}/bosh"
+ repo File.join(node[:blobstore][:repos_path], "bosh")
user node[:blobstore][:runner]
revision "HEAD"
migrate false
@@ -72,9 +80,9 @@
symlinks({})
before_migrate do
- execute "#{node[:ruby][:path]}/bin/bundle install --deployment --without development test --local --path #{node[:blobstore][:path]}/shared/gems" do
+ execute "#{File.join(node[:ruby][:path], "bin/bundle")} install --deployment --without development test --local --path #{File.join(node[:blobstore][:path], "shared/gems")}" do
ignore_failure true
- cwd "#{release_path}/simple_blobstore_server"
+ cwd File.join(release_path, "simple_blobstore_server")
end
end
end
@@ -40,6 +40,30 @@ server {
proxy_pass http://backend;
}
+ # Handle file upload
+ location = /resources {
+ # Pass altered request body to this location
+ upload_pass @upload;
+
+ # Store files to this directory
+ upload_store <%= node[:blobstore][:nginx_storage] %>;
+
+ # Allow uploaded files to be read only by user
+ upload_store_access user:r;
+
+ # Set specified fields in request body
+ 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_max_file_size 0;
+ upload_cleanup 400 404 499 500-505;
+ }
+
+ location @upload {
+ proxy_pass http://backend;
+ }
+
location /protected/ {
internal;
alias <%= node[:blobstore][:storage] %>/;
@@ -3,3 +3,4 @@
default[:nginx][:runner] = "vcap"
default[:nginx][:worker_processes] = 2
default[:nginx][:worker_connections] = 8192
+default[:nginx][:upload_module_version] = "2.0.12"
@@ -5,13 +5,18 @@
package "libpcre3-dev"
package "libssl-dev"
-remote_file "/tmp/nginx-#{node[:nginx][:version]}.tar.gz" do
+remote_file File.join("/tmp", "nginx-#{node[:nginx][:version]}.tar.gz") do
source "http://nginx.org/download/nginx-#{node[:nginx][:version]}.tar.gz"
- not_if { ::File.exists?("/tmp/nginx-#{node[:nginx][:version]}.tar.gz") }
+ not_if { ::File.exists?(File.join("/tmp", "nginx-#{node[:nginx][:version]}.tar.gz")) }
end
-%w[logs run sites].each do |dir|
- directory "#{node[:nginx][:path]}/#{dir}" do
+remote_file File.join("/tmp", "nginx_upload_module-#{node[:nginx][:upload_module_version]}.tar.gz") do
+ source "http://www.grid.net.ru/nginx/download/nginx_upload_module-#{node[:nginx][:upload_module_version]}.tar.gz"
+ not_if { ::File.exists?(File.join("/tmp", "nginx_upload_module-#{node[:nginx][:upload_module_version]}.tar.gz")) }
+end
+
+%w[logs run sites upload].each do |dir|
+ directory File.join(node[:nginx][:path], dir) do
owner node[:nginx][:runner]
group node[:nginx][:runner]
mode "0755"
@@ -23,21 +28,20 @@
bash "Install Nginx" do
cwd "/tmp"
code <<-EOH
+ tar xzf nginx_upload_module-#{node[:nginx][:upload_module_version]}.tar.gz
tar xzf nginx-#{node[:nginx][:version]}.tar.gz
cd nginx-#{node[:nginx][:version]}
- ./configure --prefix=#{node[:nginx][:path]}
+ ./configure --prefix=#{node[:nginx][:path]} --add-module=#{File.join("/tmp", "nginx_upload_module-" + node[:nginx][:upload_module_version])}
make
make install
EOH
- not_if do
- ::File.exists?("#{node[:nginx][:path]}/sbin/nginx")
- end
+ not_if "#{File.join(node[:nginx][:path], "sbin/nginx")} -V 2>&1 | grep nginx_upload_module"
end
runit_service "nginx"
template "nginx.conf" do
- path "#{node[:nginx][:path]}/conf/nginx.conf"
+ path File.join(node[:nginx][:path], "conf/nginx.conf")
source "nginx.conf.erb"
owner node[:nginx][:runner]
group node[:nginx][:runner]
@@ -64,6 +64,7 @@ def authorized?
post "/resources" do
if params[:content] && params[:content][:tempfile]
+ # Process uploads coming directly to the simple blobstore
object_id = generate_object_id
file_name = get_file_name(object_id)
@@ -72,6 +73,17 @@ def authorized?
FileUtils.mkdir_p(File.dirname(file_name))
FileUtils.copy_file(tempfile.path, file_name)
+ status(200)
+ content_type(:text)
+ object_id
+ elsif params["content.name"] && params["content.path"]
+ # Process uploads arriving via nginx
+ object_id = generate_object_id
+ file_name = get_file_name(object_id)
+
+ FileUtils.mkdir_p(File.dirname(file_name))
+ FileUtils.mv(params["content.path"], file_name)
+
status(200)
content_type(:text)
object_id

0 comments on commit f930004

Please sign in to comment.