in one of our projects it was required to create a docker image and push it to ECR
i ll show you how you can employ aws codebuild for this purpose
go to aws management console
go to codebuild
go to create build project (click on the orange button on top right corner)
add a project name and a description
make sure you add a meaningful description and a name
then you have to specify the source of the code (from where you want to trasfer the code to codebuild to build it )
there are few options in this
you can pick up the code from an s3 bucket
aws codecommit ,github,github enterprise or bitbucket
then you have to specify the environment on top of which this building process run
here we are building the code in a docker image
there are 2 options
you can create a custom image for this or an image provided by aws
if you need a custom image ,you need to create it and push it to ECR in your aws account and pull it from ecr when you are configuring the environment in codebuild
or else you can use a managed image provided to you by aws
in older aws codebuild console you willl have to speccify the runtime from console but with the new console you will have to specify the runtimes in the build spec .yml in the code
give a role
provide the build spec file in the code
enable docker image creation
below is a sample buildspec.yml file
at the end of the codebuild you can either publish a docker image or push artifctasts that were created during the build process to an s3 bucket
further you can track the entire build process with logs