---
kind: pipeline
name: thirdLargeScreen
concurrency:
  limit: 1
steps:
  - name: restore-cache
    image: docker.1ms.run/drillster/drone-volume-cache
    settings:
      restore: true
      cache_key: [DRONE_REPO_OWNER, DRONE_REPO_NAME]
      mount:
        - ./node_modules
    volumes:
      - name: cache
        path: /cache

  - name: build-dev
    image: docker.1ms.run/node:16.14.2
    commands:
      - node --version
      - npm install pnpm@8.15.4 -g --registry https://registry.npmmirror.com/
      - pnpm --version
      - pnpm install --no-frozen-lockfile --registry https://registry.npmmirror.com/
      - git diff --name-only HEAD^ HEAD | grep package-lock.json && pnpm install --no-frozen-lockfile
      - "[ -d node_modules ] && echo 'deps install done' || pnpm install --no-frozen-lockfile"
      - pnpm run build:dev
    when:
      branch:
        - dev
  - name: build-prod
    image: docker.1ms.run/node:16.14.2
    commands:
      - node --version
      - npm install pnpm@8.15.4 -g --registry https://registry.npmmirror.com/
      - pnpm --version
      - pnpm install --no-frozen-lockfile --registry https://registry.npmmirror.com/
      - git diff --name-only HEAD^ HEAD | grep package-lock.json && pnpm install  --registry https://registry.npmmirror.com/ --no-frozen-lockfile
      - "[ -d node_modules ] && echo 'deps install done' || pnpm install --registry https://registry.npmmirror.com/ --no-frozen-lockfile"
      - pnpm run build
    when:
      branch:
        - master
  - name: rebuild-cache
    image: docker.1ms.run/drillster/drone-volume-cache
    settings:
      rebuild: true
      cache_key: [DRONE_REPO_OWNER, DRONE_REPO_NAME]
      mount:
        - ./node_modules
    volumes:
      - name: cache
        path: /cache

  - name: deploy-dev
    image: docker.1ms.run/drillster/drone-rsync
    settings:
      user: root
      port: 22
      hosts: [api.mdfitnesscao.com]
      source: ./dist/*
      target: /docker/www/agency
      include: []
      exclude: []
      key:
        from_secret: ssh_key
    when:
      branch:
        - dev
  - name: deploy-prod
    image: docker.1ms.run/drillster/drone-rsync
    settings:
      user: root
      port: 22
      hosts: [api.hhmdtech.com]
      source: ./dist/*
      target: /docker/www/agency
      include: []
      exclude: []
      key:
        from_secret: ssh_key
    when:
      branch:
        - master
volumes:
  - name: cache
    host:
      path: /tmp

trigger:
  branch:
    - dev
    - master
