简体   繁体   中英

Typescript Node.js project - deployment to production workflow

How should I setup my dist build and production deployment workflow for my Node.js server app? (NestJS API)?

My current workflow:

  1. Commit changes to production branch
  2. Production server with pm2 automatically pull changes from this repo
  3. Automatic npm install on prod server.
  4. Automatic npm run build on prod server.
  5. Automatic pm2 start on prod server.

The main problem I see in this workflow is that I am running build on production server. This means that I need all devDependencies on server and also I am doing performance spikes on server when building.

I already configured GitHub Actions on my repo to build my code and save it as artifact on commit, but now I am stuck.

  • Should I commit built source code to repo and then use pm2 hook on production?
  • Should I download artifact by some script to production, unpack it and run it? I see few problems here:
    • /dist folder (artifact) does not have package.json and assets
    • I lost Git functionality, so I need to always delete old source and unpack new source

I don't have all the info I need, but I guess you should run the build step on a CI/CD tool (TravisCI for example), and push the content of the /dist folder to your production server afterwards. Then, pm2 would only run this production build.

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