Azure DevOps - 部署 Magento 2 - 请求实体太大代码 413

问题描述

我正在尝试使用 Azure DevOps 作为 CI/CD 的一部分来部署 Magento 2 示例代码。我已经构建了使用 YAML 配置的管道,该管道从主分支获取代码并以 zip 格式发送到目标。

存档阶段作业已完成,工件已使用 2GB zip 文件构建。但是,它在 Deploy 阶段抛出错误失败,如下所示

Error - Failed to deploy web package to app service. Request entity too large code 413

由于 zip 文件夹是 2GB,我尝试在 Magento 代码库的 upload_max_filesize = 3GPHP.ini 文件增加 .htaccess 的值

我目前的 azure 订阅只允许 1GB,当我下载主分支 repo 时,git 文件夹本身有 1GB 大小。

  • 是否可以只推送代码来构建管道而不是 .git 文件夹?

由于我是 Magento 的 CI/CD 新手,欢迎任何建议或方法更改

解决方法

由于 zip 文件夹是 2GB,我尝试在 Magento 代码库的 php.ini 和 .htaccess 文件中增加 upload_max_filesize = 3G 的值

使用 ZIP 或 WAR 文件将应用部署到 Azure 应用服务时,文件大小限制为 2048 MB(请参阅 here)。

是否可以只推送代码来构建管道减去 .git 文件夹?

在归档工件之前,您可以排除 .git 文件夹。在您的管道中,通常您可以这样做:

  1. 使用 Copy Files task 通过您在“Contents”字段中设置的 file matching patterns 将您需要的文件复制到目标文件夹。

    • 使用肯定模式仅包含您需要的文件。
    • 使用否定模式(以“!”开头)排除不需要的文件。在您的情况下,您可以尝试这种模式 (!.git/**)。
  2. 使用 Archive Files task 将目标文件夹中的文件归档为 ZIP 文件。

  3. 部署 ZIP 文件。

[更新]

请参考此示例以更新您的 YAML 管道:

steps:
--- some other tasks such as build,test ---
  . . .
- task: CopyFiles@2
  inputs:
    SourceFolder: 'path/to/Source/Folder'
    Contents: '!.git/**'  # Exclude the '.git' folder
    TargetFolder: 'path/to/Target/Folder'
    CleanTargetFolder: true
- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: 'path/to/root/Folder'  # This path is same as the 'TargetFolder' in the CopyFiles task
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: 'path/to/ZIP/file'  # This is the path to generate the ZIP file,e.g. "$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip"
    replaceExistingArchive: true

--- task to deploy the ZIP file to Azure ---