update_video_course.ps1 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Write-Output $addHosts
  2. $module = "video_course"
  3. $dockerImage ="docker.beswell.com:5050/loallout/$module"
  4. $cmd = "docker pull ${dockerImage}:latest"
  5. Invoke-Expression $cmd
  6. $cName = "$module"
  7. $cmd = "docker stop $cName"
  8. try {
  9. Invoke-Expression $cmd
  10. }
  11. catch {
  12. }
  13. $cmd = "docker rm $cName"
  14. try {
  15. Invoke-Expression $cmd
  16. }
  17. catch {
  18. }
  19. if ($IsWindows) {
  20. $configPath = $PSScriptRoot
  21. $consulAddr = "host.docker.internal:8500"
  22. $hostsPath = "C:\WINDOWS\system32\drivers\etc\hosts"
  23. $timeZone =" "
  24. }
  25. if ($IsLinux){
  26. $configPath = "/etc/bsw/loallout/$module"
  27. $consulAddr = "172.17.0.1:8500"
  28. $hostsPath = "/etc/hosts"
  29. $timeZone = " -v /etc/localtime:/etc/localtime "
  30. }
  31. $hosts = Get-Content $hostsPath | Where-Object { $true -ne [string]::IsNullOrWhiteSpace($_) }
  32. $addHosts = ""
  33. foreach ($item in $hosts) {
  34. if (!($item -match ".*#.*")) {
  35. $array = $item.Split("`t", [StringSplitOptions]::RemoveEmptyEntries)
  36. $ip = $array[0]
  37. $hostArray = $array[1..$array.Length]
  38. foreach ($h in $hostArray){
  39. $addHosts = $addHosts + " --add-host ${h}:$ip "
  40. }
  41. }
  42. }
  43. $cmd = "docker run -d -p 19097:58080 -P --name $cName $addHosts -v /etc/video_course:/conf $timeZone -e CONSUL_ADDR=$consulAddr -e DEBUG=TRUE --restart=always ${dockerImage}:latest"
  44. Write-Output "exec cmd: $cmd"
  45. Invoke-Expression $cmd