简体   繁体   English

从gitlab ci部署nodejs项目

[英]Deploying nodejs project from gitlab ci

I am new to node.js, I was trying to deploy node.Js project via gitlab ci. 我是node.js的新手,我试图通过gitlab ci部署node.Js项目。 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. 但在发现管道中的构建错误后,我意识到我将node_modules文件夹添加到了.gitignore,而我并没有将node_modules推送到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文件夹本地是889MB,我无法推送它,所以我应该使用什么方法从其他地方使用node_module的文件夹。

ie node_modules path is always present and accessible on remote server! 即node_modules路径始终存在并可在远程服务器上访问! Do I need to include that path in package. 我是否需要在包中包含该路径。 Json JSON

Can node_modules be maintained by using docker ? 可以使用docker维护node_modules吗? then how would I maintain to stay update specific to every project. 那么我将如何维护以保持特定于每个项目的更新。

You are right not to check in the node_modules folder, they are automatically populated at the time you run npm install 您不能检入node_modules文件夹,它们会在您运行npm install时自动填充

This should be part of your build pipeline in the gitlab ci. 这应该是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 install创建的node_modules文件夹,然后可以使用依赖项进行测试或部署。

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 从npm v5开始,有一个锁定文件,以确保您在本地运行的内容与您在服务器上运行的内容相同

Also you can use something like rennovate to automatically update your dependancies if you want to fix them and automatically manage security updates. 如果您想要修复它们并自动管理安全更新,您还可以使用rennovate之类的东西来自动更新您的依赖项。 (rennovate is open source so can be ran on gitlab) (rennovate是开源的,所以可以在gitlab上运行)

A really simple gitlab CI pipeline could be: 一个非常简单的gitlab CI管道可能是:

// .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

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

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