For the complete documentation index, see llms.txt. This page is also available as Markdown.

Build AWS CDK runtime images

A reusable Harness pipeline to help you build customized AWS CDK plugin images.

This topic provides a Harness Continuous Delivery (CD) pipeline that you can use to build custom Docker images for the AWS Cloud Development Kit (AWS CDK) plugin. The pipeline gives you the flexibility to use newer AWS CDK versions or customize runtime environments to meet your application requirements.

The pipeline builds a separate AWS CDK plugin Docker image for each supported runtime (Python, Java, .NET, and Go) and pushes the images to your Docker repository. You can use this pipeline to build images with an AWS CDK version newer than the version available in the prebuilt Harness images, or to include additional dependencies required by your CDK application.

Go to the Pipeline YAML section to copy the full pipeline.


What will you learn in this topic?


Before you begin

  • Kubernetes cluster and connector: Set up a Kubernetes cluster using KubernetesDirect infrastructure that allows privileged containers, and a Harness Kubernetes Cluster connector that references it. For managed Kubernetes such as GKE, do not use GKE Autopilot clusters; use a standard node pool that allows privileged mode. Go to Kubernetes Cluster connector settings reference to configure the connector.

  • Docker registry and Git connectors: Configure connectors for Docker registries (account.dockerhub or your own) and any required Git repositories.

  • Secrets and variables: Store Docker registry credentials and secret variables in Harness secrets management.

  • Pipeline variables: Be ready to set variables such as VERSION, AWS_CDK_VERSION, ARCH, and TARGET_REPO at runtime or with defaults.

  • Base scratch image: The pipeline pulls the base scratch image harness/aws-cdk-plugin:<VERSION>-base-<ARCH>. Confirm this tag exists for your chosen VERSION on Docker Hub before you run the build.

Go to AWS CDK on npm to find the latest CDK version.


Supported runtimes and base images

The pipeline builds images for the following runtime environments:

  • Python: Python3, pip, bash, curl, git, Node.js 20, AWS CDK CLI

  • Java: OpenJDK 11, Maven 3.9.11, bash, curl, git, Node.js 20, AWS CDK CLI

  • DotNet: .NET runtime and dependencies, bash, icu-libs, git, Node.js 20, AWS CDK CLI

  • Go: Bash, curl, git, Node.js 20, AWS CDK CLI

All runtime images derive from the supported Harness base plugin images and runtime-specific Node.js OS base images.

The pipeline tags each image it builds in the format <TARGET_REPO>:<RUNTIME>-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>, for example harness/aws-cdk-plugin:python-1.4.0-2.1029.1-linux-amd64.


Pipeline steps and execution flow

The pipeline runs the following steps to build and push each runtime image:

  1. Authentication setup: Creates the Docker config for registry authentication.

  2. Dockerfile generation: Generates Dockerfiles per runtime, each of which uses a multi-stage build (base plus runtime image), copies the plugin and scripts from the base image, installs the language runtime and AWS CDK, and configures Node.js, metadata, and the entrypoint.

  3. Image build and push: Uses Docker to build and push the tagged runtime images.


Privileged mode requirement

Certain pipeline steps, such as Docker-in-Docker for image build and push, require privileged execution. Privileged steps are not standard pipeline steps; they run with escalated permissions and must be explicitly enabled with privileged: true in the pipeline YAML.

To enable privileged mode, set privileged: true under spec in your step group or individual step. Your Kubernetes cluster must be configured to allow privileged containers.

For individual steps:

Without this setting, Docker builds and image pushes can fail due to insufficient permissions inside the container.


Run the image build pipeline

Perform the following steps to run the image build pipeline:

  1. Copy the pipeline YAML into your Harness project.

  2. Add an empty do-nothing service to the pipeline.

  3. Configure a Kubernetes environment in Harness.

  4. In the Execution section, enable container-based execution in the step group. Add the Kubernetes Cluster connector inside the container step group, then save the pipeline.

  5. Select Run Pipeline.

  6. Fill in all required variables. Go to Pipeline variables and runtime inputs to review each variable.


Pipeline variables and runtime inputs

Set the following variables in the pipeline YAML and at runtime.

Pipeline variables

The following variables are set in the pipeline YAML:

Variable
Description
Example

TARGET_REPO

Docker repository

harness/aws-cdk-plugin

DOCKER_USERNAME

Docker registry username

your-dockerhub-username

DOCKER_PASSWORD

Docker registry password or token

From secrets

Runtime inputs

The following variables are supplied at runtime:

Variable
Description
Example

VERSION

Harness base image version

1.4.0

AWS_CDK_VERSION

AWS CDK CLI version

2.1029.1

ARCH

Image build architecture

amd64 or arm64

Run Pipeline panel showing the VERSION, AWS_CDK_VERSION, and ARCH pipeline variables with example values

Pipeline YAML

The following YAML defines the AWS CDK image build pipeline. Copy and paste it into your Harness project.

The stage renders in the UI as shown below:

Pipeline Studio showing the cdkbuildandpush pipeline with a single stage and a build step group containing the dinD and Build and push steps
Pipeline YAML

After you copy the pipeline YAML into your Harness project, change the following parameters: projectIdentifier, orgIdentifier, environmentRef, infrastructureDefinitions, the Docker connectorRef, and the Kubernetes connectorRef.


Output images

After a successful build, you have four tagged images in your target Docker repository. Each tag follows the format the pipeline builds, <TARGET_REPO>:<RUNTIME>-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>:

  • Python: <TARGET_REPO>:python-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>

  • Java: <TARGET_REPO>:java-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>

  • DotNet: <TARGET_REPO>:dotnet-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>

  • Go: <TARGET_REPO>:go-<VERSION>-<AWS_CDK_VERSION>-linux-<ARCH>

Each image includes the required runtime, the AWS CDK CLI, and the Harness plugin, ready for production use.


Last updated

Was this helpful?