【发布时间】:2020-08-20 23:58:06
【问题描述】:
我正在使用 AWS 代码提交进行测试和部署,并且需要在使用 codeBuild 运行单元测试之前预安装 redis、chromium。所有安装配置都在 .ebextensions 上,如果我删除构建步骤,它可以在 EB 实例上正常工作。
但是当我使用 codeBuild 管道时, buildspec.yml 在运行测试之前似乎没有运行 .ebextension 配置。有人知道如何在 pre_build 中运行 .ebextensions 吗?
version: 0.2
phases:
install:
runtime-versions:
nodejs: 12
commands:
- echo Installing jest...
- npm install -g jest
pre_build:
commands:
- echo Installing source NPM dependencies...
- npm install
- echo Starting app...
- npm start
build:
commands:
- echo Build started on `date`
- echo Running unit tests...
- npm run test
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- **/*
- .ebextensions/**/*
代码构建日志
[2020/05/05 11:55:29 Waiting for agent ping
[2020/05/05 11:55:31 Waiting for DOWNLOAD_SOURCE
[2020/05/05 11:55:32 Phase is DOWNLOAD_SOURCE
[2020/05/05 11:55:32 CODEBUILD_SRC_DIR=/codebuild/output/src129341116/src
[2020/05/05 11:55:32 YAML location is /codebuild/output/src129341116/src/buildspec.yml
[2020/05/05 11:55:32 Processing environment variables
[2020/05/05 11:55:32 Selecting 'nodejs' runtime version '12' based on manual selections...
[2020/05/05 11:55:32 Running command echo "Installing Node.js version 12 ..."
Installing Node.js version 12 ...
[2020/05/05 11:55:32 Running command n $NODE_12_VERSION
installed : v12.16.1 (with npm 6.13.4)
[2020/05/05 11:55:41 Moving to directory /codebuild/output/src129341116/src
[2020/05/05 11:55:41 Registering with agent
[2020/05/05 11:55:41 Phases found in YAML: 4
[2020/05/05 11:55:41 BUILD: 3 commands
[2020/05/05 11:55:41 POST_BUILD: 1 commands
[2020/05/05 11:55:41 INSTALL: 2 commands
[2020/05/05 11:55:41 PRE_BUILD: 4 commands
[2020/05/05 11:55:41 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[2020/05/05 11:55:41 Phase context status code: Message:
[2020/05/05 11:55:41 Entering phase INSTALL
[2020/05/05 11:55:41 Running command echo Installing jest...
Installing jest...
.................
[2020/05/05 11:55:41 Running command npm install -g jest
....................
[2020/05/05 11:55:55 Entering phase PRE_BUILD
[2020/05/05 11:55:55 Running command echo Installing source NPM dependencies...
Installing source NPM dependencies...
如果我看到日志,它不会在运行测试之前运行 .ebextensions 脚本来安装 Redis 和其他软件。
【问题讨论】:
-
.ebextensions由 beanstalk 运行,而不是 codebuild。 -
而且你不能在代码构建中轻松运行它们,因为它们具有特定于 Beanstalk 的格式。
-
那么我如何在 codebuild 运行测试之前安装我的依赖项?将它们全部复制到 buildspec 中?
-
我添加了更多细节的答案,因为它太长了,无法在 cmets 中写入。
标签: node.js amazon-web-services aws-codebuild aws-codecommit