Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 使用capistrano deploy保留最新版本的public/uploads文件夹_Ruby On Rails 4_Deployment_Capistrano_Production - Fatal编程技术网

Ruby on rails 4 使用capistrano deploy保留最新版本的public/uploads文件夹

Ruby on rails 4 使用capistrano deploy保留最新版本的public/uploads文件夹,ruby-on-rails-4,deployment,capistrano,production,Ruby On Rails 4,Deployment,Capistrano,Production,我使用Rails 4和Capistrano在Ubuntu 14.04服务器上部署,我的用户能够上传存储在/public/uploads中的文件。此文件夹应始终为新版本保留,并且不应从git存储库获取文件 在阅读了一些指南后,我遵循了以下步骤: 将此添加到我的deploy.rb: set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} set :linked_dirs, fe

我使用Rails 4和Capistrano在Ubuntu 14.04服务器上部署,我的用户能够上传存储在
/public/uploads
中的文件。此文件夹应始终为新版本保留,并且不应从git存储库获取文件

在阅读了一些指南后,我遵循了以下步骤:

将此添加到我的
deploy.rb

set :linked_dirs,  %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :linked_dirs, fetch(:linked_dirs) + %w{public/uploads}
将此添加到我的
/.gitignore

# Ignore uploads
/public/uploads
正在删除我当前git存储库中的文件夹:

git rm -r --cached public/uploads
现在,如果我运行
cap deploy:setup
我会得到以下错误:

Stage not set, please call something such as `cap production deploy`, where production is a stage you have defined.
如果我定义了阶段
生产
部署开始,但我很早就中止了:

cap aborted!
Don't know how to build task 'deploy:setup' (see --tasks)
如果我使用常规命令部署
cap production deploy
一切正常,但是
public/uploads/
文件夹将像更改之前一样更新

不确定我是否只是错过了setup命令,或者在设置过程中是否犯了错误。我的
deploy.rb
如下所示:

# Change these
server 'ip', port: port, roles: [:web, :app, :db], primary: true

set :repo_url,        'git@github.com:blabla/bla.git'
set :application,     'blub'
set :user,            'blib'
set :puma_threads,    [4, 16]
set :puma_workers,    0

set :pty,             true
set :use_sudo,        false
set :stage,           :production
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.log"
set :ssh_options,     { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true  # Change to false when not using ActiveRecord

## Defaults:
# set :scm,           :git
# set :branch,        :master
# set :format,        :pretty
# set :log_level,     :debug
# set :keep_releases, 5

## Linked Files & Directories (Default None):
set :linked_dirs,  %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :linked_dirs, fetch(:linked_dirs) + %w{public/uploads}
#set :linked_files, %w{config/database.yml}

namespace :puma do
  desc 'Create Directories for Puma Pids and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
    end
  end

  before :start, :make_dirs
end

namespace :deploy do
  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) do
      unless `git rev-parse HEAD` == `git rev-parse origin/master`
        puts "WARNING: HEAD is not the same as origin/master"
        puts "Run `git push` to sync changes."
        exit
      end
    end
  end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart', 'puma:start'
      invoke 'deploy'
    end
  end

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:restart'
    end
  end

  before :starting,     :check_revision
  after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :restart
end


namespace :sake do
  desc "Run a task on a remote server."
  # run like: cap staging sake:invoke task="a_certain_task"
  task :invoke do
    on roles(:all) do |h|
      execute "cd #{fetch(:deploy_to)}/current && bundle exec rake #{ENV['task']} RAILS_ENV=#{fetch(:rails_env)}"
    end
  end
end


# ps aux | grep puma    # Get puma pid
# kill -s SIGUSR2 pid   # Restart puma
# kill -s SIGTERM pid   # Stop puma

在生产中的
共享
目录中是否有
公用/上传
文件夹?独立于此-您只需将
public/uploads
放在第一个
集合中:linked_dirs
,需要设置两次。哦,是的,我认为这是个错误。在生产中,
shared
目录中有
public/uploads
文件夹,但在另一个
upload
文件夹中,图像的路径是
/public/upload/upload
,而不是
public/upload