diff --git a/Dockerfile-Keeper b/Dockerfile-Keeper index 21b2496..3255111 100644 --- a/Dockerfile-Keeper +++ b/Dockerfile-Keeper @@ -1,19 +1,38 @@ -#作者(author):自动畅(auto-chang) -#微信号(WeChat):自动畅(auto-chang) -#公众号(WeChat official account):畅聊了个科技(IT-chang) -#时间(Time):2023年4月22日,星期六(Saturday, April 22, 2023) -#描述(Describe:为爱发电(Power Generation for Love) +锘# 浣跨敤鎴戜滑鐨勫熀纭闀滃儚 +FROM zlmediakit-dotnet AS keeper -FROM ubuntu-zlm-ffmpeg-dotnet AS keeper +# 璁剧疆宸ヤ綔鐩綍 WORKDIR /root/src + +# 澶嶅埗椤圭洰鏂囦欢 COPY . . + +# 鍒涘缓蹇呰鐨勭洰褰 RUN mkdir -p /root/AKStreamKeeper + +# 璁剧疆宸ヤ綔鐩綍鍒伴」鐩洰褰 WORKDIR /root/src/AKStreamKeeper -RUN ln -s $HOME/dotnet/dotnet /usr/bin/dotnet -f -RUN dotnet build "AKStreamKeeper.csproj" -c Release -o /app/build -RUN dotnet publish "AKStreamKeeper.csproj" -c Release -o /app/publish + +# 鏋勫缓椤圭洰 +RUN dotnet build "AKStreamKeeper.csproj" -c Release -o /app/build +RUN dotnet publish "AKStreamKeeper.csproj" -c Release -o /app/publish + +# 鏆撮湶蹇呰鐨勭鍙 EXPOSE 80 EXPOSE 443 EXPOSE 6880 -RUN mv /app/publish/* /root/AKStreamKeeper + +# 绉诲姩缂栬瘧鍚庣殑鏂囦欢鍒扮洰鏍囩洰褰 +RUN mv /app/publish/* /root/AKStreamKeeper + +# 鏇存柊閰嶇疆鏂囦欢涓殑璺緞 +RUN sed -i 's|"MediaServerPath": "[^"]*"|"MediaServerPath": "/opt/media/bin/MediaServer"|' /root/AKStreamKeeper/Config/AKStreamKeeper.json && \ + sed -i 's|"FFmpegPath": "[^"]*"|"FFmpegPath": "/usr/bin/ffmpeg"|' /root/AKStreamKeeper/Config/AKStreamKeeper.json + +# 鍚姩 MediaServer 骞剁瓑寰 5 绉掑悗缁堟 +RUN nohup /opt/media/bin/MediaServer & \ + sleep 5 && \ + pkill MediaServer || true + +# 璁剧疆宸ヤ綔鐩綍 WORKDIR /root/AKStreamKeeper \ No newline at end of file diff --git a/Dockerfile-zlmediakit b/Dockerfile-zlmediakit new file mode 100644 index 0000000..6825189 --- /dev/null +++ b/Dockerfile-zlmediakit @@ -0,0 +1,75 @@ +锘縁ROM zlmediakit/zlmediakit:master AS zlmediakit + +# 浣跨敤 ubuntu 20.04 浣滀负鍩虹闀滃儚 +FROM ubuntu:20.04 + +# 璁剧疆鐜鍙橀噺 +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ=Asia/Shanghai + +# 澶嶅埗 ZLMediaKit 鐩稿叧鏂囦欢 +COPY --from=zlmediakit /opt/media/bin/MediaServer /opt/media/bin/ +COPY --from=zlmediakit /opt/media/bin/default.pem /opt/media/bin/ +COPY --from=zlmediakit /opt/media/conf/config.ini /opt/media/conf/ +COPY --from=zlmediakit /opt/media/bin/www/ /opt/media/bin/www/ + + +# 瀹夎鍩虹鍖呭拰渚濊禆 +RUN apt-get update && apt-get install -y apt-transport-https ca-certificates && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + wget \ + software-properties-common \ + curl \ + gnupg \ + lsb-release \ + tzdata \ + libssl-dev \ + ffmpeg \ + gcc \ + g++ \ + gdb && \ + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \ + echo $TZ > /etc/timezone && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# 瀹夎 Microsoft 鍖呯鍚嶅瘑閽ュ拰婧 +RUN wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \ + dpkg -i packages-microsoft-prod.deb && \ + rm packages-microsoft-prod.deb + +# 瀹夎 .NET SDK 鍜岃繍琛屾椂 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + dotnet-sdk-6.0 \ + net-tools \ + aspnetcore-runtime-6.0 && \ + # 娓呯悊 apt 缂撳瓨 + apt-get autoremove -y && \ + apt-get clean -y && \ + rm -rf /var/lib/apt/lists/* + +# 璁剧疆宸ヤ綔鐩綍鍜岀幆澧冨彉閲 +WORKDIR /opt/media/bin +ENV PATH=/opt/media/bin:$PATH + +# 鏆撮湶鏈嶅姟绔彛 +# RTMP 绔彛 +EXPOSE 1935 +# RTSP 绔彛 +EXPOSE 554 +# HTTP 绔彛 +EXPOSE 80 +# HTTPS 绔彛 +EXPOSE 443 +# RTP 绔彛 +EXPOSE 10000/tcp +EXPOSE 10000/udp +# 鍏朵粬绔彛 +EXPOSE 8000/tcp +EXPOSE 8000/udp +EXPOSE 9000/udp + +# 鍚姩鍛戒护 +CMD ["./MediaServer","-s", "default.pem", "-c", "../conf/config.ini", "-l","0"] \ No newline at end of file diff --git a/deploy.ps1 b/deploy.ps1 new file mode 100644 index 0000000..519f654 --- /dev/null +++ b/deploy.ps1 @@ -0,0 +1,259 @@ +锘縫aram ( + [Parameter()] + [switch]$keeper, + [switch]$web, + [switch]$dk, + [switch]$dw, + [switch]$rw, + [switch]$rk, + [switch]$help, + [switch]$publish, # 鏄惁鍙戝竷闀滃儚 + [string]$registry = "", # 闀滃儚浠撳簱鍦板潃锛岄粯璁や负绌 + [string]$version = "latest" # 鐗堟湰鏍囩锛岄粯璁や负latest +) + +$APP_KEEPER_NAME = "ak-keeper" +$APP_WEB_NAME = "ak-web" +$BASE_IMAGE_NAME = "zlmediakit-dotnet" + +function Show-Usage { + Write-Host "Usage: .\deploy.ps1" + Write-Host " -keeper : install keeper" + Write-Host " -web : install Web" + Write-Host " -dk : deploy keeper" + Write-Host " -dw : deploy Web" + Write-Host " -rw : run Web" + Write-Host " -rk : run keeper" + Write-Host " -help : show this help" + Write-Host " -publish : publish images (.\deploy.ps1 -keeper -web -publish -registry ""xxx"" -version ""1.0.0"")" + Write-Host " -registry : registry address (default: empty)" + Write-Host " -version : version tag (default: latest)" + exit 1 +} + +if ($args.Count -eq 0 -and -not ($keeper -or $web -or $dk -or $dw -or $rw -or $rk -or $help)) { + Show-Usage +} + +if ($help) { + Show-Usage +} + + +# 绠鍖栫殑鍙戝竷鍑芥暟 +function Publish-Image { + param ( + [string]$imageName, + [string]$registry, + [string]$version + ) + + # 鏋勫缓鐩爣闀滃儚鍚嶇О + $targetImage = $imageName + if (![string]::IsNullOrEmpty($registry)) { + $targetImage = "${registry}/${imageName}" + } + $targetImage = "${targetImage}:${version}" + + # 鏍囪闀滃儚 + Write-Host "Tagging image as ${targetImage}..." + docker tag $imageName $targetImage + + # 鎺ㄩ侀暅鍍 + Write-Host "Pushing image ${targetImage}..." + docker push $targetImage + + if ($LASTEXITCODE -eq 0) { + Write-Host "Successfully published ${targetImage}" -ForegroundColor Green + } + else { + Write-Host "Failed to publish image ${targetImage}" -ForegroundColor Red + exit 1 + } +} +# 鍦ㄤ富閫昏緫涓坊鍔犲彂甯冨姛鑳 +if ($publish) { + Write-Host "Publishing images..." + + if ($keeper -or $dk -or $rk) { + Write-Host "Publishing keeper image..." + Publish-Image -imageName $APP_KEEPER_NAME -registry $registry -version $version + } + + if ($web -or $dw -or $rw) { + Write-Host "Publishing web image..." + Publish-Image -imageName $APP_WEB_NAME -registry $registry -version $version + } + # 鍙戝竷鍩虹闀滃儚 + Write-Host "Publishing base image..." + Publish-Image -imageName $BASE_IMAGE_NAME -registry $registry -version $version +} + +# 娣诲姞涓涓敤浜庝粠瀹瑰櫒澶嶅埗閰嶇疆鏂囦欢鐨勫嚱鏁 +function Copy-ConfigFromContainer { + param ( + [string]$configType + ) + + if ($configType -eq "keeper") { + # 鍒涘缓涓存椂瀹瑰櫒 + Write-Host "Creating temporary keeper container..." + docker create --name temp-keeper $APP_KEEPER_NAME + + # 鍒涘缓鏈湴鐩綍 + $targetDir = "$PWD/Docker/AKStreamKeeperConfig" + if (-not (Test-Path $targetDir)) { + New-Item -ItemType Directory -Path $targetDir -Force + } + + # 浠庡鍣ㄤ腑澶嶅埗閰嶇疆鏂囦欢 + Write-Host "Copying keeper config files from container..." + docker cp "temp-keeper:/root/AKStreamKeeper/Config/AKStreamKeeper.json" "$targetDir/" + docker cp "temp-keeper:/root/AKStreamKeeper/Config/logconfig.xml" "$targetDir/" + docker cp "temp-keeper:/opt/media/bin/config.ini" "$targetDir/" + + # 鍒犻櫎涓存椂瀹瑰櫒 + docker rm temp-keeper + Write-Host "Keeper config files copied to $targetDir" + } + elseif ($configType -eq "web") { + # 鍒涘缓涓存椂瀹瑰櫒 + Write-Host "Creating temporary web container..." + docker create --name temp-web $APP_WEB_NAME + + # 鍒涘缓鏈湴鐩綍 + $targetDir = "$PWD/Docker/AKStreamWebConfig" + if (-not (Test-Path $targetDir)) { + New-Item -ItemType Directory -Path $targetDir -Force + } + + # 浠庡鍣ㄤ腑澶嶅埗閰嶇疆鏂囦欢 + Write-Host "Copying web config files from container..." + docker cp "temp-web:/app/Config/AKStreamWeb.json" "$targetDir/" + docker cp "temp-web:/app/Config/SipClientConfig.json" "$targetDir/" + docker cp "temp-web:/app/Config/SipServerConfig.json" "$targetDir/" + docker cp "temp-web:/app/Config/logconfig.xml" "$targetDir/" + + # 鍒犻櫎涓存椂瀹瑰櫒 + docker rm temp-web + Write-Host "Web config files copied to $targetDir" + } +} + + +Write-Host "Welcome to the AKStream(c# NetCore Programming Language)" + +if ($keeper) { + Write-Host "You have chosen to install keeper" + + # 棣栧厛鏋勫缓鍩虹闀滃儚 + Write-Host "Building base ZLMediaKit with .NET image..." + docker build -f Dockerfile -t $BASE_IMAGE_NAME . + + if ($LASTEXITCODE -eq 0) { + Write-Host "Base image built successfully, now building keeper..." + docker build -f Dockerfile-Keeper -t $APP_KEEPER_NAME . + } + else { + Write-Host "Failed to build base image. Please check the Dockerfile and try again." + exit 1 + } +} + +if ($web) { + Write-Host "You have chosen to install Web" + docker build -f Dockerfile-Web -t $APP_WEB_NAME . +} + +if ($dk) { + Write-Host "You have chosen to deploy keeper" + + # 棣栧厛澶嶅埗閰嶇疆鏂囦欢 + Copy-ConfigFromContainer -configType "keeper" + docker ps | Where-Object { $_ -match $APP_KEEPER_NAME } | ForEach-Object { docker stop ($_ -split "\s+")[0] } + docker ps -a | Where-Object { $_ -match $APP_KEEPER_NAME } | ForEach-Object { docker rm ($_ -split "\s+")[0] } + + docker run -p 6880:6880 ` + -p 10001-10010:10001-10010 ` + -p 10001-10010:10001-10010/udp ` + -p 20002-20200:20002-20200 ` + -p 20002-20200:20002-20200/udp ` + -p 80:80 ` + -p 1935:1935 ` + -p 554:554 ` + -p 554:554/udp ` + -p 10000:10000 ` + -p 10000:10000/udp ` + -p 8000:8000/udp ` + -p 30000-30035:30000-30035/udp ` + -v "$PWD/Docker/AKStreamKeeperConfig/AKStreamKeeper.json:/root/AKStreamKeeper/Config/AKStreamKeeper.json" ` + -v "$PWD/Docker/AKStreamKeeperConfig/logconfig.xml:/root/AKStreamKeeper/Config/logconfig.xml" ` + -v "$PWD/Docker/AKStreamKeeperConfig/config.ini:/opt/media/bin/config.ini" ` + --name=$APP_KEEPER_NAME ` + --restart=always ` + -d $APP_KEEPER_NAME ` + dotnet AKStreamKeeper.dll +} + +if ($rk) { + Write-Host "You have chosen to run keeper" + # 棣栧厛澶嶅埗閰嶇疆鏂囦欢 + Copy-ConfigFromContainer -configType "keeper" + + docker run --rm -it -p 6880:6880 ` + -p 10001-10010:10001-10010 ` + -p 10001-10010:10001-10010/udp ` + -p 20002-20200:20002-20200 ` + -p 20002-20200:20002-20200/udp ` + -p 80:80 ` + -p 1935:1935 ` + -p 554:554 ` + -p 554:554/udp ` + -p 10000:10000 ` + -p 10000:10000/udp ` + -p 8000:8000/udp ` + -p 30000-30035:30000-30035/udp ` + -v "$PWD/Docker/AKStreamKeeperConfig/AKStreamKeeper.json:/root/AKStreamKeeper/Config/AKStreamKeeper.json" ` + -v "$PWD/Docker/AKStreamKeeperConfig/logconfig.xml:/root/AKStreamKeeper/Config/logconfig.xml" ` + --name=$APP_KEEPER_NAME ` + $APP_KEEPER_NAME ` + bash +} + +if ($dw) { + Write-Host "You have chosen to deploy Web" + + # 棣栧厛澶嶅埗閰嶇疆鏂囦欢 + Copy-ConfigFromContainer -configType "web" + docker ps | Where-Object { $_ -match $APP_WEB_NAME } | ForEach-Object { docker stop ($_ -split "\s+")[0] } + docker ps -a | Where-Object { $_ -match $APP_WEB_NAME } | ForEach-Object { docker rm ($_ -split "\s+")[0] } + + docker run -p 5800:5800 ` + -p 5060:5060 ` + -p 5060:5060/udp ` + -v "$PWD/Docker/AKStreamWebConfig/AKStreamWeb.json:/app/Config/AKStreamWeb.json" ` + -v "$PWD/Docker/AKStreamWebConfig/SipClientConfig.json:/app/Config/SipClientConfig.json" ` + -v "$PWD/Docker/AKStreamWebConfig/SipServerConfig.json:/app/Config/SipServerConfig.json" ` + -v "$PWD/Docker/AKStreamWebConfig/logconfig.xml:/app/Config/logconfig.xml" ` + --name=$APP_WEB_NAME ` + --restart=always ` + -d $APP_WEB_NAME +} + +if ($rw) { + Write-Host "You have chosen to run Web" + # 棣栧厛澶嶅埗閰嶇疆鏂囦欢 + Copy-ConfigFromContainer -configType "web" + docker run -p 5800:5800 ` + -p 5060:5060 ` + -p 5060:5060/udp ` + -v "$PWD/Docker/AKStreamWebConfig/AKStreamWeb.json:/app/Config/AKStreamWeb.json" ` + -v "$PWD/Docker/AKStreamWebConfig/SipClientConfig.json:/app/Config/SipClientConfig.json" ` + -v "$PWD/Docker/AKStreamWebConfig/SipServerConfig.json:/app/Config/SipServerConfig.json" ` + -v "$PWD/Docker/AKStreamWebConfig/logconfig.xml:/app/Config/logconfig.xml" ` + --name=$APP_WEB_NAME ` + --restart=always ` + -d $APP_WEB_NAME +} + +Write-Host "Successful script execution, best wishes for you" \ No newline at end of file