Build and Push to GCR

Updated 2 months ago by Manish Jaiswal

This topic provides settings to Build and Push an image to Google Container Registry (GCR).

The following steps build an image and push it to GCR.

In this topic:

Before You Begin

Step 1: Create the CI Stage

In your Harness Pipeline, click Add Stage, and then click CI.

Step 2: Define the Build Farm Infrastructure

In the CI stage Infrastructure, define the build farm for the codebase.

The following steps use a Kubernetes cluster build farm.

See Define Kubernetes Cluster Build Infrastructure.

Step 3: Add the Build and Push Step

In the stage's Execution, select Build and Push to GCR.

Step Parameters

Name

The unique name for this Step.

ID

See Entity Identifier Reference.

GCP Connector

The Harness GCP Connector to use to connect to GCR. GCP account associated with the GCP Connector needs specific roles.

See Google Cloud Platform (GCP) Connector Settings Reference.

Host

The GCR registry hostname. For example, us.gcr.io hosts images in data centers in the United States in a separate storage bucket from images hosted by gcr.io.

Project ID

The GCP Resource Manager project ID.

Image Name

The name of the image you want to build.

Tags

Docker build tag (-t).

Each tag should be added separately.

Option: Add a Tag using Harness Expression

You can tag the image in any way, but a Harness expression can be very useful.

The <+pipeline.sequenceId> is a built-in Harness variable. It represents the Build ID number, for example, Build ID: 9. You can then use the same tag in another stage to reference the same build by its tag.

Dockerfile

Enter the path of the Dockerfile. If you do not provide a name, Harness assumes the Dockerfile is in the root folder of the codebase.

Context

Enter a path to a directory containing a Dockerfile.

Labels

Docker object labels to add metadata to the Docker image.

Build Arguments

The Docker build-time variables (--build-arg).

Target

The Docker target build stage (--target).

For example, build-env.

Remote Cache Image

The remote cache repository needs to be created in the same host and project as the build image. The repository will be automatically created if it doesn’t exist.

Set container resources

Maximum resources limit values for the resources used by the container at runtime.

Limit Memory

Maximum memory that the container can use.

You can express memory as a plain integer or as a fixed-point number using one of these suffixes: G, M.

You can also use the power of two equivalents: Gi, Mi.

Limit CPU

See Resource units in Kubernetes.

Limit the number of cores that the container can use.

Limits for CPU resources are measured in CPU units.

Fractional requests are allowed. The expression 0.1 is equivalent to the expression 100m, which can be read as one hundred millicpu.

Timeout

Timeout for the step. Once the timeout is reached, the step fails, and the Pipeline execution continues.

Advanced:

Conditional Execution

Set conditions to determine when the step should be executed. See Conditional Execution.

Failure Strategy 

Define one or more failure strategies to control the behavior of your pipeline when your step execution encounters an error. See Failure Strategy

Step 4: Specify Codebase Branch or Tag at Pipeline Execution

Select the Codebase Git Branch or Git Tag to use for the execution.

Enter the branch or tag and click Run Pipeline.

 Step 5: View the Results

You can see the logs for the Build and Push step in the Pipeline as it runs.

In your Harness project's Builds, you can see the build listed.

On GCR, you can see the image that you pushed.

See Also


Please Provide Feedback