Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
tmokmss committed Apr 26, 2024
1 parent c7a3f73 commit e602812
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 15 deletions.
42 changes: 37 additions & 5 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
AWS CDK L3 construct that allows you to run a build job for specific purposes. Currently this library supports the following use cases:

* Build web frontend static files
* Build a container image
* Build Seekable OCI (SOCI) indices for container images

## Usage
Expand Down Expand Up @@ -118,6 +119,35 @@ To mitigate this issue, you can separate the stack for frontend construct from o
],
```

### Build a container image
You can build a container image at deploy time by the following code:

```ts
import { ContainerImageBuild } from 'deploy-time-build;

const image = new ContainerImageBuild(this, 'Build', {
directory: 'example-image',
buildArgs: { DUMMY_FILE_SIZE_MB: '15' },
tag: 'my-image-tag',
});
new DockerImageFunction(this, 'Function', {
code: image.toLambdaDockerImageCode(),
});
const armImage = new ContainerImageBuild(this, 'BuildArm', {
directory: 'example-image',
platform: Platform.LINUX_ARM64,
repository: image.repository,
zstdCompression: true,
});
new FargateTaskDefinition(this, 'TaskDefinition', {
runtimePlatform: { cpuArchitecture: CpuArchitecture.ARM64 }
}).addContainer('main', {
image: armImage.toEcsDockerImageCode(),
});
```

The third argument (props) are the super set of DockerImageAsset's properties. You can additionally set `tag` and `repository`.

### Build SOCI index for a container image
[Seekable OCI (SOCI)](https://aws.amazon.com/about-aws/whats-new/2022/09/introducing-seekable-oci-lazy-loading-container-images/) is a way to help start tasks faster for Amazon ECS tasks on Fargate 1.4.0. You can build and push a SOCI index using the `SociIndexBuild` construct.

Expand Down
17 changes: 7 additions & 10 deletions src/container-image-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import { Construct } from 'constructs';
import { SingletonProject } from './singleton-project';
import { ContainerImageBuildResourceProps } from './types';

/**
* Note:
* the default platform is LINUX_AMD64
*/
export interface ContainerImageBuildProps extends DockerImageAssetProps {
/**
* The tag when to push the image
Expand All @@ -37,13 +33,8 @@ export interface ContainerImageBuildProps extends DockerImageAssetProps {
readonly zstdCompression?: boolean;
}

// reference:
// https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecr_assets.DockerImageAsset.html
// https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.AssetImageCodeProps.html
// https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.AssetImageProps.html

/**
* Build Node.js app and optionally publish the artifact to an S3 bucket.
* Build a container image and push it to an ECR repository on deploy-time.
*/
export class ContainerImageBuild extends Construct implements IGrantable {
public readonly grantPrincipal: IPrincipal;
Expand Down Expand Up @@ -189,13 +180,19 @@ curl -v -i -X PUT -H 'Content-Type:' -d "@payload.json" "$responseURL"
this.imageTag = custom.getAttString('ImageTag');
}

/**
* Get the instance of {@link DockerImageCode} for a Lambda function image.
*/
public toLambdaDockerImageCode() {
if (this.props.zstdCompression) {
throw new Error('You cannot enable zstdCompression for a Lambda image.');
}
return DockerImageCode.fromEcr(this.repository, { tagOrDigest: this.imageTag });
}

/**
* Get the instance of {@link ContainerImage} for an ECS task definition.
*/
public toEcsDockerImageCode() {
return ContainerImage.fromEcrRepository(this.repository, this.imageTag);
}
Expand Down

0 comments on commit e602812

Please sign in to comment.