AWS CodeBuild — Using Buildpacks to build Docker image

AWS CodeBuild provides images for your CodeBuild stage. A standard way to build Docker image is to use “docker build” command.

Docker native commands are not only way to build images, and and at times they are not optimized. Here are several alternatives:

Jib Maven if you build your Java app using Maven

Graal VM

Gradle plugin

Cloud Native Buildpacks

So, what if you want to use one of those tools in CodeBuild?

The answer is — no problem, CodeBuild, is really flexible and you can insert your commands in buldspecs.yml

Let’s see the original file with “docker build

This is standard buildspec .yml — based on AWS Documentation

By modifying just 2 lines, you will now use “pack” command from Buildpacks.io .

Check lines 8 and 14 — it’s as simple as that :)

Some notes:

  1. Both buildspec.yml files are available at Github

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store