gpt4 book ai didi

ruby-on-rails-3 - 在链接(符号链接(symbolic link))文件之前要求 Capistrano 运行任务

转载 作者:行者123 更新时间:2023-12-04 06:55:37 26 4
gpt4 key购买 nike

我一直在尝试编写一个 capistrano 脚本,其中我已将配置文件从我的应用程序目录 (support/config/#{rails_env}) 复制到 shared 目录 Capistrano 中的(共享/配置)

rails_env => '暂存'

因此,当 capistrano 运行第一次时,它会将文件从 support/config/#{rails_env} 目录复制到 shared/config 目录,但它需要在 capistrano 链接文件之前运行它,即在完成之前

设置:linked_files,%w{config/api_config.yml}

这样链接任务就不会失败(因为它要求任务要求文件存在于共享目录中)

这是我的 Capfile(没什么特别的,因为大部分内容都是我的 capistrno 完成的)

set :application, 'custom-api'
set :repo_url, ''

# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :rails_env, 'staging'
set :deploy_to, '/var/apps/staging/custom-api'
set :scm, :git

set :format, :pretty
set :log_level, :debug
set :rvm_type, :user # Defaults to: :auto
set :rvm_ruby_version, 'ruby-1.9.3@484@custom-api'
#set :rvm_custom_path, '~/.myveryownrvm' # only needed if not detected
# set :pty, true
set :linked_files, %w{config/mongoid.yml config/api_config.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

#set :default_env, { path: "$HOME/.rvm/#{}:$PATH" }
set :keep_releases, 5
#SSHKit.config.command_map[:cp_r] = "cp -r"

## Need to run before the file is linked
#before 'deploy:[task_name]' , 'deploy:copy_files'

namespace :deploy do
desc 'Copy files from application to shared directory'
## copy the files to the shared directories
task :copy_files do
on roles(:app) do
execute :cp ,'-r',release_path.join('support/config'),shared_path
end
end

desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
end

after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
after :finishing, 'deploy:cleanup'
end

我只需要做类似的事情

在 'deploy:[task_name]' 之前,'deploy:copy_files'

添加注释:使用 Capistrno 3.0.1

最佳答案

根据他们的 documentation ,该任务称为 deploy:symlink:shared。我会像你的例子一样装饰它:

before 'deploy:symlink:shared', 'deploy:copy_files'

当您装饰实际任务时请注意,每次调用该任务时都会调用它。

关于ruby-on-rails-3 - 在链接(符号链接(symbolic link))文件之前要求 Capistrano 运行任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21996483/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com