Azure 帳號
Build your .NET apps with your Azure free account 建立了Azure 免費帳號。建帳號時,必須提供信用卡資料,先扣款台幣30元確認信用卡的正確性再退款台幣30元。建完免費帳號後,https://portal.azure.com/#home 就是自己在Azure的門戶網站。
Azure for .NET developers
Azure for .NET developers 是學習的起點。
第一個 Web App 發佈成 Azure Application Service
Quickstart: Deploy an ASP.NET web app 示範在Visual Studio 裡建立 Aspnet Web Core App,發布到Azure App Service。
- 以 AspNetCore Web App 模板起始沒有認證與Docker功能的Web App。
- 發佈到Azure自己的帳號裡。
- 用瀏覽器瀏覽到發佈到Azure的Web App。
- 更改程式、再次發佈、再次瀏覽。
- 到自己的門戶網站管理自己帳戶的資源使用。
第一個 Web App 發佈成 Azure Container Instance
Quickstart: Docker in Visual Studio 示範將Web App 做成 Docker Container 發佈到 Azure
發布映像組的Azure Web App
參考 Create a multi-container (preview) app using a Docker Compose configuration 的 "az webapp create ... --multicontainer-config-type compose ... compose-wordpress.yml" 與
Migrate custom software to Azure App Service using a custom container 的 az role assignment create ..., az resource update ...,製造powershell 指令檔 gglapp-azure-final.ps1。
在下列條件下
<compose-azure.ps1> 的內容:
- 用 AspNet Core Web App 模板,選擇 Enable Docker + Docker OS Linux,製成 WebAppDockerAzure 專案。
- 若要在 Docker 裡進行偵錯,必須參考 Container Tools launch settings,修改launchSettings.json 裡面關於Docker 的設定。
- 專案結點上點擊右鍵,發佈 Docker 映像到 Azure Container Registry
- Quickstart: Deploy a container instance in Azure using the Azure portal
第一個由前端與後段組成的 Web App,發佈成 Azure Application Service
Container Tools in Visual Studio 裡面的 Tutorial: Create a multi-container app with Docker Compose 示範如何用 Docker Compose 製作由兩個映像組成的Webp App,講解如何在在地端測試組合效果。
發布映像組的Azure Web App
參考 Create a multi-container (preview) app using a Docker Compose configuration 的 "az webapp create ... --multicontainer-config-type compose ... compose-wordpress.yml" 與
Migrate custom software to Azure App Service using a custom container 的 az role assignment create ..., az resource update ...,製造powershell 指令檔 gglapp-azure-final.ps1。
在下列條件下
- 已安裝Azure-CLI
- Powershell 已安裝 Azure Powershell Module(Az)
- 在地端的Desktop Docker已有 gglcr.azurecr.io/<api>, gglcr.azurecr.io/<front> 兩映像
- Azure 帳戶內沒有 gglgroup(Azure Resource Group)
- <compose-azure.ps1> 與 <compose-azure.yml> 在工作目錄中
<compose-azure.ps1> 的內容:
# https://docs.microsoft.com/en-us/azure/app-service/tutorial-custom-container?pivots=container-linux#configure-app-service-to-deploy-the-image-from-the-registry
# https://docs.microsoft.com/en-us/azure/app-service/tutorial-multi-container-app#create-a-docker-compose-app
# Login to Azure
Connect-AzAccount
# Create gglgroup(ResourceGroup) at japaneast(Location)
New-AzResourceGroup -Name gglgroup -Location japaneast
# Create gglcr(ContainerRegistry) with basic(Tier) in gglgroup
New-AzContainerRegistry -ResourceGroupName gglgroup -Name gglcr -Sku "Basic" -EnableAdminUser
# Create gglappserviceplan(AppServicePlan) with basic(Tier), linux(OS) at japaneast(Location)
New-AzAppServicePlan -ResourceGroupName gglgroup -Name gglappserviceplan -Location japaneast -Tier "Basic" -Linux
# Use docker to push local docker images,
#docker tag <front>gglcr.azurecr.io/<front>
#docker tag <api> gglcr.azurecr.io/<api>
## step 1 :set variable $password with password for gglcr
$password = (Get-AzContainerRegistryCredential -ResourceGroupName gglgroup -Name gglcr).password
## step 2 : login to gglcr
az acr login --name gglcr --username gglcr --password $password
## step 3 : push <api> and <front> to gglcr
docker push gglcr.azurecr.io/<front>
docker push gglcr.azurecr.io/<api>
# Create gglapp-azure(Web App) with gglappserviceplan(AppServicePlane) in gglgroup(ResourceGroup) using <compose-azure.yml>(ComposeFile)
az webapp create --resource-group gglgroup --plan gglappserviceplan --name <app-name> --multicontainer-config-type compose --multicontainer-config-file <compose-azure.yml>
# Assign managed service identity [system] to gglapp-azure(Web App).
az webapp identity assign --resource-group gglgroup --name <app-name>
## Retrieve <app-name> as $app(Variable)
$app = Get-AzWebApp -name <app-name>
## Retrieve subscription-id as $subscriptionid(Variable)
$subscriptionid = (Get-AzSubscription).id
# Grant [system](the managed identity) permission to access the gglcr(Container Registry)
az role assignment create --assignee $app.identity.principalid --scope /subscriptions/$subscriptionid/resourceGroups/gglgroup/providers/Microsoft.ContainerRegistry/registries/gglcr --role "AcrPull"
# Configure <app-name>(Web App) to use [system](managed identity) to pull from gglcr(ContainerRegistry).
az resource update --ids /subscriptions/$subscriptionid/resourceGroups/gglgroup/providers/Microsoft.Web/sites/<app-name>/config/web --set properties.acrUseManagedIdentityCreds=True
#Remove-AzResourceGroup -Name gglgroup -Force
<compose-azure.yml> 的內容:
version: '3.7'
services:
<api>:
image: gglcr.azurecr.io/<api>
restart: always
<front>:
depends_on:
- <api>
image: gglcr.azurecr.io/<front>
ports:
- 80:80
restart: always
End
沒有留言:
張貼留言