使用 Capistrano 的 Carrierwave 文件

发布于 2024-12-29 21:27:08 字数 509 浏览 2 评论 0原文

我使用 Rails 3.2 以及 asset 和 Carrierwave 来上传一些图像,它们存储在 /public/uploads/photo/..... 但是当我执行 cap:deploy (使用 capistrano)时,我当前的目录应用程序不包含我上传的文件,因为 capistrano 制作了一个新版本....

=== 更新 ===

毕竟我

在里面使用了这个:部署命名空间

   task :symlink_uploads do
     run "ln -nfs #{shared_path}/uploads  #{release_path}/public/uploads"
   end

及之后:

after 'deploy:update_code', 'deploy:symlink_uploads'

=== 重新更新 ===

@tristam 的解决方案是解决此问题的最佳方法。

I'm using rails 3.2 with asset and carrierwave for upload some images, they store in /public/uploads/photo/.....
but when I do a cap:deploy (with capistrano) my current directory application doesn't contain the files I uploaded, because capistrano make a new version ....

=== Update ===

After all I use this :

inside :deploy namespace

   task :symlink_uploads do
     run "ln -nfs #{shared_path}/uploads  #{release_path}/public/uploads"
   end

and after:

after 'deploy:update_code', 'deploy:symlink_uploads'

=== Re Update ===

The solution of @tristanm is the best way to solve this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

人事已非 2025-01-05 21:27:08

怎么样:

# config/deploy.rb
set :shared_children, shared_children + %w{public/uploads}

:shared_children 默认为 %w(public/system log tmp/pids) 所以我们只是扩展这个列表。

编辑:

更改 :shared_children 后,不要忘记运行 cap deploy:setup ,以便在 shared< 下创建新目标/代码>。

编辑 Capistrano 3:

Capistrano 3 使用 linked_dirs 设置,并且不再将 public/system 指定为默认值。

set :linked_dirs, fetch(:linked_dirs) + %w{public/system public/uploads}

How about this:

# config/deploy.rb
set :shared_children, shared_children + %w{public/uploads}

:shared_children defaults to %w(public/system log tmp/pids) so we're just expanding this list.

EDIT:

Don't forget to run cap deploy:setup after changing :shared_children so that the new targets are created under shared.

EDIT Capistrano 3:

Capistrano 3 uses the linked_dirs setting and doesn't specify public/system as a default anymore.

set :linked_dirs, fetch(:linked_dirs) + %w{public/system public/uploads}

青萝楚歌 2025-01-05 21:27:08

使用 Capistrano 3,无需重新部署。

就像 @tristam 提到的,将其添加到您的 config/deploy.rb

# config/deploy.rb
set :linked_dirs, fetch(:linked_dirs) + %w{public/uploads}

让 capistrano 创建共享/公共/上传

cap deploy:check:linked_dirs

现在 cap 可以创建符号链接

cap deploy:symlink:shared

最后,如果您有上传的备份,您可以将它们放在共享/公共/上传/中,它们应该可以工作而无需重新部署。

With Capistrano 3 and without needing to redeploy.

Like @tristanm mentioned add this to your config/deploy.rb

# config/deploy.rb
set :linked_dirs, fetch(:linked_dirs) + %w{public/uploads}

To have capistrano create shared/public/uploads

cap deploy:check:linked_dirs

Now cap can create the symlink

cap deploy:symlink:shared

Finally, if you have backups of the uploads you can put them in shared/public/uploads/ and they should work without needing to redeploy.

绅士风度i 2025-01-05 21:27:08

Capistrano 为每个部署创建新目录。

但也有一些例外。例如,日志文件在部署目录之间共享,因为它们只是符号链接。您还必须为公共/上传创建符号链接。

这是命令:

run <<-CMD
  rm -rf #{latest_release}/public/uploads &&
  ln -s #{shared_path}/uploads #{latest_release}/public/uploads
CMD

Capistrano creates new directory for every deploy.

There are some exceptions to it. For example, the log files are shared between the deployment directories because they are just symlinks. You have to create a symlink for public/uploads as well.

Here is the command:

run <<-CMD
  rm -rf #{latest_release}/public/uploads &&
  ln -s #{shared_path}/uploads #{latest_release}/public/uploads
CMD
幻想少年梦 2025-01-05 21:27:08

转到您的应用服务器共享文件夹并创建上传目录。

mkdir uploads

在您的deploy.rb文件中,在部署命名空间下插入这些代码

任务:symlink_uploads执行

“rm -rf” #{latest_release}/public/uploads && ln -nfs #{shared_pa​​th}/uploads #{latest_release}/public/uploads"

结束

之后 'deploy:update_code', 'deploy:symlink_uploads'

现在删除已经存在的旧文件,因为它们将不起作用。上传新文件并再次部署您的应用程序。现在应该可以了。

Go to your app server shared folder and create an uploads directory.

mkdir uploads

In your deploy.rb file insert these codes under deploy namespace

task :symlink_uploads do

run "rm -rf #{latest_release}/public/uploads && ln -nfs #{shared_path}/uploads #{latest_release}/public/uploads"

end

after 'deploy:update_code', 'deploy:symlink_uploads'

Now delete the old files present already as they won't work. Upload a new file and cap deploy your app again. It should work now.

纵情客 2025-01-05 21:27:08

使用 Capistrano 3,我刚刚将此行添加到我的 config/deploy.rb

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}

然后,运行:

$ cap production deploy

Using Capistrano 3, I just added this line to my config/deploy.rb

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}

Then, run:

$ cap production deploy
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文