diff --git a/task.ps1 b/task.ps1 index 9d5d1e8..b782521 100644 --- a/task.ps1 +++ b/task.ps1 @@ -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 @@ -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