Capistrano 3使用发布目录中可用的GIT部署WordPress [英] Capistrano 3 deploy WordPress with GIT available in release dir
问题描述
我使用Capistrano 3部署我的WordPress项目(在Bedrock WP堆栈中实现: https:// github。 com / roots / bedrock )。
WordPress特别支持许多功能,这些功能可以更新生产/登台站点的实际代码(插件更新,设置文件)对于某些插件等),在各种情况下,我可能想直接从服务器将这些代码更改提交到项目GIT存储库。
所以,问题是,有没有一种方法可以配置Capistrano Deploy来将.git repo保留在relase目录中?
我认为这与Cap 2中的复制策略设置可行我找不到有关第3章的任何信息。
我已通过修改自定义部署策略来解决此问题由 https://github.com/Mixd/wp-deploy 项目实现。 p>
请注意更改后的 context.execute
行。
#用法:
#1.将此文件拖放到lib / capistrano / submodule_strategy.rb
#2.将以下内容添加到Capfile:
#require' capistrano / git'
#require'./lib/capistrano/submodule_strategy'
#3.将以下内容添加到您的config / deploy.rb
#set:git_strategy,SubmoduleStrategy
模块SubmoduleStrategy
#做普通的capistrano git会话会做的所有事情
包括Capistrano :: Git :: DefaultStrategy
#检查.git目录
def测试
测试! [-d#{repo_path} /。git]
end
#与Capistrano :: Git :: DefaultStrategy
def check
测试相同! :git,:'ls-remote',repo_url
end
def clone
git:clone,'-b',fetch(:branch),'--recursive' ,repo_url,repo_path
end
#与Capistrano :: Git :: DefaultStrategy
def update
git:remote,:update
end $相同b
$ b#将工作树放在发布分支中,
#确保子模块是最新的
#并将所有内容复制到发布路径
def release
release_branch = fetch(:release_branch,File.basename(release_path))
git:checkout,'-B',release_branch,
fetch(:remote_branch, origin /#{fetch( :branch)}))
git:submodule,:update,'--init'
#context.execute rsync -ar --exclude = .git\ *#{repo_path} /#{ release_path}
context.execute rsync -ar#{repo_path} /#{release_path}
结束
结束
此解决方案现在将发布作为GIT存储库部署到基于发布ID的自定义分支。
然后可以将其提交并推送到主存储库,以根据需要进行合并。
所有功劳归于WP-Deploy项目的创建者亚伦·托马斯(Aaron Thomas)。
I use Capistrano 3 to deploy my WordPress projects (as implemented in the Bedrock WP stack: https://github.com/roots/bedrock).
WordPress specifically supports a number of features that update the actual code of the production/staging sites (plugin updates, settings files for certain plugins etc) and there are various scenarios where I might want to commit these code changes to the project GIT repo directly from a server.
So, the question is, is there a way configure Capistrano Deploy to keep the .git repo in the relase dir?
I gather this was doable with the 'copy strategy' settings in Cap 2, but I can't find any info about this for Cap 3.
I've solved this by modifying the custom deployment strategy that's implemented by https://github.com/Mixd/wp-deploy project.
Note the changed context.execute
line.
# Usage:
# 1. Drop this file into lib/capistrano/submodule_strategy.rb
# 2. Add the following to your Capfile:
# require 'capistrano/git'
# require './lib/capistrano/submodule_strategy'
# 3. Add the following to your config/deploy.rb
# set :git_strategy, SubmoduleStrategy
module SubmoduleStrategy
# do all the things a normal capistrano git session would do
include Capistrano::Git::DefaultStrategy
# check for a .git directory
def test
test! " [ -d #{repo_path}/.git ] "
end
# same as in Capistrano::Git::DefaultStrategy
def check
test! :git, :'ls-remote', repo_url
end
def clone
git :clone, '-b', fetch(:branch), '--recursive', repo_url, repo_path
end
# same as in Capistrano::Git::DefaultStrategy
def update
git :remote, :update
end
# put the working tree in a release-branch,
# make sure the submodules are up-to-date
# and copy everything to the release path
def release
release_branch = fetch(:release_branch, File.basename(release_path))
git :checkout, '-B', release_branch,
fetch(:remote_branch, "origin/#{fetch(:branch)}")
git :submodule, :update, '--init'
# context.execute "rsync -ar --exclude=.git\* #{repo_path}/ #{release_path}"
context.execute "rsync -ar #{repo_path}/ #{release_path}"
end
end
This solution now deploys the release as a GIT repo set to a custom branch based on the release id.
This can then be committed and pushed up to the master repo for merging as required.
All credit goes to Aaron Thomas, the creator of the WP-Deploy project.
这篇关于Capistrano 3使用发布目录中可用的GIT部署WordPress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!