[英]How to update submodules in a gitlab CI/CD
I have a project organized in the following tree我在以下树中组织了一个项目
|.
|..
|-- devops
|-- project1
|-- project2
In the devops folder, I have included the other two projects as submodules, since these two projects are developed independently by two different teams.在 devops 文件夹中,我将其他两个项目作为子模块包含在内,因为这两个项目是由两个不同的团队独立开发的。
|.
|..
|-- project1@0deed0fa
|-- project2@0beef0fb
|-- .gitlab-ci.yml
I have setup the pipeline to deploy the projects.我已经设置了管道来部署项目。 Whenever there are new commits on any of the projects, a trigger is setup to run the
devops
project pipeline.每当任何项目有新的提交时,都会设置一个触发器来运行
devops
项目管道。 As part of the devops jobs, I run git submodule
commands to fetch and merge.作为 devops 作业的一部分,我运行
git submodule
命令来获取和合并。 Then build.然后构建。 It works.
有用。
The problem I have is, over a period of time, there are a lot of changes made to the submodules.我遇到的问题是,在一段时间内,对子模块进行了很多更改。 The changes from the last submodule commit to the devops project folder is replayed every time there is a commit on any of the projects.
每次对任何项目进行提交时,都会重播从最后一个子模块提交到 devops 项目文件夹的更改。 Once a month, I manually update the
devops
project folder and update to the latest commit of the submodule projects.每月一次,我手动更新
devops
项目文件夹并更新到子模块项目的最新提交。 I can commit the changes from the devops pipeline task, but that will generate new pipeline in the same devops pipeline.我可以提交来自 devops 管道任务的更改,但这将在同一个 devops 管道中生成新管道。 (I didn't test it but it seems obvious).
(我没有测试,但看起来很明显)。
Is there any way I can update the submodules to the latest commit as part of the devops pipeline?作为 devops 管道的一部分,有什么方法可以将子模块更新为最新提交?
Thanks.谢谢。
Using git submodules are not the best practice for implementing an integration pipeline.使用 git 子模块不是实现集成管道的最佳实践。 The seminal book Continuous Delivery states the following in the section
Only Build Your Binaries Once
(Chapter 5):影响深远的书籍《 持续交付》在“
Only Build Your Binaries Once
(第 5 章)一节中陈述了以下内容:
Many build systems use source code held in the version control system as the canonical source for many steps.
许多构建系统使用版本控制系统中保存的源代码作为许多步骤的规范源代码。 The code will be compiled repeatedly in different contexts during the commit process, again at acceptance test time, [etc.] Every time you compile the code, you run the risk of introducing some difference.
在提交过程中,代码将在不同的上下文中重复编译,在验收测试时再次编译,[等等]每次编译代码时,都会冒引入一些差异的风险。
Also, recompiling takes a lot of time, resulting in longer feedback cycles.此外,重新编译需要花费大量时间,导致反馈周期更长。 The recommendation is:
建议是:
You should only build your binaries once, during the commit stage of the build.
在构建的提交阶段,您应该只构建一次二进制文件。 These binaries should be stored in a filesystem somewhere [...] where it is easy to retrieve them for later stages of the pipeline.
这些二进制文件应该存储在某个地方的文件系统中 [...] ,以便在管道的后期阶段轻松检索它们。
Following this paradigm, your workflow would look something like this:按照这种范式,您的工作流程将如下所示:
project1
and project2
will push a commitproject1
和project2
的功能分支上工作的开发人员将推送一个提交release
repositoryrelease
存储库Notice how the source code is only built once.请注意源代码是如何只构建一次的。
There are a number of popular binary repositories available.有许多流行的二进制存储库可用。 Most have a free and paid pro version.
大多数都有免费和付费的专业版。 Check their websites for more info.
查看他们的网站以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.