Learn how to create CodeBuild with custom image with easy steps. Here I am going to create a build project with custom image of golang’s latest version.

Create CodeBuild with Custom Image in AWS | Personal Blog

  • Last Modified: 11 Nov, 2022

How did it start?

“Hey, I need you to create a CodeBuild project for me.”

I turned around from my computer screen to see my boss walking towards me. We had just moved into our new office and everyone was still getting used to the change. It had only been two weeks, but it felt like forever.

“Sure thing,” I said as I got up from my chair. “What do you need?”

He handed me a sheet of paper with all the details on it. “We want to create a custom image for CodeBuild that will include all of our company’s dependencies.”

I nodded as I started to understand what he was asking. “Do you have any existing scripts or code we can use as a template?”

He shook his head. “No, we need something completely new.”

So I started working on the project to create the Build Project with the custom image. The software which we were using was working over the golang.

Today, here I am going to create a build project with a custom image of golang’s latest version. Because default runtime environment images for the code build support the limited versions of the golang upto 1.16 (by the writing of this Article). I want to use the latest golang’s version.

Setup

  1. Create a private repository in the AWS ECR. Learn More

  2. You need to run Docker Login, so we can push to the ECR

    aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account-id>.dkr.ecr.us-east-1.amazonaws.com
    

Custom Image

  1. Download the golang base image

  2. Re Tag the image as per your Amazon Docker/Container Registery

  3. Push to the repository

    docker pull golang
    docker tag golang:latest <account-id>.dkr.ecr.us-east-1.amazonaws.com/<your-ecr-repo>:latest
    docker push 983430949435.dkr.ecr.us-east-1.amazonaws.com/<your-ecr-repo>:latest
    

Code Build

  1. Create a Code Build Project. Learn More
  2. You will need to make sure to use the Custom image for Environment Image and Project Service Role for the Image Pull Credentials

You will need to make sure to use the Custom image for Environment Image and Project Service Role for the Image Pull Credentials

You will need to make sure to use the Custom image for Environment Image and Project Service Role for the Image Pull Credentials

Test

Since you have created a project and attached the source code, I assume you already have an errorless buildspec.yaml ready in your code. Now you can start a build, and it will pass. If you want to learn how to build a gohugo serverless website framework, then you can read this.

...



See Also

comments powered by Disqus