简体   繁体   中英

Deploying nodejs project from gitlab ci

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.

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

Can node_modules be maintained by using docker ? 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

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.

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

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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