使用:repo_tree链接到多个子目录 [英] Linking to multiple subdirectories using :repo_tree

查看:58
本文介绍了使用:repo_tree链接到多个子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My repository is set up similar to the following:

repo_base
  - artwork
  - app
  - designsystem
  - api

由于回购中的每个其他文件夹(例如 app api designsystem )取决于 artwork ,我在本地运行时有符号链接。这很好用,因为 designsystem 子目录中的图像的路径类似于。 ./../ artwork 。当您检出存储库时,整个树都被检出,因此符号链接指向正确的目录。

Since each of the other folders in the repo (e.g. app, api, designsystem) depend on artwork, I have symlinks in place when running locally. This is working fine, as the path for images in the designsystem subdirectory is something like ../../artwork. When you check out the repository, the entire tree is checked out, so the symlinks are pointing to the correct directory.

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

However, when I deploy with capistrano, I use :repo_tree to only deploy a portion of the overall monorepo. For example, the deploy.rb script for the designsystem folder looks like:

# 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 步骤)。

The problem, of course, is that this only ends up deploying the designsystem subdirectory. Thus, the symlinks aren't valid, and are actually skipped in the building (buildMonolith step).

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

I'm wondering how I might go about having capistrano check out another subdirectory, artwork, and placing it somewhere in the repository source tree.

推荐答案

我能够通过添加名为 assets.rb 的capistrano任务来解决此问题。 :

I was able to solve this by adding a capistrano task called assets.rb:

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

It would be nice if I could somehow link into the git scm plugin, rather than calling git from the command line directly.

这篇关于使用:repo_tree链接到多个子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆