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
运行结果如下: