2022-07-25:xiu是用rust語言編寫的流媒體伺服器軟體專案。k8s安裝xiu,drone檔案如何寫?

moonfdd發表於2022-07-25

2022-07-25:xiu是用rust語言編寫的流媒體伺服器軟體專案。k8s安裝xiu,drone檔案如何寫?

答案2022-07-25:

雲原生環境不可能完全一樣,只能做參考。
我採用的是drone,重點是rust編譯環境。

drone檔案內容如下:

kind: pipeline
type: docker
name: dev

#取消git clone程式碼
clone:
  disable: true

steps:
  - name: clone
    image: drone/git
    pull: if-not-exists
    volumes:
      - name: cache
        path: /etc/hosts
    commands:
      - git clone http://git.dsy.com/dsygroup/compile-xiu.git .
      - git clone https://gitee.com/moonfdd/xiu.git
      #- git checkout $DRONE_COMMIT

  - name: build
    image: rust:latest
    pull: if-not-exists
    environment:
      RUSTUP_DIST_SERVER: https://mirrors.ustc.edu.cn/rust-static
      RUSTUP_UPDATE_ROOT: https://mirrors.ustc.edu.cn/rust-static/rustup
    volumes:
      - name: cache
        path: /etc/hosts
    commands:
      - sed -i "s/【DRONE_COMMIT:0:8】/${DRONE_COMMIT:0:8}/g" .helm/dev/values.yaml
      - cp config /usr/local/cargo/config
      - cd xiu/application/xiu
      - echo $RUSTUP_DIST_SERVER
      - echo $RUSTUP_UPDATE_ROOT
      - echo $CARGO_HOME
      - rustup target add x86_64-unknown-linux-musl
      - cargo build --release --target=x86_64-unknown-linux-musl
      - cd ../..
      - ldd target/x86_64-unknown-linux-musl/release/xiu
      - strip -s target/x86_64-unknown-linux-musl/release/xiu

  - name: image
    image: plugins/docker
    pull: if-not-exists
    volumes:
      - name: cache
        path: /etc/hosts
      - name: d
        path: /var/run/docker.sock
    commands:
      - docker version
      - docker build -f ./MyDockerfile -t dockergit.dsy.com/dsygroup/compile-xiu:${DRONE_COMMIT:0:8} ./xiu
      - docker push dockergit.dsy.com/dsygroup/compile-xiu:${DRONE_COMMIT:0:8}

  - name: deploy
    image: "pelotech/drone-helm3"
    pull: if-not-exists
    volumes:
      - name: cache
        path: /etc/hosts
      - name: d
        path: /var/run/docker.sock
    settings:
      mode: upgrade
      chart: ./.helm/dev
      vaules_yaml: ./.helm/dev/values.yaml
      release: xiu
      namespace: maoaoandemoname
      kube_api_server: "https://git.dsy.com:6443"
      kube_token:
        from_secret: kube_token
      skip_tls_verify: true
      values:
        - image.tag=${DRONE_COMMIT:0:8}

trigger:
  branch:
    - master
    - aaa

volumes:
  - name: cache
    host:
      path: /etc/hosts
  - name: d
    host:
      path: /var/run/docker.sock

dockerfile檔案內容如下:

FROM scratch
COPY application/xiu/src/config/config_rtmp.toml /conf/config_rtmp.toml
COPY target/x86_64-unknown-linux-musl/release/xiu /bin/xiu

config檔案是設定cargo的國內映象源,內容如下:

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

helm的內容就不貼在這裡了,具體見 碼雲地址

k8s裡暴露的埠如下:

在這裡插入圖片描述
推送影片到k8s裡,命令如下:

ffmpeg -i 俄羅斯.mp4 -rtsp_transport tcp -vcodec h264 -acodec aac -f flv rtmp://172.16.11.111:42308/live/test1

執行結果如下:

在這裡插入圖片描述
在這裡插入圖片描述
在這裡插入圖片描述

本作品採用《CC 協議》,轉載必須註明作者和本文連結
微信公眾號:福大大架構師每日一題。最新面試題,涉及golang,rust,mysql,redis,雲原生,演算法,分散式,網路,作業系統。

相關文章