【问题标题】:Capistrano 3 deploy WordPress with GIT available in release dirCapistrano 3 使用发布目录中可用的 GIT 部署 WordPress
【发布时间】:2014-07-01 08:48:53
【问题描述】:

我使用 Capistrano 3 部署我的 WordPress 项目(在 Bedrock WP 堆栈中实现:https://github.com/roots/bedrock)。

WordPress 特别支持更新生产/登台站点的实际代码的许多功能(插件更新、某些插件的设置文件等),并且在各种情况下我可能希望将这些代码更改提交到项目 GIT直接从服务器回购。

那么,问题是,有没有办法配置 Capistrano Deploy 以将 .git 存储库保留在 relase 目录中?

我认为这可以通过第 2 章中的“复制策略”设置来实现,但我找不到任何关于第 3 章的信息。

【问题讨论】:

    标签: wordpress git capistrano


    【解决方案1】:

    我通过修改 https://github.com/Mixd/wp-deploy 项目实现的自定义部署策略解决了这个问题。

    注意更改后的context.execute 行。

    # 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
    

    此解决方案现在将发布作为 GIT 存储库集部署到基于发布 ID 的自定义分支。

    然后可以根据需要提交并推送到主存储库以进行合并。

    所有功劳归功于 WP-Deploy 项目的创建者 Aaron Thomas。

    【讨论】:

      猜你喜欢
      • 2014-09-27
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2014-01-24
      相关资源
      最近更新 更多