从gitlab ci部署Node.js项目 [英] Deploying nodejs project from gitlab ci

查看:507
本文介绍了从gitlab ci部署Node.js项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是node.js的新手,我试图通过gitlab ci部署node.Js项目。但是在发现管道中的构建错误后,我意识到我将node_modules文件夹添加到了.gitignore,并且我没有将node_modules推送到gitlab。并且node_modules文件夹在本地为889MB,我无法将其推送,因此我应该使用哪种方法从其他地方使用node_modules文件夹。

I am new to node.js, I was trying to deploy node.Js project via gitlab ci. But after spotting the build error in pipeline I realized I added node_modules folder to .gitignore, and I am not pushing node_modules to gitlab. And node_modules folder is 889MB locally there is no way I will push it, so what approach should I use to use node_module s folder from somewhere else.

即node_modules路径始终存在,并且可以在远程服务器上访问!我是否需要在包中包含该路径。 Json

i.e. node_modules path is always present and accessible on remote server! Do I need to include that path in package. Json

可以使用docker维护node_modules吗?那么我将如何保持针对每个项目的最新信息。

Can node_modules be maintained by using docker ? then how would I maintain to stay update specific to every project.

推荐答案

正确的是不要签入 node_modules 文件夹,在您运行 npm install

You are right not to check in the node_modules folder, they are automatically populated at the time you run npm install

这应该是gitlab ci中构建管道的一部分。流水线允许多个步骤,并且可以将伪像传递到下一个阶段。对于您的情况,您想保存通过运行 npm install 创建的 node_modules 文件夹,然后可以将依赖项用于测试或部署。

This should be part of your build pipeline in the gitlab ci. The pipeline allows multiple steps and the ability to pass artefacts through to the next stage. In your case you want to save the node_modules folder that is created by running npm install you can then use the dependencies for tests or deployment.

自npm v5起,有一个锁定文件来确保本地运行的内容与服务器上运行的内容相同

Since npm v5 there is a lockfile to make sure what you are running locally will be the same as what you are running on the server

如果您愿意,您也可以使用重新装修之类的东西来自动更新您的依赖关系修复它们并自动管理安全更新。 (rennovate是开源的,因此可以在gitlab上运行)。

Also you can use something like rennovate to automatically update your dependancies if you want to fix them and automatically manage security updates. (rennovate is open source so can be ran on gitlab)

一个非常简单的gitlab CI管道可以是:

A really simple gitlab CI pipeline could be:

// .gitlab-ci.yml
stages:
    - build
    - deploy

build:
    stage: build
    script:
        - npm install
    artifacts:
        name: "${CI_BUILD_REF}"
        expire_in: 10 mins
        paths:
            - node_modules

deploy:
   stage: deploy
   script:
     - some deploy command

这篇关于从gitlab ci部署Node.js项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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