kind: pipeline # 定义对象类型，还有secret和signature两种类型
type: docker # 定义流水线类型，还有kubernetes、exec、ssh等类型
name: ${serverName} # 服务名

steps:
  - name: package # 流水线名称
    image: node:18.20.4
    volumes:
      - name: bulid-workspace
        path: /home/app/web
      - name: node_modules
        path: /root/node_modules
    commands:
      - npm config set registry https://registry.npmmirror.com
      # - npm config set registry https://registry.npm.taobao.org
      # - SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/ npm install node-sass
      - npm install
      - npm run build:dev
      - cp -r ./dist /home/app/web/dist
      - cp Dockerfile /home/app/web/Dockerfile
      - cp docker.sh /home/app/web/docker.sh
  - name: build-start
    image: appleboy/drone-ssh # SSH工具镜像
    settings:
      host: 192.168.0.110 # 远程连接地址
      username: root # 远程连接账号
      password: dy20090625 # 远程连接密码
        # from_secret: dy20090625 # 从Secret中读取SSH密码
      port: 22 # 远程连接端口
      command_timeout: 5m # 远程执行命令超时时间
      script:
        - cd /home/app/web # 进入宿主机构建目录
        - chmod +x docker.sh # 更改为可执行脚本
        - ./docker.sh # 运行脚本打包应用镜像并运行

volumes: # 定义流水线挂载目录，用于共享数据
  - name: bulid-workspace
    host:
      path: /home/app/web # 从宿主机中挂载的目录
  - name: node_modules
    host:
      path: /root/node_modules
