2

我目前正在尝试使用 Capistrano 进行我的第一次 Rails 部署,但我遇到了我无法克服的障碍。在cap deploy我收到错误“ mkdir: cannot create directory/public'`”期间。

相关细节:

  • 导轨版本:3.2.6
  • Capistrano 版本:2.13.5
  • 在 Dreamhost 上运行
  • 我正在预编译我的资产(我怀疑这是问题的一部分),所以我已经进入load 'deploy/assets'了我的 Capfile。

我已经遵循了这里的指示:http ://wiki.dreamhost.com/Capistrano大部分情况下,以及在网上搜索有关 Capistrano 的许多其他文章。

部署.rb

require "bundler/capistrano"

ssh_options[:forward_agent] = true
ssh_options[File.join(ENV["HOME"], ".ssh", "id_rsa-dreamhost")]

set :application, "<app>"
set :repository,  "git@bitbucket.org:<gituser>/#{application}.git"
set :server_name, "<host>"
set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent     guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or   `none`
set :checkout, "export"
set :deploy_via, :remote_cache
set :branch, "master"

set :base_path, "/home/<user>/<domain>"
set :deploy_to, "#{base_path}/#{application}"
set :keep_releases, 3

set :user, '<user>'
set :runner, '<user>'

set :use_sudo, false

default_run_options[:pty] = true

set :shared_path, "/home/<user>/<shared_folder>"
set :release_path, "#{base_path}/#{application}"

role :web, "<host>"                          # Your HTTP server, Apache/etc
role :app, "<host>"                          # This may be the same as your `Web` server
role :db,  "<host>", :primary => true # This is where Rails migrations will run

# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"

# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
  task :start do ; end
  task :stop do ; end

  desc "Restart the app by touching the restart.txt file."
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "touch #{File.join(current_path,'tmp','restart.txt')}"
  end

  desc "Update the environment-specific files from the shared folder."
  task :symlink_shared, :roles => [:app] do
    run "ln -s #{shared_path}/app_config.yml #{release_path}/config/"

    run "rm #{release_path}/config/database.yml"
    run "ln -s #{shared_path}/database.yml #{release_path}/config/"

    run "rm #{release_path}/public/.htaccess"
    run "ln -s #{shared_path}/.htaccess #{release_path}/public/"
  end
end

before "deploy:restart", "deploy:symlink_shared"
after "deploy:update_code", "deploy:migrate"

上限部署的输出:设置

* 2012-12-23 16:49:27 executing `deploy:setup'
  * executing "mkdir -p /home/<user>/<domain>/<app> /home/<user>/<domain>/<app>/releases   /home/<user>/<shared_folder> /home/<user>/<shared_folder>/system  /home/<user>/<shared_folder>/log /home/<user>/<shared_folder>/pids"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 263ms
  * executing "chmod g+w /home/<user>/<domain>/<app>  /home/<user>/<domain>/<app>/releases /home/<user>/<shared_folder>  /home/<user>/<shared_folder>/system /home/<user>/<shared_folder>/log  /home/<user>/<shared_folder>/pids"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 261ms

上限部署的输出:检查

* 2012-12-23 16:49:45 executing `deploy:check'
  * executing "test -d /home/<user>/<domain>/<app>/releases"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 265ms
  * executing "test -w /home/<user>/<domain>/<app>"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 256ms
  * executing "test -w /home/<user>/<domain>/<app>/releases"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 256ms
  * executing "which git"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 259ms
  * executing "test -w /home/<user>/<shared_folder>"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 263ms
You appear to have all necessary dependencies installed

上限输出:部署

* 2012-12-23 16:51:41 executing `deploy'
  * 2012-12-23 16:51:41 executing `deploy:update'
 ** transaction: start
  * 2012-12-23 16:51:41 executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote git@bitbucket.org:<gituser>/<app>.git master"
    command finished in 1102ms
  * executing "if [ -d /home/<user>/<shared_folder>/cached-copy ]; then cd /home/<user>/<shared_folder>/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 42dfb6a3f529e2293192f5e22c3214b7da55c9b4 && git clean -q -d -x -f; else git clone -q git@bitbucket.org:<gituser>/<app>.git /home/<user>/<shared_folder>/cached-copy && cd /home/<user>/<shared_folder>/cached-copy && git checkout -q -b deploy 42dfb6a3f529e2293192f5e22c3214b7da55c9b4; fi"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 3233ms
    copying the cached version to /home/<user>/<domain>/<app>
  * executing "cp -RPp /home/<user>/<shared_folder>/cached-copy /home/<user>/<domain>/<app> && (echo 42dfb6a3f529e2293192f5e22c3214b7da55c9b4 > /home/<user>/<domain>/<app>/REVISION)"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 338ms
  * 2012-12-23 16:51:47 executing `deploy:finalize_update'
    triggering before callbacks for `deploy:finalize_update'
  * 2012-12-23 16:51:47 executing `deploy:assets:symlink'
  * executing "ls -x /home/<user>/<domain>/<app>/releases"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 252ms
  * executing "rm -rf /public/assets &&\\\n        mkdir -p /public &&\\\n        mkdir -p /home/<user>/<shared_folder>/assets &&\\\n        ln -s /home/<user>/<shared_folder>/assets /public/assets"
    servers: ["<host>"]
    [<host>] executing command
 ** [out :: <host>] mkdir: cannot create directory `/public'
 ** [out :: <host>] : Permission denied
    command finished in 268ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/<user>/<domain>/<app>; true"
    servers: ["<host>"]
    [<host>] executing command
    command finished in 265ms
failed: "sh -c 'rm -rf /public/assets &&\\\n        mkdir -p /public &&\\\n        mkdir -p /home/<user>/<shared_folder>/assets &&\\\n        ln -s /home/<user>/<shared_folder>/assets /public/assets'" on <host>

您可以在输出底部附近看到 Permission denied 错误,以及最后失败的 shell 命令。我不知道为什么它/public尝试对public. 我觉得我在某处遗漏了一个变量引用,该引用应该预先添加到 mkdir 命令中,但是我读过的所有文档都没有表明这一点。

我会很感激我能得到的任何帮助,并在此先感谢。

4

1 回答 1

1

请不要自行release_path设置shared_path。让 Capistrano 自动解决。

但是你应该deploy_to正确设置:

set :deploy_to, "/home/<user>/<domain>/<application>"

还要小心变量。Capistrano的set语法并不意味着变量可用于替换。您的问题发生是因为"#{base_path}/"is nil 并评估为"/".

在Capistrano的配置 wiki 上了解更多信息。

于 2012-12-24T01:25:43.980 回答