From 737fe0ddd4d353db1e005d2dab886a4a60bc02d8 Mon Sep 17 00:00:00 2001 From: Thijs Daniels Date: Wed, 26 Jun 2024 16:58:19 +0200 Subject: [PATCH] fix(cdk-docker-cluster): rename environment to arguments --- .changeset/tender-llamas-yawn.md | 5 +++ packages/cdk-docker-cluster/README.md | 12 ++++-- .../src/constructs/DockerCluster.ts | 8 +--- packages/cdk-next-app/README.md | 38 +++++++++++++++++-- 4 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 .changeset/tender-llamas-yawn.md diff --git a/.changeset/tender-llamas-yawn.md b/.changeset/tender-llamas-yawn.md new file mode 100644 index 00000000..2acd6e83 --- /dev/null +++ b/.changeset/tender-llamas-yawn.md @@ -0,0 +1,5 @@ +--- +"@codedazur/cdk-docker-cluster": patch +--- + +The build environment prop was renamed to arguments. diff --git a/packages/cdk-docker-cluster/README.md b/packages/cdk-docker-cluster/README.md index 3dd6d78a..c855dd00 100644 --- a/packages/cdk-docker-cluster/README.md +++ b/packages/cdk-docker-cluster/README.md @@ -6,12 +6,18 @@ This construct creates a load balanced Fargate service, for which it builds a Do new DockerCluster({ path: "../../", // path to Docker build context file: "apps/myApp/DockerFile", // path to Dockerfile + arguments: { + MY_BUILD_ARGUMENT: "foo", + }, + secrets: { + myBuildSecret: DockerBuildSecret.fromSrc("./foo"), + }, port: 3000, cpu: 1024, // 1vCPU memory: 4096, // 4GB - tasks: { minimum: 1, maximum: 10 }, - secrets: { - foo: DockerBuildSecret.fromSrc("./foo"), + tasks: { + minimum: 1, + maximum: 10, }, }); ``` diff --git a/packages/cdk-docker-cluster/src/constructs/DockerCluster.ts b/packages/cdk-docker-cluster/src/constructs/DockerCluster.ts index c76f66b3..8b041526 100644 --- a/packages/cdk-docker-cluster/src/constructs/DockerCluster.ts +++ b/packages/cdk-docker-cluster/src/constructs/DockerCluster.ts @@ -12,6 +12,7 @@ import { Construct } from "constructs"; export interface DockerClusterProps { path: string; file?: string; + arguments?: Record; secrets?: Record; port?: number; tasks?: @@ -22,10 +23,6 @@ export interface DockerClusterProps { }; cpu?: ApplicationLoadBalancedFargateServiceProps["cpu"]; memory?: ApplicationLoadBalancedFargateServiceProps["memoryLimitMiB"]; - environment?: { - buildtime?: Record; - runtime?: Record; - }; } /** @@ -40,7 +37,7 @@ export class DockerCluster extends Construct { directory: props.path, file: props.file, exclude: ["**/cdk.out"], - buildArgs: props.environment?.buildtime, + buildArgs: props.arguments, buildSecrets: props.secrets, platform: Platform.LINUX_AMD64, }); @@ -57,7 +54,6 @@ export class DockerCluster extends Construct { // image: ContainerImage.fromEcrRepository(image.repository, image.imageTag), image: ContainerImage.fromDockerImageAsset(image), containerPort: props.port, - environment: props.environment?.runtime, }, circuitBreaker: { enable: true, diff --git a/packages/cdk-next-app/README.md b/packages/cdk-next-app/README.md index 5175d647..29d3da34 100644 --- a/packages/cdk-next-app/README.md +++ b/packages/cdk-next-app/README.md @@ -16,7 +16,7 @@ Your `next.config.js` file needs to be configured for standalone output. const nextConfig = { // ... output: "standalone", -} +}; // ... ``` @@ -47,15 +47,47 @@ new NextApp(this, "NextApp", { }); ``` +### Arguments and Secrets + +The NextApp is based on the [DockerCluster](https://github.com/codedazur/toolkit/tree/main/packages/cdk-docker-cluster) construct and supports all of its features related to Docker's build arguments and secrets. + +These arguments and secrets need to be handled appropriately by your Dockerfile in order for them to have any effect. + +```ts +import { DockerBuildSecret } from "aws-cdk-lib"; + +new NextApp(this, "NextApp", { + // ... + arguments: { + MY_BUILD_ARGUMENT: process.env.MY_BUILD_ARGUMENT, + }, + secrets: { + myBuildSecret: new DockerBuildSecret.fromEnvironment("MY_BUILD_SECRET"), + }, +}); +``` + ### Scaling -The NextApp is based on the [DockerCluster](https://github.com/codedazur/toolkit/tree/main/packages/cdk-docker-cluster) construct and supports all of its features for horizontal and vertical scaling. +The NextApp is based on the [DockerCluster](https://github.com/codedazur/toolkit/tree/main/packages/cdk-docker-cluster) construct and supports all of its features for vertical scaling and horizontal (auto-)scaling. + +```ts +new NextApp(this, "NextApp", { + // ... + cpu: 1024, + memory: 4096, + tasks: 3, +}); +``` ```ts new NextApp(this, "NextApp", { // ... cpu: 1024, memory: 4096, - tasks: { min: 1, max: 10 }, + tasks: { + minimum: 1, + maximum: 5, + }, }); ```