DEV Community

loading...
AWS Community Builders

AWS CI/CD pipeline with CodeGuru & UnitTest

Salah Elhossiny
ML engineer || AWS Certified MLS || AWS Community Builders member || Fullstack developer
Updated on ・5 min read

This post explains how to build a CI/CD pipeline using AWS services. It also explains how to organize various ways to improve code quality (CodeReview & UnitTest) in the AWS pipeline.

It covers simple branch build and deployment, UnitTest report, and CodeGuru which automatically performs code review when create pull-requests.

1

AWS Code Series (AWS CI/CD services)

You can use the AWS Code Series. Code series is a fully managed service, so there is no need for a infrastructure.

  • CodeCommit: AWS CodeCommit is a fully-managed source control service that hosts secure Git-based repositories.
  • CodeBuild: AWS CodeBuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy.

  • CodeDeploy: AWS CodeDeploy is a fully managed deployment service that automates software deployments to a variety of compute services such as Amazon EC2, AWS Fargate, AWS Lambda, and your on-premises servers.

  • CodePipeline: AWS CodePipeline is a fully managed continuous delivery service that helps you automate your release pipelines for fast and reliable application and infrastructure updates.

AWS CodeGuru

Amazon CodeGuru is a machine learning service for automated code reviews and application performance recommendations.

It helps you find the most expensive lines of code that hurt application performance and keep you up all night troubleshooting, then gives you specific recommendations to fix or improve your code. It supports JAVA, repository can use GitHub or CodeCommit. It is also easy to integrate.

codequeility

CodeGuru Reviewer that provides Automated CodeReview

Amazon CodeGuru Reviewer finds issues in your code and recommends how to remediate them.

git-pr-codereviewer

The contents that CodeGuru Reviewer detects can be this categories.

  • AWS Best Practices : AWS APIs contain a rich set of features to ensure performance and stability of software.
  • Concurrency : CodeGuru Reviewer identifies problems with implementations of concurrency in multithreaded code

  • Resource Leaks : CodeGuru Reviewer looks for lines of code where resource leaks might be occurring.

  • Sensitive Information Leak : Sensitive information in code should not be shared with unauthorized parties.

CodeGuru Profiler

Amazon CodeGuru Profiler is always searching for application performance optimizations, identifying your most expensive lines of code and recommending ways to fix them to reduce CPU utilization, cut compute costs, and improve application performance.

For setup steps, you can find it here and here

CodeCommit Setup and source code download

  1. let’s set up the code in Cloud9. Enter the following command in the terminal of Cloud9.
~ git clone https://github.com/aws-samples/amazon-cicd-concurrency-sample-application.git
Enter fullscreen mode Exit fullscreen mode
  1. If the command is executed successfully, created a folder name amazon-cicd-concurrency-sample-application in the file cloud9 file tree.

codecommit-master2

  1. clone gets the master branch. If you look at the contents of the folder, there are no other files except the README.md file. the real source code in develop, pull the develop branch.
~ cd amazon-cicd-concurrency-sample-application
~ git checkout origin/develop -b develop
Enter fullscreen mode Exit fullscreen mode

codecommit-develop2

  1. To check the output of CloudFormation, go to the CloudFormation console.

go to the CloudFormation console : https://console.aws.amazon.com/cloudformation

  1. Select Stacks from the left menu and select CodeQuality-Workshop you created. You can check the detailed information of the stack created here.

codecommit-cloudformation-select-stack

  1. Select Outputs at the top of the stack details. There you copy the URL of CodeCommit that lab `a repository.

codecommit-cloudformation-stacks-output

  1. Change the url of origin to the address of the newly created codecommit at https://github.com/aws-samples/amazon-cicd-concurrency-sample-application.git.

Entering the following in the terminal of Cloud9. is the changeCodeCommit copied from the Stack of CloudFormation.


~ git remote set-url origin <YOUR-REPOSITORY-URL>

After finished the command, check again with git remote show origin, and you can see that the URL of origin has been changed to your CodeCommit address.

After that, you can checkout to master branch first then push commits. Then, develop branch and push commits.


~ git checkout master
~ git push
~ git checkout develop
~ git push

CodeGuru Reviewer setup

codeguru-reviewer-select

  • Select Associate repository at the top right.

codeguru-associate-repository

  • Select AWS CodeCommit as the Source provider for Repository details, then select concurrencysample at Repository location. and click Associate.

codeguru-associate2

  • Check the connected concurrencysample in Codeguru’s Dashboard.

codeguru-fin

  • Now CodeGuru and Codecommit are linked.

CodeGuru profiler setup

codeguru-profiler-select

  • Select Create profiling groups at the top right.

codeguru-profiler-group

  • Enter concurrencysample-profiler in Name of Profiling group details in Create profiling group. click Create at the bottom right.

codeguru-profiler-create

  • Enter WebAppRole in choose users and roles in the Manage permissions for concurrencysample-profiler box. Select the checkbox on the left and click Save to save.

1

  • Profiler can be found in the main of the source code, ConcurrencyCheckout.java.

  • Now CodeGuru profiler and instance is complete.

CodeBuild report

codebuild-report-4

  • Enter Concurrency-Unittest-Report in Report group name of Rport group configuration. Select Test for the report type. Uncheck the box for Export to Amazon S3.

codebuild-report-5

  • To copy the ARN of the report groups, Concurrency-Unittest-Report from Report groups. The results of the Unittest here will now be shown. Copy the contents of Report group ARN of Configuration.

codebuild-report-copy-arn

  • Now let’s go back to Cloud9 and edit buildspec.yml. buildspec.yml is located in ConcurrencySample’s root directory.

  • Double-click the file to add content. Paste the Report group ARN to .

yml
reports:
<YOUR-REPORT-GROUP-ARN>:
files:
- '**/*'
base-directory: 'build/test-results/test'

  • Commit and push them to codecommit.


~ cd amazon-cicd-concurrency-sample-application
~ git add .
~ git commit -m "change Buildspec.yml"
~ git push

Now we finished the first part in this series.

Discussion (0)