简体   繁体   English

如何更新 gitlab CI/CD 中的子模块

[英]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.谢谢。

Only Build Your Binaries Once只构建一次二进制文件

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.这些二进制文件应该存储在某个地方的文件系统中 [...] ,以便在管道的后期阶段轻松检索它们。

CI/CD Pipeline Flow CI/CD 管道流

Following this paradigm, your workflow would look something like this:按照这种范式,您的工作流程将如下所示:

  1. Developers working on feature branches in project1 and project2 will push a commitproject1project2的功能分支上工作的开发人员将推送一个提交
  2. A project pipeline is triggered that builds the binaries, runs unit/component tests and packages the container触发构建二进制文件、运行单元/组件测试和打包容器的项目管道
  3. If everything passes, the binaries or containers are deployed to a "development" repository如果一切顺利,二进制文件或容器将部署到“开发”存储库
  4. The project pipelines will trigger your downstream devops pipeline, which will download the binaries/containers from the repositories.项目管道将触发您的下游 devops 管道,该管道将从存储库下载二进制文件/容器。
  5. The devops pipeline integrates pieces and runs end-to-end tests devops 管道集成各个部分并运行端到端测试
  6. If E2E tests pass, the binaries/containers are deployed (aka promoted) to a release repository如果 E2E 测试通过,二进制文件/容器将部署(也称为提升)到release存储库
  7. If you're doing Continuous Delivery, you would deploy to production here, but many teams prefer pushing a button in a manual job如果你正在进行持续交付,你会在这里部署到生产环境,但许多团队更喜欢在手动工作中按下按钮

Notice how the source code is only built once.请注意源代码是如何只构建一次的。

Popular Binary Repositories流行的二进制存储库

There are a number of popular binary repositories available.有许多流行的二进制存储库可用。 Most have a free and paid pro version.大多数都有免费和付费的专业版。 Check their websites for more info.查看他们的网站以获取更多信息。

  1. GitLab Job Artifacts (between stages or pipelines) GitLab 作业工件(阶段或管道之间)
  2. GitLab Package Registry or GitLab Container Registry GitLab Package RegistryGitLab Container Registry
  3. GitHub Package Registry or GitHub Container Registry GitHub Package RegistryGitHub Container Registry
  4. JFrog Artifactory JFrog 神器
  5. Nexus Repository连结资料库
  6. Cloud storage container registry ( AWS ECR , GCP CR , Azure CR )云存储容器注册表( AWS ECRGCP CRAzure CR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM