platform:
  runner: 10.11.92.34

kind: pipeline
name: dev
trigger:
  branch:
    - dev
clone:
  disable: true

volumes:
  - name: docker-sock
    host:
      path: /var/run/docker.sock

##-------------------------------流水线⬇-------------------------------##
steps: # 定义流水线执行步骤，这些步骤将顺序执行
  - name: fetch
    image: registry.cn-qingdao.aliyuncs.com/wod/devops-git:1.0
    network_mode: host

  - name: s3-cache
    image: registry.cn-qingdao.aliyuncs.com/wod/devops-s3-cache:1.0
    network_mode: host
    settings:
      restore: true
      mount:
        - ./node_modules
      endpoint: http://cache.wodcloud.com
      access_key:
        from_secret: ACCESS_KEY_MINIO
      secret_key:
        from_secret: SECRET_KEY_MINIO

  - name: build # 项目打包
    image: registry.cn-qingdao.aliyuncs.com/wod/devops-node:16.16.0-slim
    # 将宿主机中文件夹挂载到容器中，宿主机文件夹中的文件会被容器访问并修改，起到使用缓存的作用，避免每次运行都要重现下载依赖，提高运行速度 
    commands:
      - yarn
      - export NODE_ENV=production
      - yarn build
  
  - name: s3-cache-build
    image: registry.cn-qingdao.aliyuncs.com/wod/devops-s3-cache:1.0
    network_mode: host
    settings:
      rebuild: true
      hash: package.json
      mount:
        - node_modules
      endpoint: http://cache.wodcloud.com
      access_key:
        from_secret: ACCESS_KEY_MINIO
      secret_key:
        from_secret: SECRET_KEY_MINIO

  - name: docker
    image: registry.cn-qingdao.aliyuncs.com/wod/devops-docker:1.0
    # 将宿主机的 docker和配置挂载到运行的 docker 容器中，那么在容器中运行 docker 命令时，等同于在宿主机中运行该docker命令 
    volumes:
      - name: docker-sock
        path: /var/run/docker.sock # 将下载依赖的目录挂载出来，防止重复下载
    settings: # 当前设置
      base: registry.cn-qingdao.aliyuncs.com/wod/nginx:1.19.5 # 基础镜像,根据项目需求进行使用，如果第三方登录改成ui-base
      dockerfile: .beagle/dockerfile
      repo: wod/apaas-system-ui # 生成镜像的 分组/名称
      version: "5.0.1" # 版本号
      channel: alpha # 后缀 example: alpha test fix-alpha fix等
      args: "TARGETOS=linux,TARGETARCH=amd64" # 不同架构的构建参数
      registry: registry.cn-qingdao.aliyuncs.com # 私有仓库地址
      registry_user: # 用户
        from_secret: REGISTRY_USER_ALIYUN
      registry_password: # 密码
        from_secret: REGISTRY_PASSWORD_ALIYUN
  
  - name: deploy-cloud
    image: registry.cn-qingdao.aliyuncs.com/wod/devops-kubernetes:1.0
    settings:
      namespace: apaas-v5
      deployment: apaas-manage-ui
      container: apaas-manage-ui
      image: registry.cn-qingdao.aliyuncs.com/wod/apaas-system-ui:5.0.1-alpha
    environment:
      KUBERNETES_SERVER:
        from_secret: KUBERNETES_SERVER
      KUBERNETES_TOKEN:
        from_secret: KUBERNETES_TOKEN

  - name: docker-arm64
    image: registry.cn-qingdao.aliyuncs.com/wod/devops-docker:1.0
    volumes:
      - name: docker-sock
        path: /var/run/docker.sock
    settings:
      base: registry.cn-qingdao.aliyuncs.com/wod/nginx:1.19.5-arm64
      dockerfile: .beagle/dockerfile
      repo: wod/apaas-system-ui
      version: "5.0.1"
      channel: alpha-arm64
      args: "TARGETOS=linux,TARGETARCH=arm64"
      registry: registry.cn-qingdao.aliyuncs.com
      registry_user:
        from_secret: REGISTRY_USER_ALIYUN
      registry_password:
        from_secret: REGISTRY_PASSWORD_ALIYUN
---
clone:
  disable: true

trigger:
  branch:
    - master

volumes:
  - name: docker-sock
    host:
      path: /var/run/docker.sock

kind: pipeline
name: master
steps:
  - name: harbor
    image: registry.cn-qingdao.aliyuncs.com/wod/devops-docker-tag:1.0
    volumes:
      - name: docker-sock
        path: /var/run/docker.sock
    pull: always
    environment:
      http_proxy: http://10.11.92.33:1282
      https_proxy: http://10.11.92.33:1282
      REGISTRY_USER:
        from_secret: REGISTRY_USER_ALIYUN
      REGISTRY_PASSWORD:
        from_secret: REGISTRY_PASSWORD_ALIYUN
    settings:
      source: registry.cn-qingdao.aliyuncs.com/wod/apaas-system-ui:5.0.1-alpha
      target: registry.cn-qingdao.aliyuncs.com/wod/apaas-system-ui:5.0.1
      registry: registry.cn-qingdao.aliyuncs.com

  - name: harbor-arm64
    image: registry.cn-qingdao.aliyuncs.com/wod/devops-docker-tag:1.0
    volumes:
      - name: docker-sock
        path: /var/run/docker.sock
    pull: always
    environment:
      http_proxy: http://10.11.92.33:1282
      https_proxy: http://10.11.92.33:1282
      REGISTRY_USER:
        from_secret: REGISTRY_USER_ALIYUN
      REGISTRY_PASSWORD:
        from_secret: REGISTRY_PASSWORD_ALIYUN
    settings:
      source: registry.cn-qingdao.aliyuncs.com/wod/apaas-system-ui:5.0.1-alpha-arm64
      target: registry.cn-qingdao.aliyuncs.com/wod/apaas-system-ui:5.0.1-arm64
      registry: registry.cn-qingdao.aliyuncs.com
##--------------对于需要保密的信息隐藏，减少账户信息的泄密⬇-----------------##
---
kind: secret
name: REGISTRY_USER
get:
  name: REGISTRY_USER
  path: devops-secrets
---
kind: secret
name: REGISTRY_PASSWORD
get:
  name: REGISTRY_PASSWORD
  path: devops-secrets
---
kind: secret
name: KUBERNETES_SERVER
get:
  name: KUBERNETES_SERVER
  path: devops-secrets
---
kind: secret
name: KUBERNETES_TOKEN
get:
  name: KUBERNETES_TOKEN
  path: devops-secrets
---
kind: secret
name: ACCESS_KEY_MINIO
get:
  name: ACCESS_KEY
  path: devops-secrets

---
kind: secret
name: SECRET_KEY_MINIO
get:
  name: SECRET_KEY
  path: devops-secrets

---
kind: secret
name: REGISTRY_USER_ALIYUN
get:
  name: USERNAME
  path: devops-registry-aliyun
---
kind: secret
name: REGISTRY_PASSWORD_ALIYUN
get:
  name: PASSWORD
  path: devops-registry-aliyun