AWS CodeBuild — Using Buildpacks to build Docker image

John Gakhokidze
Oct 19, 2020

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
  2. Do not use Google builder — it will fail. Heroku worked for me as I used the Python app.

--

--