Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandrhaupt committed Aug 27, 2024
1 parent 400d0e9 commit 23b82a2
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions task.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $acrSku = "Basic"
$appName = "mate-webapp"
$planName = "mate-appservice-plan"
$registryName = "task-19-todoapp"
$containerImageName = "$acrLoginServer/todoapp:v1"

Write-Host "Creating a resource group $resourceGroupName ..."
New-AzResourceGroup -Name $resourceGroupName -Location $location
Expand Down Expand Up @@ -80,22 +81,38 @@ if (-not $plan) {
}

# Create the Web App with container settings
$webApp = New-AzWebApp -ResourceGroupName $resourceGroupName -Name $appName -Location $location -AppServicePlan $planName -ContainerImageName "DOCKER|$acrLoginServer/todoapp:v1"
$webApp = New-AzWebApp -ResourceGroupName $resourceGroupName -Name $appName -Location $location -AppServicePlan $planName -ContainerImageName "DOCKER|$containerImageName"

# Configure the Web App to use ACR credentials
Write-Host "Configuring Web App $appName to use ACR credentials ..."
$acrCredentials = (az acr credential show --name $acrName --resource-group $resourceGroupName --debug | ConvertFrom-Json)
# Configure the Web App to use a Docker container
$containerConfig = New-Object Microsoft.Azure.Commands.WebApps.Models.WebAppContainer
$containerConfig.ContainerRegistryServerUrl = "https://$acrLoginServer"
$containerConfig.ContainerRegistryImageName = "$acrLoginServer/todoapp:v1"

az acr credential show

#add new part
#Get-AzWebApp -ResourceGroupName $resourceGroupName -Name $appName | Select-Object -ExpandProperty SiteConfig
$acrCredentials = az acr credential show --name $acrName --resource-group $resourceGroupName | ConvertFrom-Json
$acrUsername = $acrCredentials.username
$acrPassword = $acrCredentials.passwords[0].value

#$acrCredentials = (az acr credential show --name $acrName --resource-group $resourceGroupName --debug | ConvertFrom-Json)
# Configure the Web App to use a Docker container
#$containerConfig = New-Object Microsoft.Azure.Commands.WebApps.Models.WebAppContainer
#$containerConfig.ContainerRegistryServerUrl = "https://$acrLoginServer"
#$containerConfig.ContainerRegistryImageName = "$acrLoginServer/todoapp:v1"

#az acr credential show

#$acrUsername = $acrCredentials.username
#$acrPassword = $acrCredentials.passwords[0].value
Set-AzWebApp -ResourceGroupName $resourceGroupName -Name $appName -AppSettings @{
"DOCKER_REGISTRY_SERVER_URL" = "https://$acrName.azurecr.io"
"DOCKER_REGISTRY_SERVER_USERNAME" = $acrUsername
"DOCKER_REGISTRY_SERVER_PASSWORD" = $acrPassword
"WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false" # Optional: Set to false if not needed
"DOCKER_ENABLE_CI" = "true" # Optional: Continuous deployment
}

Write-Host "Restarting Web App $appName to apply changes..."
Restart-AzWebApp -ResourceGroupName $resourceGroupName -Name $appName
# Apply the container settings to the Web App
Set-AzWebApp -ResourceGroupName $resourceGroupName -Name $webAppName -ContainerSettings $containerConfig
#Set-AzWebApp -ResourceGroupName $resourceGroupName -Name $webAppName -ContainerSettings $containerConfig
#Restart-AzWebApp -ResourceGroupName $resourceGroupName -Name $appName

az webapp config container set --name $appName --resource-group $resourceGroupName --docker-custom-image-name "$acrLoginServer/todoapp:v1" --docker-registry-server-url "https://$acrLoginServer" --docker-registry-server-user $acrUsername --docker-registry-server-password $acrPassword
#az webapp config container set --name $appName --resource-group $resourceGroupName --docker-custom-image-name "$acrLoginServer/todoapp:v1" --docker-registry-server-url "https://$acrLoginServer" --docker-registry-server-user $acrUsername --docker-registry-server-password $acrPassword

0 comments on commit 23b82a2

Please sign in to comment.