如何在 ElasticBeanstalk 中提取 AWS CodeBuild 的输出 zip?

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

我正在尝试让 AWS CodePipeline 与 S3 源代码、CodeBuild 和 Elastic Beanstalk(nodejs 环境)一起工作

我的问题在 CodeBuild 和 Beanstalk 之间。

我让 CodeBuild 通过工件输出最终 nodeJS 应用程序的 zip 文件。这是我的 CodeBuild buildspec.yml

version: 0.1

phases:
  install:
    commands:
      - echo Installing Node Modules...
      - npm install -g mocha
      - npm install
  post_build:
    commands:
      - echo Performing Test
      - npm test
      - zip -r app-api.zip .
artifacts:
  files:
    - app-api.zip

当我手动运行 CodeBuild 时,它成功地将 zip 放入 S3。当我运行 CodePipeline 时,它将 zip 放在 /var/app/current 中的每个 Elastic Beanstalk 实例上作为 app-api.zip

我想要的是将 app-api.zip 提取为 /var/app/current。就像通过 Elastic Beanstalk 控制台界面手动部署一样。

amazon-web-services amazon-s3 amazon-elastic-beanstalk aws-codepipeline aws-codebuild
2个回答
11
投票

首先,快速解释一下。 CodePipeline 将您指定为工件的任何文件发送到 Elastic Beanstalk。在你的情况下,你发送

app-api.zip

您可能 想要 做的是发送所有文件,但不将它们打包成 ZIP。

让我们将您的

buildspec.yml
更改为不创建
app-api.zip
,而是将原始文件发送到 CodePipeline。

version: 0.1

phases:
  install:
    commands:
      - echo Installing Node Modules...
      - npm install -g mocha
      - npm install
  post_build:
    commands:
      - echo Performing Test
      - npm test
#     - zip -r app-api.zip . **<< Remove this line**
artifacts:
  files:
    - '**/*'
# Replace artifacts/files with the value shown above

0
投票

2023 更新

从 CodeBuild 向 Beanstalk 发送一个压缩的工件似乎仍然存在很大问题。在我的例子中,部署文件夹在安装期间使用

maven-antrun-plugin
插件压缩,而不是像上面那样通过
buildspec
压缩,并且在上传到 EB 控制台或 CLI 时效果很好。

但是当 CodeBuild

buildspec
指向同一个压缩工件时,EB 因错误而失败

An error occurred during execution of command [app-deploy] - [CheckProcfileForJavaApplication]. Stop running the command. Error: there is no Procfile and no .jar file at root level of your source bundle 

事实并非如此,因为我可以下载/解压缩部署文件夹并在本地运行 jar。它与我通常通过控制台上传的内容相同。

我终于注意到

eb-engine.log
的细微差别。

/opt/elasticbeanstalk/deployment/app_source_bundle: Zip archive data, at least v1.0 to extract
本地构建并上传到控制台 - 作品

/opt/elasticbeanstalk/deployment/app_source_bundle: Zip archive data, at least v2.0 to extract
在 CodeBuild 中压缩 - 不起作用

@Unsigned 提供的解决方案似乎仍然是解决方案,或者说是最佳实践。

© www.soinside.com 2019 - 2024. All rights reserved.