Search code examples
node.jsamazon-web-servicesaws-codebuildaws-codecommit

AWS codeBuild doesn't run the .ebextension config


I am using AWS code commit to test and deployment and needs to pre-install redis, chromium before running the unit tests using codeBuild. All the installation config is there on .ebextensions which works fine on EB instance if I remove the build step.

But when I use the codeBuild pipeline the buildspec.yml doesn't seems to run the .ebextension config before running the tests. Anyone know how can I run the .ebextensions in pre_build ?

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/**/*

Code build logs


[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...

If I see the logs, it doesn't run the .ebextensions script to install Redis and other software before running tests.


Solution

  • .ebextensions are executed by Elastic Beanstalk.

    CodeBuild is not going to run them, and you can't execute them in CodeBuild as they have format specific to Elastic Beanstalk.

    To install dependencies for your tests you have to manually do it using yum or apt commands, depending on your CodeBuild image.

    You can also create bash script files in your deployment package which you can execute in the CodeBuild. The script files can then install all dependencies.

    Alternatively, it you have lots of complex dependencies, config files, you can deploy your application as docker on Beanstalk. This way your docker image will contain all required dependencies, including those for testing.

    There is also possibility of using eb cli in CodeBuild:

    However, I'm not sure if this would be suited for your use case.