Gathering detailed insights and metrics for token-injectable-docker-builder
Gathering detailed insights and metrics for token-injectable-docker-builder
npm install token-injectable-docker-builder
Typescript
Module System
Node Version
NPM Version
42
Supply Chain
79.3
Quality
95.1
Maintenance
100
Vulnerability
98.2
License
TypeScript (80.26%)
JavaScript (18.55%)
Dockerfile (1.19%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
4,326
Last Day
10
Last Week
320
Last Month
992
Last Year
4,326
MIT License
3 Stars
84 Commits
1 Forks
1 Watchers
3 Branches
1 Contributors
Updated on Mar 10, 2025
Minified
Minified + Gzipped
Latest Version
1.5.8
Package Id
token-injectable-docker-builder@1.5.8
Unpacked Size
228.45 kB
Size
37.80 kB
File Count
9
NPM Version
10.9.2
Node Version
22.14.0
Published on
Mar 10, 2025
Cumulative downloads
Total Downloads
Last Day
-50%
10
Compared to previous day
Last Week
122.2%
320
Compared to previous week
Last Month
105%
992
Compared to previous month
Last Year
0%
4,326
Compared to previous year
2
22
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 resources.
AWS CDK already provides mechanisms for creating deployable assets using Docker, such as DockerImageAsset and DockerImageCode, but these constructs are limited because they cannot accept CDK tokens as build-args. The TokenInjectableDockerBuilder
allows injecting CDK tokens as build-time arguments into Docker-based assets, enabling more dynamic dependency relationships.
For example, a Next.js frontend Docker image may require an API Gateway URL as an argument to create a reference from the UI to the associated API in a given deployment. With this construct, you can deploy the API Gateway first, then pass its URL as a build-time argument to the Next.js Docker image. As a result, your Next.js frontend can dynamically fetch data from the API Gateway without hardcoding the URL or needing multiple separate stacks.
install
and pre_build
phases of the CodeBuild build process.completenessQueryInterval
property (defaults to 30 seconds).Install the construct using NPM:
1npm install token-injectable-docker-builder
Install the construct using pip:
1pip install token-injectable-docker-builder
TokenInjectableDockerBuilder
scope
: The construct's parent scope.id
: The construct ID.props
: Configuration properties.TokenInjectableDockerBuilderProps
Property | Type | Required | Description |
---|---|---|---|
path | string | Yes | The file path to the Dockerfile or source code directory. |
buildArgs | { [key: string]: string } | No | Build arguments to pass to the Docker build process. These are transformed into --build-arg flags. To use in Dockerfile, leverage the ARG keyword. For more details, please see the official Docker docs. |
dockerLoginSecretArn | string | No | ARN of an AWS Secrets Manager secret for Docker credentials. Skips login if not provided. |
vpc | IVpc | No | The VPC in which the CodeBuild project will be deployed. If provided, the CodeBuild project will be launched within the specified VPC. |
securityGroups | ISecurityGroup[] | No | The security groups to attach to the CodeBuild project. These should define the network access rules for the CodeBuild project. |
subnetSelection | SubnetSelection | No | The subnet selection to specify which subnets to use within the VPC. Allows the user to select private, public, or isolated subnets. |
installCommands | string[] | No | Custom commands to run during the install phase of the CodeBuild build process. Will be executed before the Docker image is built. Useful for installing necessary dependencies for running pre-build scripts. |
preBuildCommands | string[] | No | Custom commands to run during the pre_build phase of the CodeBuild build process. Will be executed before the Docker image is built. Useful for running pre-build scripts, such as fetching configs. |
kmsEncryption | boolean | No | Whether to enable KMS encryption for the ECR repository. If true , a KMS key will be created for encrypting ECR images; otherwise, AES-256 encryption is used. Defaults to false . |
completenessQueryInterval | Duration | No | The query interval for checking if the CodeBuild project has completed. This determines how frequently the custom resource polls for build completion. Defaults to Duration.seconds(30) . |
This example demonstrates the basic usage of the TokenInjectableDockerBuilder
, where a Next.js frontend Docker image requires an API Gateway URL as a build argument to create a reference from the UI to the associated API in a given deployment.
1import * as cdk from 'aws-cdk-lib'; 2import { TokenInjectableDockerBuilder } from 'token-injectable-docker-builder'; 3import * as ecs from 'aws-cdk-lib/aws-ecs'; 4import * as ec2 from 'aws-cdk-lib/aws-ec2'; 5import * as apigateway from 'aws-cdk-lib/aws-apigateway'; 6 7export class SimpleStack extends cdk.Stack { 8 constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { 9 super(scope, id, props); 10 11 // Create your API Gateway 12 const api = new apigateway.RestApi(this, 'MyApiGateway', { 13 restApiName: 'MyService', 14 }); 15 16 // Create the Docker builder 17 const dockerBuilder = new TokenInjectableDockerBuilder(this, 'SimpleDockerBuilder', { 18 path: './nextjs-app', // Path to your Next.js app Docker context 19 buildArgs: { 20 API_URL: api.url, // Pass the API Gateway URL as a build argument 21 }, 22 // Optionally override the default completeness query interval: 23 // completenessQueryInterval: cdk.Duration.seconds(45), 24 }); 25 26 // Use in ECS 27 const cluster = new ecs.Cluster(this, 'EcsCluster', { 28 vpc: new ec2.Vpc(this, 'Vpc'), 29 }); 30 31 const service = new ecs.FargateService(this, 'FargateService', { 32 cluster, 33 taskDefinition: new ecs.FargateTaskDefinition(this, 'TaskDef', { 34 cpu: 512, 35 memoryLimitMiB: 1024, 36 }).addContainer('Container', { 37 image: dockerBuilder.containerImage, 38 logging: ecs.LogDriver.awsLogs({ streamPrefix: 'MyApp' }), 39 }), 40 }); 41 42 service.node.addDependency(dockerBuilder); 43 } 44}
1from aws_cdk import ( 2 aws_ecs as ecs, 3 aws_ec2 as ec2, 4 aws_apigateway as apigateway, 5 Duration, 6 core as cdk, 7) 8from token_injectable_docker_builder import TokenInjectableDockerBuilder 9 10class SimpleStack(cdk.Stack): 11 12 def __init__(self, scope: cdk.App, id: str, **kwargs): 13 super().__init__(scope, id, **kwargs) 14 15 # Create your API Gateway 16 api = apigateway.RestApi(self, "MyApiGateway", 17 rest_api_name="MyService", 18 ) 19 20 # Create the Docker builder 21 docker_builder = TokenInjectableDockerBuilder(self, "SimpleDockerBuilder", 22 path="./nextjs-app", # Path to your Next.js app Docker context 23 build_args={ 24 "API_URL": api.url, # Pass the API Gateway URL as a build argument 25 }, 26 # Optionally override the default completeness query interval: 27 # completeness_query_interval=Duration.seconds(45) 28 ) 29 30 # Use in ECS 31 vpc = ec2.Vpc(self, "Vpc") 32 cluster = ecs.Cluster(self, "EcsCluster", vpc=vpc) 33 34 task_definition = ecs.FargateTaskDefinition(self, "TaskDef", 35 cpu=512, 36 memory_limit_mib=1024, 37 ) 38 39 task_definition.node.add_dependency(docker_builder) 40 41 task_definition.add_container("Container", 42 image=docker_builder.container_image, 43 logging=ecs.LogDriver.aws_logs(stream_prefix="MyApp"), 44 ) 45 46 ecs.FargateService(self, "FargateService", 47 cluster=cluster, 48 task_definition=task_definition, 49 )
Building on the previous example, this advanced usage demonstrates how to include additional configurations, such as fetching private API endpoints and configuration files during the build process.
1import * as cdk from 'aws-cdk-lib'; 2import { TokenInjectableDockerBuilder } from 'token-injectable-docker-builder'; 3import * as ecs from 'aws-cdk-lib/aws-ecs'; 4import * as ec2 from 'aws-cdk-lib/aws-ec2'; 5import * as apigateway from 'aws-cdk-lib/aws-apigateway'; 6 7export class AdvancedStack extends cdk.Stack { 8 constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { 9 super(scope, id, props); 10 11 // Create your API Gateway 12 const api = new apigateway.RestApi(this, 'MyApiGateway', { 13 restApiName: 'MyService', 14 }); 15 16 // VPC and Security Group for CodeBuild 17 const vpc = new ec2.Vpc(this, 'MyVpc'); 18 const securityGroup = new ec2.SecurityGroup(this, 'MySecurityGroup', { 19 vpc, 20 }); 21 22 // Create the Docker builder with additional pre-build commands 23 const dockerBuilder = new TokenInjectableDockerBuilder(this, 'AdvancedDockerBuilder', { 24 path: './nextjs-app', 25 buildArgs: { 26 API_URL: api.url, 27 }, 28 vpc, 29 securityGroups: [securityGroup], 30 subnetSelection: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }, 31 installCommands: [ 32 'echo "Updating package lists..."', 33 'apt-get update -y', 34 'echo "Installing necessary packages..."', 35 'apt-get install -y curl', 36 ], 37 preBuildCommands: [ 38 'echo "Fetching private API configuration..."', 39 // Replace with your actual command to fetch configs 40 'curl -o config.json https://internal-api.example.com/config', 41 ], 42 // Optionally override the default completeness query interval: 43 // completenessQueryInterval: cdk.Duration.seconds(45), 44 }); 45 46 // Use in ECS 47 const cluster = new ecs.Cluster(this, 'EcsCluster', { vpc }); 48 49 const service = new ecs.FargateService(this, 'FargateService', { 50 cluster, 51 taskDefinition: new ecs.FargateTaskDefinition(this, 'TaskDef', { 52 cpu: 512, 53 memoryLimitMiB: 1024, 54 }).addContainer('Container', { 55 image: dockerBuilder.containerImage, 56 logging: ecs.LogDriver.awsLogs({ streamPrefix: 'MyApp' }), 57 }), 58 }); 59 60 service.node.addDependency(dockerBuilder); 61 } 62}
1from aws_cdk import ( 2 aws_ecs as ecs, 3 aws_ec2 as ec2, 4 aws_apigateway as apigateway, 5 Duration, 6 core as cdk, 7) 8from token_injectable_docker_builder import TokenInjectableDockerBuilder 9 10class AdvancedStack(cdk.Stack): 11 12 def __init__(self, scope: cdk.App, id: str, **kwargs): 13 super().__init__(scope, id, **kwargs) 14 15 # Create your API Gateway 16 api = apigateway.RestApi(self, "MyApiGateway", 17 rest_api_name="MyService", 18 ) 19 20 # VPC and Security Group for CodeBuild 21 vpc = ec2.Vpc(self, "MyVpc") 22 security_group = ec2.SecurityGroup(self, "MySecurityGroup", vpc=vpc) 23 24 # Create the Docker builder with additional pre-build commands 25 docker_builder = TokenInjectableDockerBuilder(self, "AdvancedDockerBuilder", 26 path="./nextjs-app", 27 build_args={ 28 "API_URL": api.url, 29 }, 30 vpc=vpc, 31 security_groups=[security_group], 32 subnet_selection=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS), 33 install_commands=[ 34 'echo "Updating package lists..."', 35 'apt-get update -y', 36 'echo "Installing necessary packages..."', 37 'apt-get install -y curl', 38 ], 39 pre_build_commands=[ 40 'echo "Fetching private API configuration..."', 41 # Replace with your actual command to fetch configs 42 'curl -o config.json https://internal-api.example.com/config', 43 ], 44 # Optionally override the default completeness query interval: 45 # completeness_query_interval=Duration.seconds(45) 46 ) 47 48 # Use in ECS 49 cluster = ecs.Cluster(self, "EcsCluster", vpc=vpc) 50 51 task_definition = ecs.FargateTaskDefinition(self, "TaskDef", 52 cpu=512, 53 memory_limit_mib=1024, 54 ) 55 56 task_definition.node.add_dependency(docker_builder) 57 58 task_definition.add_container("Container", 59 image=docker_builder.container_image, 60 logging=ecs.LogDriver.aws_logs(stream_prefix="MyApp"), 61 ) 62 63 ecs.FargateService(self, "FargateService", 64 cluster=cluster, 65 task_definition=task_definition, 66 )
In this advanced example:
installCommands
and preBuildCommands
properties are used to install necessary packages and fetch configuration files from a private API before building the Docker image.path
property as an S3 asset.buildArgs
to build the Docker image.installCommands
and preBuildCommands
during the build process.onEvent
).isComplete
) which polls at the interval specified by completenessQueryInterval
(defaulting to 30 seconds if not provided)..containerImage
: Returns the Docker image for ECS..dockerImageCode
: Returns the Docker image code for Lambda.The construct automatically grants permissions for:
dockerLoginSecretArn
is provided.buildArgs
as --build-arg
flags. CDK tokens can be used to inject dynamic values resolved at deployment time.installCommands
and preBuildCommands
to run custom shell commands during the build process. This can be useful for installing dependencies or fetching configuration files.completenessQueryInterval
property.onEvent
and isComplete
Lambda function logs in CloudWatch Logs.For issues or feature requests, please open an issue on GitHub.
This project is licensed under the terms of the MIT license.
Feel free to reach out if you have any questions or need further assistance!
No vulnerabilities found.
No security vulnerabilities found.