@ -0,0 +1,37 @@ | |||
Param( | |||
[parameter(Mandatory=$false)][string]$acrName, | |||
[parameter(Mandatory=$false)][string]$gitUser, | |||
[parameter(Mandatory=$false)][string]$repoName="eShopOnContainers", | |||
[parameter(Mandatory=$false)][string]$gitBranch="dev", | |||
[parameter(Mandatory=$true)][string]$patToken | |||
) | |||
$gitContext = "https://github.com/$gitUser/$repoName" | |||
$services = @( | |||
@{ Name="eshopbasket"; Image="eshop/basket.api"; File="src/Services/Basket/Basket.API/Dockerfile" }, | |||
@{ Name="eshopcatalog"; Image="eshop/catalog.api"; File="src/Services/Catalog/Catalog.API/Dockerfile" }, | |||
@{ Name="eshopidentity"; Image="eshop/identity.api"; File="src/Services/Identity/Identity.API/Dockerfile" }, | |||
@{ Name="eshopordering"; Image="eshop/ordering.api"; File="src/Services/Ordering/Ordering.API/Dockerfile" }, | |||
@{ Name="eshoporderingbg"; Image="eshop/ordering.backgroundtasks"; File="src/Services/Ordering/Ordering.BackgroundTasks/Dockerfile" }, | |||
@{ Name="eshopmarketing"; Image="eshop/marketing.api"; File="src/Services/Marketing/Marketing.API/Dockerfile" }, | |||
@{ Name="eshopwebspa"; Image="eshop/webspa"; File="src/Web/WebSPA/Dockerfile" }, | |||
@{ Name="eshopwebmvc"; Image="eshop/webmvc"; File="src/Web/WebMVC/Dockerfile" }, | |||
@{ Name="eshopwebstatus"; Image="eshop/webstatus"; File="src/Web/WebStatus/Dockerfile" }, | |||
@{ Name="eshoppayment"; Image="eshop/payment.api"; File="src/Services/Payment/Payment.API/Dockerfile" }, | |||
@{ Name="eshoplocations"; Image="eshop/locations.api"; File="src/Services/Location/Locations.API/Dockerfile" }, | |||
@{ Name="eshopocelotapigw"; Image="eshop/ocelotapigw"; File="src/ApiGateways/ApiGw-Base/Dockerfile" }, | |||
@{ Name="eshopmobileshoppingagg"; Image="eshop/mobileshoppingagg"; File="src/ApiGateways/Mobile.Bff.Shopping/aggregator/Dockerfile" }, | |||
@{ Name="eshopwebshoppingagg"; Image="eshop/webshoppingagg"; File="src/ApiGateways/Web.Bff.Shopping/aggregator/Dockerfile" }, | |||
@{ Name="eshoporderingsignalrhub"; Image="eshop/ordering.signalrhub"; File="src/Services/Ordering/Ordering.SignalrHub/Dockerfile" } | |||
) | |||
$services |% { | |||
$bname = $_.Name | |||
$bimg = $_.Image | |||
$bfile = $_.File | |||
Write-Host "Setting ACR build $bname ($bimg)" | |||
az acr build-task create --registry $acrName --name $bname --image ${bimg}:$gitBranch --context $gitContext --branch $gitBranch --git-access-token $patToken --file $bfile | |||
} | |||
# Basket.API |
@ -0,0 +1,72 @@ | |||
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 | |||
} | |||
} | |||