简体   繁体   English

GitLab运行器角度依赖

[英]GitLab runner Angular dependencies

I'd like to configure runner that automaticaly builds and deploys an Angular app. 我想配置可自动构建和部署Angular应用程序的运行器。 For that, I'd have to install the project dependencies with npm install before building or deploying, because those are not stored in the repo. 为此,在构建或部署之前,我必须使用npm install项目依赖项,因为这些依赖项未存储在存储库中。 The thing is that it is a very slow process, so I'd have to wait for like 5 minutes for that process to complete and the app to be deployed. 事实是,这是一个非常缓慢的过程,因此我必须等待大约5分钟才能完成该过程并部署应用程序。

Is it possible to avoid this somewhat? 有可能避免这种情况吗? A possibility in to install all project dependencies globally, but it is far from ideal. 可以全局安装所有项目依赖项,但这远非理想。

Meet GitLab's CI cache ! 满足GitLab的CI缓存

You can use it eg to share your node_modules folder. 您可以使用它例如共享您的node_modules文件夹。 Running npm install once the dependencies are there, will just update if needed. 一旦依赖项存在就运行npm install ,将在需要时进行更新。

Here you have an example project with Angular of using: 在这里,您有一个使用Angular的示例项目

cache:
  paths: 
    - node_modules/

Where you can compare the execution time of the 2 stages ( https://gitlab.com/solidgear-projects/GitlabCI/pipelines/11759264 ): 您可以在其中比较两个阶段的执行时间( https://gitlab.com/solidgear-projects/GitlabCI/pipelines/11759264 ):

  • First stage: 8 minutes 25 seconds 第一阶段:8分25秒
  • Second stage: 56 seconds since after " Successfully extracted cache " 第二阶段:“ Successfully extracted cache ”之后的56秒

Note that cache is only to share stuff between jobs (you mentioned you have one for build and one for deploy). 请注意, cache仅用于在作业之间共享内容(您提到过,有一个用于构建,一个用于部署)。

To share stuff between different builds (pipelines), I'd recommend you to read on https://about.gitlab.com/2017/07/11/dockerizing-review-apps/ which gives some hints on how to use docker images to bundle all your app's dependencies in a base image and reuse it in the future for your builds. 要在不同的版本(管道)之间共享内容,我建议您阅读https://about.gitlab.com/2017/07/11/dockerizing-review-apps/上的内容 ,其中提供了有关如何使用docker映像的一些提示将所有应用程序的依赖项捆绑在一个基础映像中,并在将来用于构建时重用。 eg 例如

build_base:
    stage: build
    image: docker
    services:
        - docker:dind
    before_script:
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD registry.gitlab.com
        - docker pull registry.gitlab.com/your-name/your-project:base
    script:
        - docker build -t registry.gitlab.com/your-name/your-project .
        - docker push registry.gitlab.com/your-name/your-project:base
    when: manual

I was facing the same problem, and what I ended up doing is: 我遇到了同样的问题,最终我要做的是:

  1. Copy node_modules and package.json in an external folder, that is not overwritten in each commit node_modulespackage.json复制到一个外部文件夹中,该文件夹在每次提交中都不会被覆盖
  2. In my task, the fisrt thing I do is creating a symlink called node_modules in the project root's folder pointing to the external node_modules folder 在我的任务中,我要做的第一件事就是在项目根目录的文件夹中创建一个指向外部node_modules文件夹的符号链接,称为node_modules
  3. I check for differences between the project's package.json and the one in the external location. 我检查项目的package.json和外部位置的package.json之间的差异。 If they are different, I run npm install and update the external node_modules and package.json 如果它们不同,则运行npm install并更新外部node_modulespackage.json
  4. Run, build, ... whatever. 运行,构建……等等。 Don't forget to add the --preserve-symlinks option to your build or serve commands 不要忘记在构建或服务命令中添加--preserve-symlinks选项

With this setting I am now having a build time of 47s compared de 3+ min before. 通过此设置,我现在的构建时间为47s,而之前是3分钟以上。

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

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