Capistrano创建任务以更改当前符号链接

时间:2014-02-17 13:19:06

标签: deployment capistrano web-deployment capistrano3

我正在尝试为我的网站设置Capistrano部署,我已经部署了工作,所有身份验证都很好,但我主持了Media temple,因此默认的符号链接将无法正常运行,因为apache无法访问该路径为当前指定的最新版本。

我正在尝试创建一个取消链接当前符号链接的任务,然后使用相对路径重新创建它,但是Capistrano文档严重缺乏,我无法在任何地方找到有关如何设置它的更多信息。

我尝试过使用sh,但是这似乎是在我的计算机上而不是在服务器上运行命令,找不到运行命令,我尝试执行但找不到正确的格式来执行rm或ln之类的操作,等...

目前我正在尝试以下方法:

namespace :deploy do

  desc "Change HTML Symlink to relative path"
  task :create_symlink do
    #latest_release_relative = relative_path(deploy_to, release_path + '/html')
    #sh "rm -f #{current_path} && ln -s #{latest_release_relative} #{current_path}"
    #sh "echo #{File.basename release_path}"
    info "echo Modifying symlink to be relative"
    #run "rm -d #{current_path}"
    #run "ln releases/#{File.basename release_path} #{current_path}"
    #execute :rm, '-d', #{current_path}
  end

  desc "Create environment file"
  task :create_env_conf
  file 'env.conf' do |t|
    sh "touch env.conf"
  end

end

after :deploy, "deploy:create_symlink", "deploy:create_env_conf"

1 个答案:

答案 0 :(得分:8)

经过大量的反复试验,我发现问题是那个;

  1. 需要在cap v3

  2. 中使用execute
  3. 需要cd&then&&&用于运行特定于目录的命令

  4. Capistrano需要更多文档......

  5. 这就是我的工作方式,我认为有更好的方法可以使用Capistrano 3,但我找不到足够的文档描述如何在任何地方工作。

    #config valid only for Capistrano 3.1
    lock '3.1.0'
    
    set :application, 'prism-credentials'
    set :repo_url, 'REPO URL'
    
    # Default deploy_to directory is /var/www/my_app
    set :deploy_to, 'DEPLOY FOLDER'
    
    # Default value for keep_releases is 5
    set :keep_releases, 5
    
    set :branch, "master"
    if ENV['branch']
        set :branch, ENV['branch']
    end
    
    namespace :deploy do
    
      desc "Change HTML Symlink to relative path"
      task :create_symlink do
        on roles(:app) do
    
            #execute "ls -l"
            info "Modifying symlink to be relative"
            execute "rm -d #{current_path}"
    
            info "Deleted current symlink"
            execute "cd ../DEPLOY FOLDER && ln -s ./releases/#{File.basename release_path} current"
            info "Created relative current symlink"
    
            execute "cd ~/../DEPLOY FOLDER && touch env.conf && echo 'live' >> env.conf"
            info "Created environment file"
    
        end
      end
    
    end
    
    after :deploy, "deploy:create_symlink"