Custom Images
Harness provides the flexibility to use custom images in your IaCM stage, which applies to individual infrastructure provisioning steps, such as the init
step in an OpenTofu or Terraform pipeline stage. This guide walks you through the process of creating a custom image and incorporating it into your Harness pipelines.
Network Connectivity Requirements
Create an image
Harness allows you to create custom images based on a provided base image. This enables you to tailor the image to your specific needs and use it in your workflows.
Custom images created from our base image are version-locked, meaning they won't automatically update with new releases. While an outdated version might not cause pipeline failures, it could lack features, have security vulnerabilities, or face compatibility issues.
To keep your custom image current with our latest improvements, periodically check for updates to our base image and rebuild your custom image as needed. Proactively monitor our releases to fully benefit from the latest enhancements.
Harness will log a warning if your image version is five versions behind the latest release, helping you detect out-of-date versions.
Create a custom image
Create custom images with root-based and rootless custom containers for Harness Cloud and Kubernetes environments. The following examples demonstrate package installation via microdnf
and direct binary installation for tools like kubectl
.
- Root-based custom container
- Rootless custom container
Create a root-based custom container for use in Harness Cloud and Docker.
Once your image is created, build with: docker build -f Dockerfile --platform linux/amd64 --target custom-root -t harness_terraform_vm_custom
.
FROM plugins/harness_terraform_vm AS custom-root
## Example of an installation using the in-built "microdnf" package manager
RUN microdnf install -y wget
RUN microdnf clean all
## Example of downloading and installing a binary directly
## Binaries need to be suitable for the amd64 architecture
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
RUN install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
Create a custom container for use in Kubernetes.
Once your image is created, build with: docker build -f Dockerfile --platform linux/amd64 --target custom-root -t harness_terraform_custom
.
FROM plugins/harness_terraform AS custom-rootless
## Switch to root temporarily so that we can install extra tools
USER root
## Example of an installation using the in-built "microdnf" package manager
RUN microdnf install -y wget
RUN microdnf clean all
## Example of downloading and installing a binary directly
## Binaries need to be suitable for the amd64 architecture
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
RUN install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
## Switch back to the "app" user now that all tools are installed
USER app
Cloud v0.56 or later
Use your own image
To use your custom image in a step, create a reference in the YAML configuration indicating that the step should use your image.
- step:
type: IACMTerraformPlugin
name: apply
identifier: apply
timeout: 2h
spec:
command: apply
image: plugins/private_harness_terraform_plugin # (1)
connectorRef: privateConnector # (2)
In this example, the image
attribute (1) in the YAML points to the plugin image hosted in the Elastic Container Registry (ECR) to store your Docker images securely.
If it's in a private ECR, create a connector and define the connectorRef
(2) to allow Harness access and to ensure the apply
step in your pipeline uses the 'private_harness_terraform_plugin' and has access to kubectl
and kustomize
for operations.
IACM execution-config
To use images from your repository in an IACM stage, you can use the execution-config
API endpoints.
Although some images mentioned here are also used by CI, it's important to note that any overrides specified using the IACM execution-config
APIs are not applied to CI stages and vice versa. The images that can be overridden are:
- harness/ci-addon.
- harness/ci-lite-engine.
- harness/drone-git.
- plugins/harness_terraform.
- Set images
- Reset default images
- List custom images
- View default images
Set your Images with the update-config
endpoint:
curl \
-X POST \
-H 'x-api-key: <pat>' \
'https://app.harness.io/gateway/iacm-manager/execution-config/update-config?accountIdentifier=<account>&infra=k8' \
--header 'Content-Type: application/json' \
--data-binary @- << EOF
[
{
"field": "addonTag",
"value": "<your_repo>/ci-addon:1.16.44"
},
{
"field": "liteEngineTag",
"value": "<your_repo>/ci-lite-engine:1.16.37"
},
{
"field": "gitCloneTag",
"value": "<your_repo>/drone-git:1.5.0-rootless"
},
{
"field": "IACMTerraformTag",
"value": "<your_repo>/harness_terraform:latest"
},
{
"field": "IACMOpentofuTag",
"value": "<your_repo>/harness_terraform:latest"
}
]
EOF
Reset the Images back to the defaults with the reset-config
endpoint:
curl \
-X POST \
-H 'x-api-key: <pat>' \
'https://app.harness.io/gateway/iacm-manager/execution-config/reset-config?accountIdentifier=<account>&infra=k8' \
--header 'Content-Type: application/json' \
--data-binary @- << EOF
[
{
"field": "addonTag"
},
{
"field": "liteEngineTag"
},
{
"field": "gitCloneTag"
},
{
"field": "IACMTerraformTag"
},
{
"field": "IACMOpentofuTag"
}
]
EOF
View your custom Images via the get-customer-config
endpoint:
curl \
-H 'x-api-key: <pat>' \
'https://app.harness.io/gateway/iacm-manager/execution-config/get-customer-config?accountIdentifier=<account>&infra=k8'
View the default images via the get-default-config
endpoint:
curl \
-H 'x-api-key: <pat>' \
'https://app.harness.io/gateway/iacm-manager/execution-config/get-default-config?accountIdentifier=<account>&infra=k8'
Conclusion
In conclusion, custom images provide a powerful way to optimize your IaCM pipelines. By staying proactive with updates and leveraging the flexibility of Harness, you can ensure robust, secure, and efficient infrastructure management. Ready to take the next step? Implement these strategies and watch your deployment processes transform!