Description: In this discussion, I will guide you through the process of automatically publishing Docker images to Amazon Elastic Container Registry (ECR) using AWS Code Build. Learn how to trigger this process each time changes are pushed to AWS Code Commit. Dive into the step-by-step setup, enabling seamless integration between Code Commit, Code Build, and ECR for efficient image management in your AWS environment.
Setup Repository in CodeCommit:
The first setup to prepare code commit repository with source code, Dockerfile for build the image and buildspec.yml file for managing the build workflow
Kindly check the GitHub repository for reference URL
buildspec.yml
phases: pre_build: commands: - echo Logging in to Amazon ECR... - ECR_LOGIN=$(aws ecr get-login-password --region $AWS_DEFAULT_REGION) - echo $ECR_LOGIN | docker login -u AWS --password-stdin XXXXXXXX.dkr.ecr.ap-south-1.amazonaws.com - REPOSITORY_URI=XXXXXXXX.dkr.ecr.ap-south-1.amazonaws.com/reactrepository - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) - IMAGE_TAG=build-$(echo $CODEBUILD_BUILD_ID | awk -F":" '{print $2}') build: commands: - echo Build started on `date` - echo Building the Docker image... - docker build -t $REPOSITORY_URI:latest . - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG post_build: commands: - echo Pushing the Docker image to Amazon ECR... - docker push $REPOSITORY_URI
Setup ECR [Elastic Container Registry]
After setup repository Create the ECR private repository
To create code build navigate to CodeBuild stage and click on create buildstage
Permission: AmazonEC2ContainerRegistryFullAccess
No comments:
Post a Comment