Deploying nodejs project from gitlab ci

2019-06-24 10:00发布

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.

i.e. 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.

1条回答
冷血范
2楼-- · 2019-06-24 10:20

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
查看更多
登录 后发表回答