UNPKG

token-injectable-docker-builder

Version:

The TokenInjectableDockerBuilder is a flexible AWS CDK construct that enables the usage of AWS CDK tokens in the building, pushing, and deployment of Docker images to Amazon Elastic Container Registry (ECR). It leverages AWS CodeBuild and Lambda custom re

64 lines (63 loc) 2.76 kB
import { Duration } from 'aws-cdk-lib'; import { Project } from 'aws-cdk-lib/aws-codebuild'; import { Repository } from 'aws-cdk-lib/aws-ecr'; import { Key } from 'aws-cdk-lib/aws-kms'; import { Construct } from 'constructs'; /** * Options for creating a `TokenInjectableDockerBuilderProvider`. */ export interface TokenInjectableDockerBuilderProviderProps { /** * How often the provider polls for build completion. * * @default Duration.seconds(30) */ readonly queryInterval?: Duration; } /** * Shared provider for `TokenInjectableDockerBuilder` instances. * * Creates the onEvent and isComplete Lambda functions once per stack. * Each builder instance registers its CodeBuild project ARN so the * shared Lambdas have permission to start builds and read logs. */ export declare class TokenInjectableDockerBuilderProvider extends Construct { /** * Get or create the singleton provider for this stack. * All `TokenInjectableDockerBuilder` instances in the same stack * share a single pair of Lambda functions. */ static getOrCreate(scope: Construct, props?: TokenInjectableDockerBuilderProviderProps): TokenInjectableDockerBuilderProvider; /** The service token used by CustomResource instances. */ readonly serviceToken: string; private readonly onEventHandlerFunction; private readonly isCompleteHandlerFunction; private replicationFn?; private replicationCr?; private readonly replicationSpecs; private constructor(); /** * Grant the shared Lambdas permission to start builds for a specific * CodeBuild project and pull/push to its ECR repository. */ registerProject(project: Project, ecrRepo: Repository, encryptionKey?: Key): void; /** * Register a builder's replica regions with the singleton's replication-config * custom resource. Multiple builders contribute specs; the CR merges them into * a single registry-wide configuration on every deploy. * * Also grants the `isComplete` Lambda permission to BatchGetImage on each * replica region's repo so it can poll for replication availability. */ registerReplication(repoName: string, replicaRegions: string[]): void; private ensureReplicationCr; /** * Enforce ECR registry replication caps at synth time so users get a clear * error before deploy. Caps are per-registry (per AWS account), not * per-stack — but this construct can only see specs registered through * its own singletons. Cross-stack/cross-app rules outside this construct * are invisible here; the replication CR will still surface those at * deploy time via the ECR API's own error. */ private assertReplicationCapsWithinLimits; }