You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.6 KiB

8 years ago
8 years ago
8 years ago
  1. Param([string] $rootPath)
  2. $scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
  3. Write-Host "Current script directory is $scriptPath" -ForegroundColor Yellow
  4. if ([string]::IsNullOrEmpty($rootPath)) {
  5. $rootPath = "$scriptPath\.."
  6. }
  7. Write-Host "Root path used is $rootPath" -ForegroundColor Yellow
  8. workflow BuildAndPublish {
  9. param ([string] $rootPath
  10. )
  11. $projectPaths =
  12. @{Path="$rootPath\src\Web\WebMVC";Prj="WebMVC.csproj"},
  13. @{Path="$rootPath\src\Web\WebSPA";Prj="WebSPA.csproj"},
  14. @{Path="$rootPath\src\Services\Identity\Identity.API";Prj="Identity.API.csproj"},
  15. @{Path="$rootPath\src\Services\Catalog\Catalog.API";Prj="Catalog.API.csproj"},
  16. @{Path="$rootPath\src\Services\Ordering\Ordering.API";Prj="Ordering.API.csproj"},
  17. @{Path="$rootPath\src\Services\Basket\Basket.API";Prj="Basket.API.csproj"},
  18. @{Path="$rootPath\src\Services\Location\Locations.API";Prj="Locations.API.csproj"},
  19. @{Path="$rootPath\src\Services\Marketing\Marketing.API";Prj="Marketing.API.csproj"},
  20. @{Path="$rootPath\src\Services\Payment\Payment.API";Prj="Payment.API.csproj"},
  21. @{Path="$rootPath\src\Web\WebStatus";Prj="WebStatus.csproj"}
  22. foreach -parallel ($item in $projectPaths) {
  23. $projectPath = $item.Path
  24. $projectFile = $item.Prj
  25. $outPath = $item.Path + "\obj\Docker\publish"
  26. $projectPathAndFile = "$projectPath\$projectFile"
  27. #Write-Host "Deleting old publish files in $outPath" -ForegroundColor Yellow
  28. remove-item -path $outPath -Force -Recurse -ErrorAction SilentlyContinue
  29. #Write-Host "Publishing $projectPathAndFile to $outPath" -ForegroundColor Yellow
  30. dotnet build $projectPathAndFile
  31. dotnet publish $projectPathAndFile -o $outPath
  32. }
  33. }
  34. BuildAndPublish $rootPath
  35. ########################################################################################
  36. # Delete old eShop Docker images
  37. ########################################################################################
  38. $imagesToDelete = docker images --filter=reference="eshop/*" -q
  39. If (-Not $imagesToDelete) {Write-Host "Not deleting eShop images as there are no eShop images in the current local Docker repo."}
  40. Else
  41. {
  42. # Delete all containers
  43. Write-Host "Deleting all containers in local Docker Host"
  44. docker rm $(docker ps -a -q) -f
  45. # Delete all eshop images
  46. Write-Host "Deleting eShop images in local Docker repo"
  47. Write-Host $imagesToDelete
  48. docker rmi $(docker images --filter=reference="eshop/*" -q) -f
  49. }
  50. # WE DON'T NEED DOCKER BUILD AS WE CAN RUN "DOCKER-COMPOSE BUILD" OR "DOCKER-COMPOSE UP" AND IT WILL BUILD ALL THE IMAGES IN THE .YML FOR US