首页 > 解决方案 > 使用 Bitbucket Pipelines NodeJS 应用程序部署到 VPS

问题描述

我对 Bitbucket Pipelines 有点陌生,我正在尝试设置一个 NodeJS api 来自动部署到数字海洋水滴,并且非常感谢一些建议,因为我已经尝试了两天!

我已经设法弄清楚如何 scp 部署npm run build生成的 dist 目录,但我认为我需要的不仅仅是服务器上的目录,我是否正确?即 node_modules、package.json 等..?

这些是我尝试过的一些例子..

sftp

image: node:10.16.0
pipelines:
  default:
    - step:
        name: Build API
        caches:
          - node
        script:
          - npm install
          - npm run build
    - step:
        name: Deploy API PRODUCTION
        deployment: production
        script:
          - pipe: atlassian/sftp-deploy:0.4.1
            variables:
              USER: $USER
              SERVER: $PROD_SERVER
              REMOTE_PATH: '/var/www/live'

拉上拉链

image: node:10.16.0
pipelines:
  default:
    - step:
        name: Build API
        caches:
          - node
        script:
          - npm install
          - npm run build
          - tar czfv appname-api.tgz dist/ src/ node_modules/ package-lock.json package.json tsconfig.json tslint.json
        artifacts:
          - appname-api.tgz
    - step:
        name: Deploy API PRODUCTION
        deployment: production
        script:
          - pipe: atlassian/scp-deploy:0.3.3
            variables:
              USER: $USER
              SERVER: $PROD_SERVER
              REMOTE_PATH: '/var/www/live'
              LOCAL_PATH: 'appname-api.tgz'

以各种方式压缩它

tar --exclude='./git' -czfv appname-api.tgz ./

我想我可以做deploy.sh一个 git pull,但我的 repos 是私有的,这意味着我必须为每台服务器添加 ssh 密钥等,所以这并不理想..

标签: node.jsdigital-oceanbitbucket-pipelines

解决方案


推荐阅读