【问题标题】:Linking to multiple subdirectories using :repo_tree使用 :repo_tree 链接到多个子目录
【发布时间】:2019-08-05 14:45:25
【问题描述】:

我的存储库设置类似于以下内容:

repo_base
  - artwork
  - app
  - designsystem
  - api

由于 repo 中的每个其他文件夹(例如 appapidesignsystem)都依赖于 artwork,因此我在本地运行时有符号链接。这工作正常,因为designsystem 子目录中images 的路径类似于../../artwork。当您签出存储库时,整个树都被签出,因此符号链接指向正确的目录。

但是,当我使用 capistrano 进行部署时,我使用 :repo_tree 仅部署整个 monorepo 的一部分。例如,designsystem 文件夹的 deploy.rb 脚本如下所示:

# config valid for current version and patch releases of Capistrano
lock "~> 3.11.0"

set :application, "designsystem"
set :repo_url, "git@gitlab.com:myuser/mymonorepo"
set :deploy_to, "/var/www/someplace.net/designsystem.someplace.net"
set :deploy_via, "remote_cache_with_project_root"
set :repo_tree, 'designsystem'
set :log_level, :error

before 'deploy:set_current_revision', 'deploy:buildMonolith'

当然,问题在于这只会部署designsystem 子目录。因此,符号链接无效,实际上在建筑物中被跳过(buildMonolith 步骤)。

我想知道如何让 capistrano 检出 另一个 子目录 artwork,并将其放在存储库源代码树中的某个位置。

【问题讨论】:

    标签: capistrano


    【解决方案1】:

    我可以通过添加一个名为 assets.rb 的 capistrano 任务来解决这个问题:

    require 'pathname'
    
    ##
    # Import assets from a top level monorepo directory into the current working
    # directory.
    #
    # When you use :repo_tree to deploy a specific directory of a monorepo, but your
    # asset repository is in a different directory, you need to check out this
    # top-level directory and add it to the deployment path. For example, if your
    # monorepo directory structure looks something like:
    #
    # - /app
    #   - src/
    #     - assets -> symlink to ../../assets
    # - /assets
    # - /api
    #
    # And you want to deploy /app, the symlink to the upper directory won't exist if
    # capistrano is configured to use :repo_tree "app". In order to overcome this,
    # this task checks out a specified piece of the larger monorepo (in this case,
    # the assets directory), and places it in the deployment directory at a
    # specified location.
    #
    # Configuration:
    # In your deploy/<stage>.rb file, you will need to specify two variables:
    #   - :asset_path - The location within the deployment directory where the
    #                   assets should be placed. Relative to the deployment working
    #                   directory.
    #   - :asset_source - The location of the top-level asset folder in the
    #                     monorepo. Relative to the top level of the monorepo (i.e.
    #                     the directory that would be used as a deployment if
    #                     :repo_tree was not specified).
    #
    # In the above example, you would specify:
    #
    # set :asset_path, "src/assets"
    # set :asset_source, "assets"
    #
    namespace :deploy do
      desc "Import assets from a top-level monorepo directory"
      task :import_assets do
       on roles(:all) do |host|
          within repo_path do
            final_asset_location = "#{release_path}/#{fetch(:asset_path)}"
            asset_stat_result = capture "stat", "-t", "#{final_asset_location}"
            asset_stat_result = asset_stat_result.split(" ")
            if asset_stat_result[0] == "#{final_asset_location}"
              info "Removing existing asset directory #{final_asset_location}..."
              execute "rm", "-rf", "#{final_asset_location}"
            end
    
            source_dir = Pathname.new(final_asset_location).parent.to_s
            info "Importing assets to #{source_dir}/#{fetch(:asset_source)}"
            execute "GIT_WORK_TREE=#{source_dir}", :git, "checkout", "#{fetch(:branch)}", "--", "#{fetch(:asset_source)}"
    
            info "Moving asset directory #{source_dir}/#{fetch(:asset_source)} to #{final_asset_location}..."
            execute :mv, "#{source_dir}/#{fetch(:asset_source)}", "#{final_asset_location}"
          end
        end
      end
    end
    

    如果我能以某种方式链接到git scm 插件,而不是直接从命令行调用git,那就太好了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多