Skip to content

Commit

Permalink
fix(cdk-docker-cluster): rename environment to arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsdaniels committed Jun 26, 2024
1 parent 08bb0d7 commit 737fe0d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-llamas-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codedazur/cdk-docker-cluster": patch
---

The build environment prop was renamed to arguments.
12 changes: 9 additions & 3 deletions packages/cdk-docker-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
```
8 changes: 2 additions & 6 deletions packages/cdk-docker-cluster/src/constructs/DockerCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Construct } from "constructs";
export interface DockerClusterProps {
path: string;
file?: string;
arguments?: Record<string, string>;
secrets?: Record<string, string>;
port?: number;
tasks?:
Expand All @@ -22,10 +23,6 @@ export interface DockerClusterProps {
};
cpu?: ApplicationLoadBalancedFargateServiceProps["cpu"];
memory?: ApplicationLoadBalancedFargateServiceProps["memoryLimitMiB"];
environment?: {
buildtime?: Record<string, string>;
runtime?: Record<string, string>;
};
}

/**
Expand All @@ -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,
});
Expand All @@ -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,
Expand Down
38 changes: 35 additions & 3 deletions packages/cdk-next-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Your `next.config.js` file needs to be configured for standalone output.
const nextConfig = {
// ...
output: "standalone",
}
};
// ...
```

Expand Down Expand Up @@ -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,
},
});
```

0 comments on commit 737fe0d

Please sign in to comment.