DEV Community

Cover image for Understand How to Test Build and Push Your Artifacts
Pavan Belagatti
Pavan Belagatti

Posted on • Originally published at developer.harness.io

Understand How to Test Build and Push Your Artifacts

Docker made a revolution with containerization. It truly helped to bridge the gap between Dev and Ops teams. Similarly, the cloud providers introduced their own container registries to provide more security and governance. For example, Amazon has Elastic Container Registry (ECR), Microsoft has Azure Container Registry (ACR), and Google has a Google Container Registry (GCR). Container registries have become an integral part of any CI/CD pipeline to store images, metadata, and other important artifacts. In addition, they provide a secure way to store and share container images across a distributed system to help development teams build their software efficiently. In this article, we will explore the Amazon ECR container registry and see how to use it to push container images.

Understanding container registries

As the name suggests, container registries are used to store some valuable data related to a pipeline. In particular, for storing and sharing container images securely and reliably in a central repository, which multiple users and systems can access. This makes managing and deploying container images easy across a distributed system. Container registries also provide the ability to store multiple versions of a single container image, which allows for version control and rollback if needed. In addition, container registries can store and share sensitive data, such as credentials and secrets, across the team.

Overview of Amazon ECR

Amazon ECR is a fully managed service from Amazon Web Services (AWS). It is used to store and manage Docker images securely and reliably. In addition, Amazon ECR provides a simple web-based interface for creating, managing, and sharing Docker images and integrating them with other AWS services.

The following graphic shows how to push your container image to ECR from Harness CI:
amazon ecr

Prerequisites

Before you can push your container image to ECR from Harness, there are a few prerequisites:

  1. You must have an AWS account and have created a repository in ECR.
  2. You must have a Docker image of your application ready to push to ECR - We have a sample application with a Dockerfile. You can clone it and use it in this tutorial.
  3. You must have access to the AWS CLI or the AWS Management Console.
  4. To use Harness CI, you must have an account on Harness (it is Free). Harness offers hosted virtual machines (VMs) to run your builds. With Harness Cloud, you can build your code worry-free on the infrastructure that Harness provides. You don't have to spend time and effort to maintain build infrastructure; you can focus on developing great software instead.

Push your container image to ECR using Harness

We have a sample application you can fork and use. This sample code repo has a Dockerfile with instructions to build our image. We need to create an ECR repository on AWS to push our image. Then, we will use the Harness CI module to test, build, and push the image to our ECR repo.

This tutorial assumes you have the ECR repo created on AWS.
Log in to your Harness CI module and create a project.
Harness CI

Create your pipeline and add run step and ECR step to it.
configure run step

Similarly, add the ECR step
ECR step

Finally, your pipeline should look like this.
ci pipeline new

Basically, we are testing the application with a simple ‘npm test’ command as configured in the ‘Run’ step and pushing the built image to Amazon ECR (configured in the last step).

Save and run the pipeline.
console output result

In this tutorial, we explored Amazon ECR and saw how to use it to push our container images using Harness CI. Now that you have a better understanding of ECR and Harness CI, why not give it a try? Push your container images to ECR using Harness and speed up your build process.

Top comments (0)