update.ps1 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. param(
  2. [switch]$u
  3. )
  4. $beginPWD = $PWD
  5. Write-Output $addHosts
  6. $dockerImage ="docker.beswell.com:5050/sportfitness/base"
  7. if ($u)
  8. {
  9. $cmd = "docker pull ${dockerImage}:latest"
  10. Write-Output "更新稳定版"
  11. Invoke-Expression $cmd
  12. }
  13. Set-Location $PSScriptRoot
  14. #try {
  15. # docker stop bsw_im
  16. #}
  17. #catch {
  18. #}
  19. #try {
  20. # docker rm bsw_im
  21. #}
  22. #catch {
  23. #}
  24. if ($IsWindows) {
  25. $configPath = $PSScriptRoot
  26. $consulAddr = "host.docker.internal:8500"
  27. $hostsPath = "C:\WINDOWS\system32\drivers\etc\hosts"
  28. $timeZone =" "
  29. }
  30. if ($IsLinux){
  31. $configPath = "/etc/bsw/signaldig2"
  32. $consulAddr = "172.17.0.1:8500"
  33. $hostsPath = "/etc/hosts"
  34. $timeZone = " -v /etc/localtime:/etc/localtime "
  35. }
  36. $hosts = Get-Content $hostsPath | Where-Object { $true -ne [string]::IsNullOrWhiteSpace($_) }
  37. $addHosts = ""
  38. foreach ($item in $hosts) {
  39. if (!($item -match ".*#.*")) {
  40. $array = $item.Split("`t", [StringSplitOptions]::RemoveEmptyEntries)
  41. $ip = $array[0]
  42. $hostArray = $array[1..$array.Length]
  43. foreach ($h in $hostArray){
  44. $addHosts = $addHosts + " --add-host ${h}:$ip "
  45. }
  46. }
  47. }
  48. docker-compose up -d
  49. Set-Location $beginPWD
  50. #$cmd = "docker run -d -P --name bsw_im $addHosts $timeZone -e CONSUL_ADDR=$consulAddr --restart=always ${dockerImage}:latest"
  51. #Write-Output "exec cmd: $cmd"
  52. #Invoke-Expression $cmd