@codedazur/cdk-next-app 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @codedazur/cdk-next-app
2
2
 
3
+ ## 0.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`17034ee`](https://github.com/codedazur/toolkit/commit/17034ee5fcbc026fc779a12130572d515d2b8298) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - Dependency versions were made explicit.
8
+
9
+ - Updated dependencies [[`d1f3d51`](https://github.com/codedazur/toolkit/commit/d1f3d512d31d659ffdc115147d9631057fe8d073), [`17034ee`](https://github.com/codedazur/toolkit/commit/17034ee5fcbc026fc779a12130572d515d2b8298), [`737fe0d`](https://github.com/codedazur/toolkit/commit/737fe0ddd4d353db1e005d2dab886a4a60bc02d8)]:
10
+ - @codedazur/cdk-docker-cluster@0.5.0
11
+
12
+ ## 0.2.2
13
+
14
+ ### Patch Changes
15
+
16
+ - [`17d19aea004254b214364caef8fa02f9a6019f8f`](https://github.com/codedazur/toolkit/commit/17d19aea004254b214364caef8fa02f9a6019f8f) Thanks [@thijsdaniels](https://github.com/thijsdaniels)! - The version of the DockerCluster dependency is now explicit.
17
+
18
+ - Updated dependencies [[`17d19aea004254b214364caef8fa02f9a6019f8f`](https://github.com/codedazur/toolkit/commit/17d19aea004254b214364caef8fa02f9a6019f8f)]:
19
+ - @codedazur/cdk-docker-cluster@0.4.0
20
+
3
21
  ## 0.2.1
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -2,15 +2,37 @@
2
2
 
3
3
  The NextApp CDK construct deploys a standalone Next.js build to a load balanced Fargate service on AWS.
4
4
 
5
+ It automatically mounts the `~/.npmrc` file as a build secret for installation of private NPM packages.
6
+
7
+ ## Prerequisites
8
+
9
+ ### Next.js Configuration
10
+
11
+ Your `next.config.js` file needs to be configured for standalone output.
12
+
13
+ ```js
14
+ // next.config.js
15
+ // ...
16
+ const nextConfig = {
17
+ // ...
18
+ output: "standalone",
19
+ };
20
+ // ...
21
+ ```
22
+
23
+ ### Docker
24
+
25
+ In order to use this construct, your Next.js application needs to be configured for Docker deployments. See the [official documentation](https://nextjs.org/docs/pages/building-your-application/deploying#docker-image) for more information.
26
+
5
27
  ## Example
6
28
 
7
29
  ### Standard Repository
8
30
 
9
- For a non-mnonorepo build, simply provide the path to the directory that contains your Dockerfile.
31
+ For a non-monorepo build, simply provide the path to the directory that contains your Dockerfile.
10
32
 
11
33
  ```ts
12
34
  new NextApp(this, "NextApp", {
13
- path: "../next",
35
+ source: "../next",
14
36
  });
15
37
  ```
16
38
 
@@ -20,24 +42,54 @@ For monorepo builds, set the build context to the root of your monorepo, and pro
20
42
 
21
43
  ```ts
22
44
  new NextApp(this, "NextApp", {
23
- path: "../../",
24
- file: "apps/next/Dockerfile",
45
+ source: {
46
+ directory: "../../",
47
+ file: "apps/next/Dockerfile",
48
+ },
49
+ });
50
+ ```
51
+
52
+ ### Arguments and Secrets
53
+
54
+ 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.
55
+
56
+ These arguments and secrets need to be handled appropriately by your Dockerfile in order for them to have any effect.
57
+
58
+ ```ts
59
+ import { DockerBuildSecret } from "aws-cdk-lib";
60
+
61
+ new NextApp(this, "NextApp", {
62
+ source: {
63
+ // ...
64
+ arguments: {
65
+ MY_BUILD_ARGUMENT: process.env.MY_BUILD_ARGUMENT,
66
+ },
67
+ secrets: {
68
+ myBuildSecret: new DockerBuildSecret.fromEnvironment("MY_BUILD_SECRET"),
69
+ },
70
+ },
25
71
  });
26
72
  ```
27
73
 
28
74
  ### Scaling
29
75
 
30
- 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.
76
+ 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.
31
77
 
32
78
  ```ts
33
79
  new NextApp(this, "NextApp", {
34
- ...
80
+ // ...
35
81
  cpu: 1024,
36
82
  memory: 4096,
37
- tasks: { min: 1, max: 10 },
83
+ tasks: 3,
38
84
  });
39
85
  ```
40
86
 
41
- ## Docker
42
-
43
- In order to use this construct, your Next.js application needs to be configure for Docker deployments. See the [official documentation](https://nextjs.org/docs/pages/building-your-application/deploying#docker-image) for more information.
87
+ ```ts
88
+ new NextApp(this, "NextApp", {
89
+ // ...
90
+ tasks: {
91
+ minimum: 1,
92
+ maximum: 5,
93
+ },
94
+ });
95
+ ```
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DockerClusterProps, DockerCluster } from '@codedazur/cdk-docker-cluster';
2
+ import { ContainerImage } from 'aws-cdk-lib/aws-ecs';
2
3
  import { Construct } from 'constructs';
3
4
 
4
5
  interface NextAppProps extends DockerClusterProps {
@@ -8,7 +9,16 @@ interface NextAppProps extends DockerClusterProps {
8
9
  * for private NPM packages using a build-time secret.
9
10
  */
10
11
  declare class NextApp extends DockerCluster {
11
- constructor(scope: Construct, id: string, { port, secrets, ...props }: NextAppProps);
12
+ constructor(scope: Construct, id: string, { port, source, ...props }: NextAppProps);
13
+ protected static withNpmSecret(source: NextAppProps["source"]): ContainerImage | {
14
+ secrets: {
15
+ npmrc: string;
16
+ };
17
+ directory: string;
18
+ exclude?: string[];
19
+ file?: string;
20
+ arguments?: Record<string, string>;
21
+ };
12
22
  }
13
23
 
14
- export { NextApp, NextAppProps };
24
+ export { NextApp, type NextAppProps };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DockerClusterProps, DockerCluster } from '@codedazur/cdk-docker-cluster';
2
+ import { ContainerImage } from 'aws-cdk-lib/aws-ecs';
2
3
  import { Construct } from 'constructs';
3
4
 
4
5
  interface NextAppProps extends DockerClusterProps {
@@ -8,7 +9,16 @@ interface NextAppProps extends DockerClusterProps {
8
9
  * for private NPM packages using a build-time secret.
9
10
  */
10
11
  declare class NextApp extends DockerCluster {
11
- constructor(scope: Construct, id: string, { port, secrets, ...props }: NextAppProps);
12
+ constructor(scope: Construct, id: string, { port, source, ...props }: NextAppProps);
13
+ protected static withNpmSecret(source: NextAppProps["source"]): ContainerImage | {
14
+ secrets: {
15
+ npmrc: string;
16
+ };
17
+ directory: string;
18
+ exclude?: string[];
19
+ file?: string;
20
+ arguments?: Record<string, string>;
21
+ };
12
22
  }
13
23
 
14
- export { NextApp, NextAppProps };
24
+ export { NextApp, type NextAppProps };
package/dist/index.js CHANGED
@@ -39,17 +39,35 @@ var import_os = __toESM(require("os"));
39
39
  var import_path = __toESM(require("path"));
40
40
  var import_cdk_docker_cluster = require("@codedazur/cdk-docker-cluster");
41
41
  var import_aws_cdk_lib = require("aws-cdk-lib");
42
- var NextApp = class extends import_cdk_docker_cluster.DockerCluster {
43
- constructor(scope, id, { port = 3e3, secrets, ...props }) {
42
+ var import_aws_ecs = require("aws-cdk-lib/aws-ecs");
43
+ var NextApp = class _NextApp extends import_cdk_docker_cluster.DockerCluster {
44
+ constructor(scope, id, { port = 3e3, source, ...props }) {
44
45
  super(scope, id, {
45
46
  port,
46
- secrets: {
47
- npmrc: import_aws_cdk_lib.DockerBuildSecret.fromSrc(import_path.default.join(import_os.default.homedir(), "/.npmrc")),
48
- ...secrets
49
- },
47
+ source: _NextApp.withNpmSecret(source),
50
48
  ...props
51
49
  });
52
50
  }
51
+ static withNpmSecret(source) {
52
+ if (source instanceof import_aws_ecs.ContainerImage) {
53
+ return source;
54
+ }
55
+ if (typeof source === "string") {
56
+ return {
57
+ directory: source,
58
+ secrets: {
59
+ npmrc: import_aws_cdk_lib.DockerBuildSecret.fromSrc(import_path.default.join(import_os.default.homedir(), "/.npmrc"))
60
+ }
61
+ };
62
+ }
63
+ return {
64
+ ...source,
65
+ secrets: {
66
+ npmrc: import_aws_cdk_lib.DockerBuildSecret.fromSrc(import_path.default.join(import_os.default.homedir(), "/.npmrc")),
67
+ ...source.secrets
68
+ }
69
+ };
70
+ }
53
71
  };
54
72
  // Annotate the CommonJS export names for ESM import in node:
55
73
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -5,17 +5,35 @@ import {
5
5
  DockerCluster
6
6
  } from "@codedazur/cdk-docker-cluster";
7
7
  import { DockerBuildSecret } from "aws-cdk-lib";
8
- var NextApp = class extends DockerCluster {
9
- constructor(scope, id, { port = 3e3, secrets, ...props }) {
8
+ import { ContainerImage } from "aws-cdk-lib/aws-ecs";
9
+ var NextApp = class _NextApp extends DockerCluster {
10
+ constructor(scope, id, { port = 3e3, source, ...props }) {
10
11
  super(scope, id, {
11
12
  port,
12
- secrets: {
13
- npmrc: DockerBuildSecret.fromSrc(path.join(os.homedir(), "/.npmrc")),
14
- ...secrets
15
- },
13
+ source: _NextApp.withNpmSecret(source),
16
14
  ...props
17
15
  });
18
16
  }
17
+ static withNpmSecret(source) {
18
+ if (source instanceof ContainerImage) {
19
+ return source;
20
+ }
21
+ if (typeof source === "string") {
22
+ return {
23
+ directory: source,
24
+ secrets: {
25
+ npmrc: DockerBuildSecret.fromSrc(path.join(os.homedir(), "/.npmrc"))
26
+ }
27
+ };
28
+ }
29
+ return {
30
+ ...source,
31
+ secrets: {
32
+ npmrc: DockerBuildSecret.fromSrc(path.join(os.homedir(), "/.npmrc")),
33
+ ...source.secrets
34
+ }
35
+ };
36
+ }
19
37
  };
20
38
  export {
21
39
  NextApp
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codedazur/cdk-next-app",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "main": ".dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -22,21 +22,17 @@
22
22
  "types": "tsc --noEmit",
23
23
  "test": "vitest run --passWithNoTests"
24
24
  },
25
- "dependencies": {
26
- "@codedazur/cdk-docker-cluster": "*"
27
- },
28
25
  "peerDependencies": {
29
26
  "aws-cdk-lib": ">=2",
30
27
  "constructs": ">=10"
31
28
  },
29
+ "dependencies": {
30
+ "@codedazur/cdk-docker-cluster": "^0.5.0"
31
+ },
32
32
  "devDependencies": {
33
- "@codedazur/eslint-config": "*",
34
- "@codedazur/tsconfig": "*",
35
- "@types/node": "^20.14.2",
36
- "aws-cdk-lib": "^2.145.0",
33
+ "@types/node": "^20.14.9",
34
+ "aws-cdk-lib": "^2.147.2",
37
35
  "constructs": "^10.3.0",
38
- "esbuild": "^0.20.2",
39
- "eslint": "^8.30.0",
40
- "typescript": "^5.4.5"
36
+ "esbuild": "^0.21.5"
41
37
  }
42
38
  }
package/tsconfig.json CHANGED
@@ -1,5 +1,3 @@
1
1
  {
2
- "extends": "@codedazur/tsconfig/cdk.json",
3
- "include": ["."],
4
- "exclude": ["dist", "build", "node_modules"]
2
+ "extends": "@codedazur/tsconfig/cdk.json"
5
3
  }