build_api_app.ps1 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. $beginPWD = $PWD
  2. $module = "video_course"
  3. try {
  4. Write-Output "set location to script path: $PSScriptRoot"
  5. Set-Location $PSScriptRoot
  6. git checkout master
  7. git checkout .
  8. git pull
  9. # git submodule foreach git checkout master
  10. # git submodule foreach git pull
  11. # .\scrips\gen_proto.ps1
  12. $cmd = "git describe --tags"
  13. $version = Invoke-Expression $cmd
  14. Write-Output "version: $version"
  15. $stableVersionParttern = ".*-stable$"
  16. $isStable = $version -match $stableVersionParttern
  17. if ($isStable) {
  18. Write-Output "is stable version"
  19. }
  20. Write-Output "use origin golang compiler"
  21. Set-Location ($PSScriptRoot + "/assembly/$module/main")
  22. $cmd = "go build -o $module -ldflags ""-X main._VERSION_='$version'"""
  23. Write-Output $cmd
  24. Invoke-Expression $cmd
  25. Write-Output "compile finish"
  26. Remove-Item "$PSScriptRoot/docker/$module/$module"
  27. Move-Item "$module" "$PSScriptRoot/docker/$module/$module"
  28. $dockerImage = "docker.beswell.com:5050/loallout/$module"
  29. $dockerImageWithVersion = "${dockerImage}:$version"
  30. $dockerImageLatest = "${dockerImage}:latest"
  31. $cmd = "docker build -t $dockerImageWithVersion $PSScriptRoot/docker/$module"
  32. Invoke-Expression $cmd
  33. $cmd = "docker tag $dockerImageWithVersion $dockerImageLatest"
  34. Invoke-Expression $cmd
  35. $cmd = "docker push $dockerImageWithVersion"
  36. Invoke-Expression $cmd
  37. $cmd = "docker push $dockerImageLatest"
  38. Invoke-Expression $cmd
  39. }
  40. catch {
  41. $err = $Error[0]
  42. Write-Error $err
  43. }
  44. Set-Location $beginPWD