Circle CI + AWS ECR Demo
Deploy your Docker Image to AWS ECR use CircleCI. :)
License
MIT
Hello!
I'm going to share about how to deploy Docker Image to Amazon ECR using CircleCI. What is CircleCI? CircleCI is a CI/CD (Continuous Integration/Continuous Deployment) platform. We will learn together to deploy Docker Image to Amazon ECR. If you want to know more about Docker or Docker Image, please visit their official documentation. So, what is Amazon ECR? Amazon ECR (Amazon Elastic Container Registry) is an Amazon Services that you can use to store Docker Image. Okay, let's get started.
You will need to create ECR Repository. You also can check here to understand how to create ECR Repository. I will give some screen captures.
dotnet new webapi -o CircleCIDemo
..gitignore
and .sln
. Use dotnet new gitignore
and dotnet new sln
. After that connect solution with project, use dotnet sln add CircleCIDemo
.
FROM mcr.microsoft.com/dotnet/sdk:6.0 as build
WORKDIR /app
COPY . .
RUN dotnet restore
RUN dotnet build -c Release --no-restore
RUN dotnet publish -c Release --no-restore --no-build -o publish
FROM mcr.microsoft.com/dotnet/aspnet:6.0 as runtime
WORKDIR /app
COPY --from=build /app/publish /app
CMD [ "dotnet CircleCIDemo.dll" ]
version: 2.1
orbs:
aws-ecr: circleci/aws-ecr@8.0.0
workflows:
build_and_push_image:
jobs:
- aws-ecr/build-and-push-image:
context: dev # update with your CircleCI Context
public-registry: true # use this if you use public repository
repo: <your repo name> # update with your repo name
Please use context to fill some environment variables. You can check here.
I've defined some variables like this.
You need to define some variables like AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ECR_REGISTRY_ID, and AWS_REGION.
More information about the orbs, you can check here.
Done. You can push the config and try build from CircleCI.
You will see this screenshot if you successfully configure the repository.
You may try the ECR. If you are using the public repository, you can pull it without Authentication. Different with private repository, you should have the Authentication before pull the Docker image.
docker pull <your ecr name>
. As example, docker pull public.ecr.aws/f2t8g3i6/dotnet-demo-berv
.docker run -p 8080:80 --name dotnet-demo -d <your ecr name>
. Example: docker run -p 8080:80 --name dotnet-demo -d public.ecr.aws/f2t8g3i6/dotnet-demo-berv
Thank you for reading. If you have questions, don't worry to ask me.