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.

72 lines
2.4 KiB

  1. Param(
  2. [parameter(Mandatory=$false)][string]$registry,
  3. [parameter(Mandatory=$false)][string]$dockerUser,
  4. [parameter(Mandatory=$false)][string]$dockerPassword,
  5. [parameter(Mandatory=$false)][string]$imageTag,
  6. [parameter(Mandatory=$false)][bool]$buildImages=$true,
  7. [parameter(Mandatory=$false)][bool]$pushImages=$true,
  8. [parameter(Mandatory=$false)][string]$dockerOrg="eshop"
  9. )
  10. # Initialization
  11. $useDockerHub = [string]::IsNullOrEmpty($registry)
  12. # Check required commands (only if not in CI environment)
  13. $requiredCommands = ("docker", "docker-compose")
  14. foreach ($command in $requiredCommands) {
  15. if ((Get-Command $command -ErrorAction SilentlyContinue) -eq $null) {
  16. Write-Host "$command must be on path" -ForegroundColor Red
  17. exit
  18. }
  19. }
  20. # Get tag to use from current branch if no tag is passed
  21. if ([string]::IsNullOrEmpty($imageTag)) {
  22. $imageTag = $(git rev-parse --abbrev-ref HEAD)
  23. }
  24. Write-Host "Docker image Tag: $imageTag" -ForegroundColor Yellow
  25. # Build docker images if needed
  26. if ($buildImages) {
  27. Write-Host "Building Docker images tagged with '$imageTag'" -ForegroundColor Yellow
  28. $env:TAG=$imageTag
  29. docker-compose -p .. -f ../docker-compose.yml build
  30. }
  31. # Login to Docker registry
  32. if (-not [string]::IsNullOrEmpty($dockerUser)) {
  33. $registryFDQN = if (-not $useDockerHub) {$registry} else {"index.docker.io/v1/"}
  34. Write-Host "Logging in to $registryFDQN as user $dockerUser" -ForegroundColor Yellow
  35. if ($useDockerHub) {
  36. docker login -u $dockerUser -p $dockerPassword
  37. }
  38. else {
  39. docker login -u $dockerUser -p $dockerPassword $registryFDQN
  40. }
  41. if (-not $LastExitCode -eq 0) {
  42. Write-Host "Login failed" -ForegroundColor Red
  43. exit
  44. }
  45. }
  46. # Push images to Docker registry
  47. if ($pushImages) {
  48. Write-Host "Pushing images to $registry/$dockerOrg..." -ForegroundColor Yellow
  49. $services = ("basket.api", "catalog.api", "identity.api", "ordering.api", "ordering.backgroundtasks", "marketing.api","payment.api","locations.api", "webmvc", "webspa", "webstatus", "ocelotapigw", "mobileshoppingagg", "webshoppingagg", "ordering.signalrhub")
  50. foreach ($service in $services) {
  51. $imageFqdn = if ($useDockerHub) {"$dockerOrg/${service}"} else {"$registry/$dockerOrg/${service}"}
  52. docker tag eshop/${service}:$imageTag ${imageFqdn}:$imageTag
  53. docker push ${imageFqdn}:$imageTag
  54. }
  55. }