settembre 7, 2017 - No Comments!

How to integrate AWS CodeCommit with BuddyBuild: a solution for our Continuous Delivery

AWS CodeCommit - BuddyBuild integrationUsing a Continuous Delivery solution in a software development project is really useful because it brings a great saving of time and costs while providing fast feedbacks on the build.

In our opinion, a Mobile project needs a Continuous Delivery because it enables automation of all time-consuming operations such as tests, builds and releases.

These advantages are even more obvious if applied to a team similar to ours, that follows an iterative-incremental approach to the development cycle with frequent releases.

While developing a mobile app for a customer working on payment services we found ourselves using BuddyBuild as Continuous Delivery service and AWS CodeCommit as Git repository.

Currently BuddyBuild offers a full integration with GitHub, BitBucket and GitLab. It is also possible to use other Git services through SSH protocol, but this approach does not support the trigger of an automatic build after a Git push.

Therefore we had to find an alternative solution in order to have a complete and automated Continuous Delivery cycle.

First Approach

Initially we had to configure a local script shared throughout team members to automatically trigger the build at every push towards CodeCommit. In this way we use a "git post-push" hook to call the BuddyBuild API.

This approach gave us some trouble over time.

In particular we faced problems with new team members which had to configure the script on their own machine. Furthermore every change to the script had to be propagated on every already configured environment.

New Approach with AWS Lambda

AWS LambdaRecently, AWS introduced the opportunity to trigger an AWS Lambda from a CodeCommit event such as a push, branch creation, etc.

Therefore we decided to develop a small project to integrate CodeCommit and BuddyBuild. We created a Lambda which is triggered by CodeCommit at every push and uses the BuddyBuild API to run a new build.

DockerWe create a new project using Docker as Development Environment. This permits to have an environment as similar as possible to the container inside which AWS Lambda runs the code. Other reasons we like working with Docker are that we can replicate through different team members the same Environment and we can keep our host machines clean.

We use Serverless Framework to develop and deploy the Lambda project but at time of writing there is no support to the CodeCommit event, so we have to manually configure the trigger from the AWS Console.

The function itself is very simple. It's an HTTP request to BuddyBuild API that needs only APP_ID and USER_TOKEN to be configured.

Here a piece of the Lambda source code:

 headers: {'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`},
 uri: `${process.env.APP_ID}/build`,
 method: 'POST'
} /*, [...] */ )

For security reason we get BuddyBuild tokens and AWS credentials from environment variables, in this way everyone can configure these variables with an .env file without pushing them to the repository.

We chose to open source the code which is now publicly available on GitHub: CodeCommit - BuddyBuild Integration: all feedbacks are welcome 🙂

Published by: xpeppers in XPeppers

Leave a Reply