|
|
- Param(
- [parameter(Mandatory=$false)][string]$registry,
- [parameter(Mandatory=$false)][string]$dockerUser,
- [parameter(Mandatory=$false)][string]$dockerPassword,
- [parameter(Mandatory=$false)][string]$imageTag,
- [parameter(Mandatory=$false)][bool]$buildImages=$true,
- [parameter(Mandatory=$false)][bool]$pushImages=$true,
- [parameter(Mandatory=$false)][string]$dockerOrg="eshop"
- )
-
- # Initialization
-
- $useDockerHub = [string]::IsNullOrEmpty($registry)
-
- # Check required commands (only if not in CI environment)
-
- $requiredCommands = ("docker", "docker-compose")
- foreach ($command in $requiredCommands) {
- if ((Get-Command $command -ErrorAction SilentlyContinue) -eq $null) {
- Write-Host "$command must be on path" -ForegroundColor Red
- exit
- }
- }
-
- # Get tag to use from current branch if no tag is passed
- if ([string]::IsNullOrEmpty($imageTag)) {
- $imageTag = $(git rev-parse --abbrev-ref HEAD)
- }
- Write-Host "Docker image Tag: $imageTag" -ForegroundColor Yellow
-
- # Build docker images if needed
- if ($buildImages) {
- Write-Host "Building Docker images tagged with '$imageTag'" -ForegroundColor Yellow
- $env:TAG=$imageTag
- docker-compose -p .. -f ../docker-compose.yml build
- }
-
- # Login to Docker registry
- if (-not [string]::IsNullOrEmpty($dockerUser)) {
- $registryFDQN = if (-not $useDockerHub) {$registry} else {"index.docker.io/v1/"}
-
- Write-Host "Logging in to $registryFDQN as user $dockerUser" -ForegroundColor Yellow
- if ($useDockerHub) {
- docker login -u $dockerUser -p $dockerPassword
- }
- else {
- docker login -u $dockerUser -p $dockerPassword $registryFDQN
- }
-
- if (-not $LastExitCode -eq 0) {
- Write-Host "Login failed" -ForegroundColor Red
- exit
- }
-
- }
-
- # Push images to Docker registry
- if ($pushImages) {
- Write-Host "Pushing images to $registry/$dockerOrg..." -ForegroundColor Yellow
- $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")
-
- foreach ($service in $services) {
- $imageFqdn = if ($useDockerHub) {"$dockerOrg/${service}"} else {"$registry/$dockerOrg/${service}"}
- docker tag eshop/${service}:$imageTag ${imageFqdn}:$imageTag
- docker push ${imageFqdn}:$imageTag
- }
- }
-
-
-
-
-
|