DEV Community

t.okazaki
t.okazaki

Posted on

AWS Codebuild: Prepare your own custom build environment

AWS Codebuild is a fully managed continuous integration service that compiles source code, runs tests, and produces software packages that are ready to deploy.You can create custom build environments that use your own build tools.

This feature caught my attention because I am a little bothered that existing fully managed CI service has changed their build environment and our development team took a time to repair the build script.
( Of ourse, you can also get started quickly by using prepackaged build environments on Codebuild )

How to prepare your own custom build environment

We have to prepare a Docker image for custom build environment. Hopefully, AWS give us sample docker images. You can get them by following.

$ git clone https://github.com/aws/aws-codebuild-docker-images.git
$ cd aws-codebuild-docker-images
$ cd ubuntu/standard/4.0
$ docker build -t aws/codebuild/standard:4.0 .
$ ls -1
Dockerfile
amazon-ssm-agent.json
dockerd-entrypoint.sh
legal
runtimes.yml
ssh_config
tools

$ docker run -it --entrypoint sh aws/codebuild/standard:4.0 -c bash
Enter fullscreen mode Exit fullscreen mode

In the Dockerfile, various programming language packages, browsers and another build tools are installed
For example:

  • ChromeDriver, Chrome, Firefox
  • Java, Ruby, Python, PHP, Golang, Nodejs

You can add or choose packages which you need by customising above Dockerfile.

Local debugging your custom build environment

You can run Codebuild on your laptop using Docker. You can test and build your custom Codebuild docker image and your application locally before committing.

Pull the docker image of the local CodeBuild agent.

docker pull amazon/aws-codebuild-local:latest --disable-content-trust=false
Enter fullscreen mode Exit fullscreen mode

Download the shell script named codebuild_build.sh from AWS GIthub
https://github.com/aws/aws-codebuild-docker-images/tree/master/local_builds

./codebuild_build.sh -i codebuild4-test:1.0 -a /tmp -s /work/repo -m
Enter fullscreen mode Exit fullscreen mode

options

  • -i Specify docker image tag of your custom build environment image.
  • -a Used to specify an artifact output directory.
  • -s Used to specify a source directory. Defaults to the current working directory.
  • -m Used to mount the source directory to the customer build container directly.
  • -c Use the AWS configuration and credentials from your local host. This includes ~/.aws and any AWS_* environment variables.

References

Top comments (0)