Search code examples
node.jsamazon-web-servicesamazon-ec2amazon-elastic-beanstalkaws-codepipeline

.ebextensions with CodePipeline and Elastic Beanstalk


I started working on my first CodePipeline with node.js app which is hosted on github. I would like to create simple pipe as follow:

  1. Github repo triggers pipe
  2. Test env (Elastic Beanstalk app) is built from S3 .zip file
  3. Test env runs npm test and npm lint
  4. If everything is OK then QA env (another EB app) is built

For above pipe I've created .config files under .ebextensions directory:

  1. I would like to use npm install --production for QA and PROD env, but it seems that EC2 can't find node nor npm. I checked logs and EC2 triggered npm install by default in temporary folder, then it fails on my first script and app catalogue is always empty.

container_commands: install-dev: command: "npm install" test: "[ \"$NODE_ENV\" = \"TEST\" ]" ignoreErrors: false install-prod: command: "npm install --production" test: "[ \"$NODE_ENV\" != \"TEST\" ]" ignoreErrors: false

  1. Is it posible to run unit tests and linting without jenkins?

container_commands: lint: command: "npm run lint" test: "[ \"$NODE_ENV\" = \"TEST\" ]" ignoreErrors: false test: command: "npm run test" test: "[ \"$NODE_ENV\" = \"TEST\" ]" ignoreErrors: false

I set NODE_ENV for each Elastic Beanstalk instance. No matter what I will do every time my pipe fails because of npm is not recognized, but how is it possible if I'm running 64bit Amazon Linux with node.js ? What's more I cannot find any examples about CodePipeline with node.js in AWS Docs. Thanks in advance!


Solution

  • Have you incorporated CodeBuild into your pipeline?

    You should

    1) Create a pipeline whose source is your github account. Go through the setup procedure so that commits on a particular branch trigger the Codepipeline

    2) Create a test stage in your Codepipeline which leverages the CodeBuild service. In order to run your Node tests, you might need to provide a configured build environment. And you probably also need to provide a build spec file that specifies the tests to run etc.

    3) Assuming that the test stage passes, you can determine if the pipeline continues to another stage which is linked to an elasticbeanstalk app environment which supports the Node platform. These environments are purely for artifacts that have passed testing, so I see no need to have the .ebextensions commands written above.

    Have a read of what CodeBuild can do to help you run tests for Node,

    https://aws.amazon.com/codebuild/

    Good luck!