image: node:18

deployments:
  production:
    - master
  staging-testing:
    - staging-testing
  staging:
    - staging
  testing:
    - testing
  development:
    - development

pipelines:
  branches:
    master:
      - step:
          name: Build and Deploy to Production
          deployment: production
          script:
            - npm ci
            - npm run build
            - pipe: atlassian/ssh-run:0.4.1
              variables:
                SSH_USER: $SSH_USERNAME
                SERVER: $PROD_HOST
                COMMAND: |
                  source /home/wosacom/nodevenv/apis-vc.western-overseas.com/18/bin/activate
                  cd /home/wosacom/apis-vc.western-overseas.com
                  git pull origin master
                  npm ci --production
                  pm2 restart vc-be-production-app

    staging-testing:
      - step:
          name: Build and Deploy to Staging Testing
          deployment: staging-testing
          script:
            - npm ci
            - npm run build:staging-testing
            - pipe: atlassian/ssh-run:0.4.1
              variables:
                SSH_USER: $SSH_USERNAME
                SERVER: $STAGING_TEST_HOST
                COMMAND: |
                  source /home/wosacom/nodevenv/stage-test-apis-vc.western-overseas.com/18/bin/activate
                  cd /home/wosacom/stage-test-apis-vc.western-overseas.com
                  git pull origin staging-testing
                  npm ci --staging-testing
                  pm2 restart vc-be-staging-testing-app

    staging:
      - step:
          name: Build and Deploy to Staging
          deployment: staging
          script:
            - npm ci
            - npm run build:staging
            - pipe: atlassian/ssh-run:0.4.1
              variables:
                SSH_USER: $SSH_USERNAME
                SERVER: $STAGING_HOST
                COMMAND: |
                  source /home/wosacom/nodevenv/stage-apis-vc.western-overseas.com/18/bin/activate
                  cd /home/wosacom/stage-apis-vc.western-overseas.com
                  git pull origin staging
                  npm ci --staging
                  pm2 restart vc-be-staging-app

    testing:
      - step:
          name: Build and Deploy to Testing
          deployment: testing
          script:
            - npm ci
            - npm run build:testing
            - pipe: atlassian/ssh-run:0.4.1
              variables:
                SSH_USER: $SSH_USERNAME
                SERVER: $TESTING_HOST
                COMMAND: |
                  source /home/wosacom/nodevenv/test-apis-vc.western-overseas.com/18/bin/activate
                  cd /home/wosacom/test-apis-vc.western-overseas.com
                  git pull origin testing
                  npm ci --testing
                  pm2 restart vc-be-testing-app

    development:
      - step:
          name: Build and Deploy to Development
          deployment: development
          script:
            - npm ci
            - npm run build:dev
            - pipe: atlassian/ssh-run:0.5.0
              variables:
                SSH_USER: $SSH_USERNAME
                SERVER: $DEV_HOST
                PORT: '7822'
                COMMAND: |
                  source /home/wosacom/nodevenv/dev-apis-vc.western-overseas.com/18/bin/activate
                  cd /home/wosacom/dev-apis-vc.western-overseas.com
                  git pull origin development
                  npm ci
                  npm run build:dev
                  pm2 restart vc-be-development-app
