In this video, you’ll see how to build applications locally using AWS CodeBuild.
With the CodeBuild local agent, you can test the integrity and contents of buildspec files locally,
build and test applications locally before committing,
and identify and fix errors quickly from your local development environment.
AWS CodeBuild is a fully managed service, with no servers to provision and scale,
and no software to install, configure, and operate.
You just specify the location of your source code, choose your build settings,
and CodeBuild runs build scripts for compiling, testing, and packaging your code.
CodeBuild now offers local build support.
Let’s see how to set that up.
For the purposes of this example, we’ll use the Cloud9 integrated development environment (IDE),
but you can use any local development environment.
By default, Cloud9 instances already have Docker and Git installed.
Note that the development environment you plan to use must also have Docker and Git installed
before you can set up CodeBuild locally.
Let’s begin by cloning the AWS Git repository that contains Docker images
for the available CodeBuild versions.
Now that we’ve cloned the necessary repository, let’s take a look at its contents.
This repository contains several different CodeBuild images and the files needed to build and use them.
For the purposes of this example, we’ll use the CodeBuild 3.0 Docker image.
Here’s the Dockerfile for CodeBuild 3.0 and its necessary files.
Let's return to the console and navigate to this file directory so we can build the image.
Now we’ll use the Docker “build” command to build AWS CodeBuild 3.0 locally.
Building the Docker image from this Dockerfile can take around 30 minutes to successfully execute.
Ensure that your local environment has at least 10 GB of free space to complete the build.
The Docker image was successfully built and tagged.
Next, let’s clear the screen and use the “docker pull” command to download the CodeBuild local image.
The CodeBuild local image runs the CodeBuild local agent,
which acts as a local version of the remote CodeBuild build servers.
This allows you to use CodeBuild to locally build and package an application from within a Docker container.
Now that the Docker image for the CodeBuild local agent has been pulled,
let’s return to the home environment to build a sample web application.
First, we’ll download a CodeBuild script you can use to run your local builds.
Next, we’ll make the shell script we just downloaded executable.
For our purposes, let’s clone a sample Java web application to build with CodeBuild locally.
Now that the sample Java web application has been cloned to the home environment,
let’s try running the script on the application as-is.
First, we’ll specify the shell script that we’re running.
Next, we need to specify the tag of the CodeBuild Docker image we built.
Next, we’ll specify the desired output artifact directory.
Finally, we’ll specify the directory containing the source code.
As you can see, we got a runtime error that says a needed YAML file does not exist.
To successfully build a project with CodeBuild,
you must create a buildspec.yml file at the root of the source directory.
This file provides instructions to CodeBuild on build configurations and options.
Let’s create the file now.
Now that we’ve created a build specifications file, let’s return to the home environment.
Let’s run the CodeBuild script again.
As you can see, the CodeBuild agent successfully built the sample web application in a local
environment from within a Docker container.
Let’s take a look in the artifacts directory.
Here we can see the output artifact of the CodeBuild build.
To ensure you’re aware of any new CodeBuild agent versions,
you can create an Amazon Simple Notification Service (Amazon SNS) subscription.
Let’s do that now.
We’ll paste in a specific Topic ARN that sends out notifications
whenever a new CodeBuild version is available.
Now we can proceed through the steps and create the subscription.
Once the subscription is confirmed, we’ll receive email notifications whenever a new
version of CodeBuild becomes available.
You’ve just seen how to build applications locally using AWS CodeBuild.
Thanks for watching.
Now it's your turn to try.