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.
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 infrastructure for the Codebase.
The following steps use a Kubernetes cluster build farm.
Step 3: Add the Build and Push Step
In the stage's Execution, select Build and Push to GCR.
The unique name for this Step.
The Harness GCP Connector to use to connect to GCR. GCP account associated with the GCP Connector needs specific roles.
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.
The GCP Resource Manager project ID.
The name of the image you want to build.
The Docker build tag (--target).
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.
<+pipeline.sequenceId> is a built-in Harness variable. It represents the Build ID number, such as Build ID: 9. You can then use the same tag in another stage to reference the same build with its tag.
Enter the path of the Dockerfile. If you don't provide a name, Harness assumes the Dockerfile is in the root folder of the codebase.
Enter a path to a directory containing a Dockerfile.
Docker object labels to add metadata to the Docker image.
The Docker build-time variables (--build-arg).
The Docker target build stage (--target).
For example, build-env.
Remote Cache Image
The remote cache repository and build image need to be created on the same host and project. The Build creates the repository automatically if it doesn’t exist.
Set container resources
Maximum resources limit values for the resources used by the container at runtime.
Maximum memory that the container can use.
You can express memory as a plain integer or as a fixed-point number using suffixes G or M. You can also use the power-of-two equivalents Gi or Mi.
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 for the step. Once the timeout is reached, the step fails, and the Pipeline execution continues.
Set conditions to determine when the step should be executed. See Conditional Execution.
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.