Azure DevOps 容器作业中的 PHP Composer 缓存

问题描述 投票:0回答:0

我在 Azure DevOps 中有以下管道用于构建和部署 PHP Web 应用程序。 Azure 代理根据映像 (mycustomimage/pipeline-build-php8) 启动一个容器,并构建和部署容器中的所有内容。使用容器作业时如何缓存 PHP Composer 依赖项?我的理解是,Cache@2 任务存在于 Azure 代理正在侦听的主机(AzureAgentServer)上,而不是在容器中。

trigger:
  branches:
    include:
      - UAT

variables:
- group: 'Pipeline Secrets'

jobs:
- job: DeploytoUAT
  displayName: 'Deploy to UAT'
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/UAT'))
  pool:
    name: 'UAT Pool Linux'
    vmImage: 'AzureAgentServer'
  container:
    image: mycustomimage/pipeline-build-php8
  steps:
  - task: DownloadSecureFile@1
    name: AZagentSSHkey
    displayName: 'Download SSH key for Azure container user'
    inputs:
      secureFile: 'azagent_azpcontainer_ssh.key'
  - task: Cache@2
    displayName: 'Cache Composer'
    inputs:
      key: 'composer | "$(Agent.OS)" | composer.lock'
      restoreKeys: |
        composer | "$(Agent.OS)"
        composer
      path: | 
        $(Pipeline.Workspace)/.composer
  - script: |
      # Add credentials so that the azagent_azpcontainer can SSH to hosts (web servers) without password
      mkdir ~/.ssh/ && cp $(AZagentSSHkey.secureFilePath) ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
      composer config --global --auth http-basic.dev.azure.com token $AZURE_DEVOPS_EXT_PAT
      composer update myproject/anotherprojectrepo --no-interaction
      composer install --no-interaction --no-progress --prefer-dist --no-dev
      composer dump-autoload --no-dev --classmap-authoritative
      composer global require deployer/deployer --dev --ignore-platform-reqs
      export PATH=$PATH:~/.config/composer/vendor/bin/
      dep deploy uat
    env:
      AZURE_DEVOPS_EXT_PAT: $(AZURE_DEVOPS_PAT)
php azure-devops azure-pipelines composer-php php-deployer
© www.soinside.com 2019 - 2024. All rights reserved.