简体   繁体   中英

Best practice copy large installer.exe file from exernal location to Azure DevOps docker image build agent

I am building a docker windows container image, via a Dockerfile with a Azure DevOps pipeline using windows-server-2019. For the container, I need to install a large proprietary program, via a setup.exe file.

What is best practice for supplying that to the build context?

My idea goes into the direction of not including the setup.exe in the git repo, where the Dockerfile is located, but store it on a blob storage and supply it directly to the build context.


My Dockerfile:

FROM mcr.microsoft.com/windows/servercore:ltsc2019

# install APP
WORKDIR c:/temp
COPY pf.exe C:/temp/installer.exe
RUN powershell.exe -Command Start-Process C:/temp/installer.exe -ArgumentList '-install -quiet' -Wait;

My build pipeline.yml:

variables:
  imageName: "APP"
  dockerRegistryServiceConnection: "XXX"

trigger:
  branches:
    include:
      - "master"
      - "develop"

pool:
  vmImage: "windows-2019"

steps:
  - task: Docker@2
    displayName: Build an image
    inputs:
      repository: $(imageName)
      command: buildAndPush
      tags: $(imageName)-$(Build.BuildNumber)
      Dockerfile: extraction/Dockerfile

Your idea is achievable. You can store the installer.exe file in Blob storage and directly use it in Azure Pipeline.

Here are the steps:

Step1: Create an Azure Storage account and store the installer.exe file

Step2: In Azure Pipeline, you can use the Azure PowerShell task to run the azcopy copy command to download the files from Azure Storage account to the same as dockerfile.

Here is the YAML Example:

variables:
  imageName: "APP"
  dockerRegistryServiceConnection: "XXX"

trigger:
  branches:
    include:
      - "master"
      - "develop"

pool:
  vmImage: "windows-2019"

steps:
  - task: AzurePowerShell@5
  displayName: 'Azure PowerShell script: InlineScript'
  inputs:
    azureSubscription: azure
    ScriptType: InlineScript
    Inline: 'azcopy copy ''https://mystorageaccount.blob.core.windows.net/mycontainer/installer.exe'' ''$(build.sourcesdirectory)\installer.exe'''
    azurePowerShellVersion: LatestVersion

  - task: Docker@2
    displayName: Build an image
    inputs:
      repository: $(imageName)
      command: buildAndPush
      tags: $(imageName)-$(Build.BuildNumber)
      Dockerfile: extraction/Dockerfile

For more info, you can refer to this doc: Download blobs from Azure Blob Storage by using AzCopy

Hi I managed to do it very similar to what you suggested, this is my solution:


variables:
    imageName: "xxx"
    dockerRegistryServiceConnection: "xxx"
    azureResourceServiceConnection: "xxx"
    keyVaultName: "xxx"
    keyVaultSecretName: "xxx"
    azureSubscription: "xxx"
    storageAccountName: "xxx"
    containerName: "xxx-installer"
    fileName: "xxx.exe"
  
  trigger:
    branches:
      include:
        - "master"
  
  pool:
    vmImage: "windows-2019"
  
  steps:
    - task: AzureKeyVault@2
      inputs:
        azureSubscription: $(azureResourceServiceConnection)
        KeyVaultName: $(keyVaultName)
        SecretsFilter: $(keyVaultSecretName)
        RunAsPreJob: true
    - task: AzureCLI@2
      displayName: "Download xxx installer"
      inputs:
        azureSubscription: $(azureSubscription)
        scriptLocation: inlineScript
        scriptType: ps
        inlineScript: |
          mkdir $(Build.SourcesDirectory)\BuildContext
          az storage blob download --container-name $(containerName) --file $(Build.SourcesDirectory)\BuildContext/$(fileName) --name $(fileName) --account-key $(xxx) --account-name $(storageAccountName)
          copy extraction\Dockerfile $(Build.SourcesDirectory)\BuildContext\Dockerfile
    - task: Docker@2
      displayName: Build docker image
      inputs:
        repository: $(imageName)
        containerRegistry: $(dockerRegistryServiceConnection)
        command: buildAndPush
        tags: $(imageName)-$(Build.BuildNumber)
        Dockerfile: $(Build.SourcesDirectory)/BuildContext/Dockerfile
    - task: AzureCLI@2
      displayName: "Post build cleanup"
      inputs:
        azureSubscription: $(azureSubscription)
        scriptLocation: inlineScript
        scriptType: ps
        inlineScript: |
          Get-ChildItem -Path $(Build.SourcesDirectory)\BuildContext -Recurse | Remove-Item -force -recurse
          Remove-Item $(Build.SourcesDirectory)\BuildContext -Force

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM