연습 - 레지스트리에 모듈 게시
장난감 회사에서 사용할 프라이빗 레지스트리를 만들었습니다. 이 연습에서 다음을 수행합니다.
- 웹 사이트 리소스용 모듈을 만듭니다.
- CDN에 리소스에 대한 또 다른 모듈을 만듭니다.
- 모듈을 레지스트리에 게시합니다.
- 레지스트리에 모듈을 나열합니다.
이 연습에서는 Visual Studio Code용 Bicep 확장을 사용합니다. Visual Studio Code에서 해당 확장을 설치해야 합니다.
웹 사이트용 모듈 만들기
앞에서 웹 사이트를 배포하는 모듈을 만들었습니다. 여기서는 게시할 수 있도록 모듈 파일을 저장합니다.
Visual Studio Code를 엽니다.
website.bicep이라는 새 파일을 만듭니다.
다음 코드를 website.bicep 파일에 붙여넣습니다.
@description('The Azure region into which the resources should be deployed.') param location string @description('The name of the App Service app.') param appServiceAppName string @description('The name of the App Service plan.') param appServicePlanName string @description('The name of the App Service plan SKU.') param appServicePlanSkuName string resource appServicePlan 'Microsoft.Web/serverfarms@2023-12-01' = { name: appServicePlanName location: location sku: { name: appServicePlanSkuName } } resource appServiceApp 'Microsoft.Web/sites@2023-12-01' = { name: appServiceAppName location: location properties: { serverFarmId: appServicePlan.id httpsOnly: true } } @description('The default host name of the App Service app.') output appServiceAppHostName string = appServiceApp.properties.defaultHostName
파일을 저장합니다.
파일>을 다른 이름으로 저장을 선택하거나 Windows의 경우 Ctrl+S(macOS의 경우 ⌘+S)를 선택할 수 있습니다. 파일 저장 위치를 기억해야 합니다. 예를 들어, 파일을 저장할 templates 폴더를 만들 수 있습니다.
CDN용 모듈 만들기
이전 단계와 유사하게 바로 게시할 수 있도록 미리 생성된 모듈 파일을 저장합니다.
이름이 cdn.bicep인 새 파일을 만듭니다.
다음 코드를 cdn.bicep 파일에 붙여넣습니다.
@description('The host name (address) of the origin server.') param originHostName string @description('The name of the CDN profile.') param profileName string = 'cdn-${uniqueString(resourceGroup().id)}' @description('The name of the CDN endpoint') param endpointName string = 'endpoint-${uniqueString(resourceGroup().id)}' @description('Indicates whether the CDN endpoint requires HTTPS connections.') param httpsOnly bool var originName = 'my-origin' resource cdnProfile 'Microsoft.Cdn/profiles@2024-02-01' = { name: profileName location: 'global' sku: { name: 'Standard_Microsoft' } } resource endpoint 'Microsoft.Cdn/profiles/endpoints@2024-02-01' = { parent: cdnProfile name: endpointName location: 'global' properties: { originHostHeader: originHostName isHttpAllowed: !httpsOnly isHttpsAllowed: true queryStringCachingBehavior: 'IgnoreQueryString' contentTypesToCompress: [ 'text/plain' 'text/html' 'text/css' 'application/x-javascript' 'text/javascript' ] isCompressionEnabled: true origins: [ { name: originName properties: { hostName: originHostName } } ] } } @description('The host name of the CDN endpoint.') output endpointHostName string = endpoint.properties.hostName
파일을 저장합니다.
모듈을 레지스트리에 게시
Visual Studio Code 터미널에서 다음 명령을 실행합니다.
YOUR_CONTAINER_REGISTRY_NAME
을 프라이빗 레지스트리의 이름으로 바꿉니다.az bicep publish \ --file website.bicep \ --target 'br:YOUR_CONTAINER_REGISTRY_NAME.azurecr.io/website:v1' az bicep publish \ --file cdn.bicep \ --target 'br:YOUR_CONTAINER_REGISTRY_NAME.azurecr.io/cdn:v1'
로그인하지 않아도 됩니다. Bicep은 Azure CLI의 로그인 정보를 사용하여 레지스트리에 인증합니다.
다음 명령을 실행하여 레지스트리의 아티팩트 목록을 표시합니다.
az acr repository list \ --name YOUR_CONTAINER_REGISTRY_NAME
출력에는 모듈의 이름이 표시됩니다.
[ "cdn", "website" ]
Visual Studio Code 터미널에서 다음 명령을 실행합니다.
YOUR_CONTAINER_REGISTRY_NAME
을 프라이빗 레지스트리의 이름으로 바꿉니다.bicep publish website.bicep ` --target 'br:YOUR_CONTAINER_REGISTRY_NAME.azurecr.io/website:v1' bicep publish cdn.bicep ` --target 'br:YOUR_CONTAINER_REGISTRY_NAME.azurecr.io/cdn:v1'
로그인하지 않아도 됩니다. Bicep은 Azure PowerShell의 로그인 정보를 사용하여 레지스트리에 사용자를 인증합니다.
다음 명령을 실행하여 레지스트리의 아티팩트 목록을 표시합니다.
Get-AzContainerRegistryRepository -RegistryName YOUR_CONTAINER_REGISTRY_NAME
출력에는 모듈의 이름이 표시됩니다.
cdn website
Azure Portal을 사용하여 레지스트리의 모듈을 나열할 수도 있습니다. 리소스 그룹의 개요 탭에서 YOUR_CONTAINER_REGISTRY_NAME
을 선택한 다음 리포지토리를 선택합니다. 이 모듈의 뒷부분에서 Azure Portal에 연결합니다.