Azure Pipelines를 사용하여 Azure Government에 앱 배포

이 방법 가이드는 Azure Pipelines를 사용하여 Azure Government에서 실행되는 웹앱의 CI(연속 통합) 및 CD(지속적인 업데이트)를 설정하는 데 도움이 됩니다. CI/CD는 빌드된 코드 아티팩트를 Azure Government의 서비스 또는 서비스 집합에 배포(릴리스)하는 작업과 리포지토리에서 코드를 빌드하는 작업을 자동화합니다. 이 방법 가이드에서는 웹앱을 빌드하고 Azure Governments App Service에 배포합니다. 빌드 및 릴리스 프로세스는 리포지토리의 코드 파일 변경에 의해 트리거됩니다.

참고 항목

Azure DevOps는 Azure Government에서 사용할 수 없습니다. 이 방법 가이드에서는 Azure Government 내의 서비스에 앱을 배포하도록 Azure Pipelines의 CI/CD 기능을 구성하는 방법을 보여 주지만 Azure Pipelines는 Azure Government 외부에서 해당 파이프라인을 실행한다는 점에 유의하세요. 배포 도구의 일부로 사용하기 전에 조직의 보안 및 서비스 정책을 조사합니다. Azure DevOps Server를 사용하여 Azure Government의 프라이빗 네트워크 내에서 DevOps 환경을 만드는 방법에 대한 지침은 Azure Government의 Azure DevOps Server를 참조하세요.

Azure Pipelines는 개발 팀에서 Azure 구독에 호스트되는 애플리케이션에 대한 지속적인 배포를 구성하는 데 사용됩니다. Azure Government에 대한 서비스 연결을 정의하여 Azure Government에서 실행되는 애플리케이션에 이 서비스를 사용할 수 있습니다.

참고 항목

Azure Az PowerShell 모듈을 사용하여 Azure와 상호 작용하는 것이 좋습니다. 시작하려면 Azure PowerShell 설치를 참조하세요. Az PowerShell 모듈로 마이그레이션하는 방법에 대한 자세한 내용은 Azure PowerShell을 AzureRM에서 Azure로 마이그레이션을 참조하세요.

필수 조건

이 방법 가이드를 시작하기 전에 다음 필수 조건을 완료해야 합니다.

활성 Azure Government 구독이 없는 경우, 시작하기 전에 체험 계정을 만듭니다.

Azure Government App Service 앱 만들기

자습서: Azure App Service 앱 배포에 따라 Azure Government에 Azure App Service 앱을 배포하는 방법을 알아봅니다. 다음 단계에서는 웹앱에 배포할 CD 프로세스를 설정합니다.

빌드 및 소스 제어 통합 설정

다음 빠른 시작 중 하나를 검토하여 특정 유형의 앱에 대한 빌드를 설정합니다.

서비스 주체 만들기

  1. 다음 서비스 주체 만들기 PowerShell 스크립트를 복사하여 IDE 또는 편집기에 붙여넣은 다음, 스크립트를 저장합니다. 이 코드는 Azure Az PowerShell v7.0.0 이상과만 호환됩니다.

    param
    (
        [Parameter(Mandatory=$true, HelpMessage="Enter Azure subscription name - you need to be subscription admin to execute the script")]
        [string] $subscriptionName,
    
        [Parameter(Mandatory=$false, HelpMessage="Provide SPN role assignment")]
        [string] $spnRole = "owner",
    
        [Parameter(Mandatory=$false, HelpMessage="Provide Azure environment name for your subscription")]
        [string] $environmentName = "AzureUSGovernment"
    )
    
    # Initialize
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "SilentlyContinue"
    $userName = ($env:USERNAME).Replace(' ', '')
    $newguid = [guid]::NewGuid()
    $displayName = [String]::Format("AzDevOps.{0}.{1}", $userName, $newguid)
    $homePage = "http://" + $displayName
    $identifierUri = $homePage
    
    # Check for Azure Az PowerShell module
    $isAzureModulePresent = Get-Module -Name Az -ListAvailable
    if ([String]::IsNullOrEmpty($isAzureModulePresent) -eq $true)
    {
        Write-Output "Script requires Azure PowerShell modules to be present. Obtain Azure PowerShell from https://learn.microsoft.com//powershell/azure/install-az-ps" -Verbose
        return
    }
    
    Import-Module -Name Az.Accounts
    Write-Output "Provide your credentials to access your Azure subscription $subscriptionName" -Verbose
    Connect-AzAccount -Subscription $subscriptionName -Environment $environmentName
    $azureSubscription = Get-AzSubscription -SubscriptionName $subscriptionName
    $connectionName = $azureSubscription.Name
    $tenantId = $azureSubscription.TenantId
    $id = $azureSubscription.SubscriptionId
    
    # Create new Azure AD application
    Write-Output "Creating new application in Azure AD (App URI - $identifierUri)" -Verbose
    $azureAdApplication = New-AzADApplication -DisplayName $displayName -HomePage $homePage -Verbose
    $appId = $azureAdApplication.AppId
    $objectId = $azureAdApplication.Id
    Write-Output "Azure AD application creation completed successfully (Application Id: $appId) and (Object Id: $objectId)" -Verbose
    
    # Add secret to Azure AD application
    Write-Output "Creating new secret for Azure AD application"
    $secret = New-AzADAppCredential -ObjectId $objectId -EndDate (Get-Date).AddYears(2)
    Write-Output "Secret created successfully" -Verbose
    
    # Create new SPN
    Write-Output "Creating new SPN" -Verbose
    $spn = New-AzADServicePrincipal -ApplicationId $appId
    $spnName = $spn.DisplayName
    Write-Output "SPN creation completed successfully (SPN Name: $spnName)" -Verbose
    
    # Assign role to SPN
    Write-Output "Waiting for SPN creation to reflect in directory before role assignment"
    Start-Sleep 20
    Write-Output "Assigning role ($spnRole) to SPN app ($appId)" -Verbose
    New-AzRoleAssignment -RoleDefinitionName $spnRole -ApplicationId $spn.AppId
    Write-Output "SPN role assignment completed successfully" -Verbose
    
    # Print values
    Write-Output "`nCopy and paste below values for service connection" -Verbose
    Write-Output "***************************************************************************"
    Write-Output "Connection Name: $connectionName(SPN)"
    Write-Output "Environment: $environmentName"
    Write-Output "Subscription Id: $id"
    Write-Output "Subscription Name: $connectionName"
    Write-Output "Service Principal Id: $appId"
    Write-Output "Tenant Id: $tenantId"
    Write-Output "***************************************************************************"
    
  2. PowerShell 창을 열고 다음 명령을 실행합니다. 이 명령은 로컬 파일을 실행할 수 있도록 하는 정책을 설정합니다.

    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

    실행 정책을 변경할 것인지 묻는 메시지가 표시되면 "A"("모두 예")를 입력합니다.

  3. 서비스 주체 만들기 PowerShell 스크립트를 저장한 디렉터리로 이동합니다.

  4. 스크립트 이름으로 다음 명령을 편집하고 실행합니다.

    ./<name of script file you saved>

  5. "subscriptionName" 매개 변수는 Connect-AzAccount -EnvironmentName AzureUSGovernment를 통해 Azure Government 구독에 로그인한 후 Get-AzureSubscription을 실행하여 찾을 수 있습니다.

  6. Azure Government 구독 자격 증명을 제공한 후 다음 메시지가 표시됩니다.

    The Environment variable should be AzureUSGovernment

  7. 스크립트가 실행되면 서비스 연결 값이 표시됩니다. 이러한 값은 엔드포인트를 설정할 때 필요하므로 복사해 둡니다.

    Service connection values displayed after running the PowerShell script.

Azure Pipelines 서비스 연결 구성

서비스 연결 관리에 따라 Azure Pipelines 서비스 연결을 설정합니다.

Azure Government에 관련된 한 가지 변경을 수행합니다.

릴리스 프로세스 정의

Azure Web App 배포 지침에 따라 릴리스 파이프라인을 설정하고 Azure Government에서 애플리케이션에 배포합니다.

Q&A

빌드 에이전트가 필요한가요?
배포를 실행하려면 하나 이상의 에이전트가 필요합니다. 기본적으로 빌드 및 배포 프로세스는 호스트된 에이전트를 사용하도록 구성됩니다. 프라이빗 에이전트를 구성하면 Azure Government 외부에서 데이터 공유가 제한될 수 있습니다.

Azure Government를 대상으로 하도록 Azure DevOps Server(이전의 Team Foundation Server)에서 CD를 구성할 수 있나요?
Azure Government에서 Azure DevOps Server를 설정할 수 있습니다. Azure DevOps Server를 사용하여 Azure Government의 프라이빗 네트워크 내에서 DevOps 환경을 만드는 방법에 대한 지침은 Azure Government의 Azure DevOps Server를 참조하세요.

다음 단계

자세한 내용은 다음 리소스를 참조하세요.