@jttc/projen-project-types 1.0.0-beta.1 → 1.0.0-beta.10
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/.cz-config.js +83 -43
- package/.czrc +1 -1
- package/.jsii +4565 -14
- package/AGENTS.md +132 -0
- package/API.md +29886 -306
- package/README.md +197 -29
- package/docs/components/cdk8s.md +724 -0
- package/docs/components/commitzent.md +261 -0
- package/docs/components/k3d.md +456 -0
- package/docs/index.md +79 -13
- package/docs/project-types/cdk-app.md +481 -0
- package/docs/project-types/cdk-library.md +16 -108
- package/docs/project-types/cdk8s-app.md +353 -0
- package/docs/project-types/cdk8s-library.md +442 -0
- package/docs/project-types/nx-monorepo.md +382 -0
- package/lib/cdk/cdk-app-project.d.ts +12 -0
- package/lib/cdk/cdk-app-project.js +28 -0
- package/lib/cdk/cdk-library-project.d.ts +5 -2
- package/lib/cdk/cdk-library-project.js +4 -3
- package/lib/cdk/cdk8s-app-project.d.ts +14 -0
- package/lib/cdk/cdk8s-app-project.js +54 -0
- package/lib/cdk/cdk8s-library-project.d.ts +14 -0
- package/lib/cdk/cdk8s-library-project.js +50 -0
- package/lib/cdk/index.d.ts +5 -0
- package/lib/cdk/index.js +22 -0
- package/lib/cdk/interfaces/cdk-app-options.d.ts +7 -0
- package/lib/cdk/interfaces/cdk-app-options.js +3 -0
- package/lib/cdk/interfaces/cdk-library-options.d.ts +7 -0
- package/lib/cdk/interfaces/cdk-library-options.js +3 -0
- package/lib/cdk/interfaces/cdk8s-app-options.d.ts +18 -0
- package/lib/cdk/interfaces/cdk8s-app-options.js +3 -0
- package/lib/cdk/interfaces/cdk8s-library-options.d.ts +8 -0
- package/lib/cdk/interfaces/cdk8s-library-options.js +3 -0
- package/lib/cdk/interfaces/index.d.ts +5 -0
- package/lib/cdk/interfaces/index.js +22 -0
- package/lib/cdk/interfaces/jsii-options.d.ts +7 -0
- package/lib/cdk/interfaces/jsii-options.js +3 -0
- package/lib/cdk/interfaces/project-global-options.d.ts +15 -0
- package/lib/cdk/interfaces/project-global-options.js +3 -0
- package/lib/cdk/jsii-project.d.ts +12 -0
- package/lib/cdk/jsii-project.js +24 -0
- package/lib/common/common-options.d.ts +17 -1
- package/lib/common/common-options.js +45 -4
- package/lib/components/agents/agents.d.ts +21 -0
- package/lib/components/agents/agents.js +476 -0
- package/lib/components/agents/index.d.ts +1 -0
- package/lib/components/agents/index.js +18 -0
- package/lib/components/cdk8s/cdk8s.d.ts +11 -0
- package/lib/components/cdk8s/cdk8s.js +124 -0
- package/lib/components/cdk8s/index.d.ts +2 -0
- package/lib/components/cdk8s/index.js +19 -0
- package/lib/components/cdk8s/interfaces/Cdk8s.d.ts +34 -0
- package/lib/components/cdk8s/interfaces/Cdk8s.js +12 -0
- package/lib/components/cdk8s/main-library.ts.template +35 -0
- package/lib/components/cdk8s/main.test.ts.template +3 -0
- package/lib/components/cdk8s/main.ts.template +38 -0
- package/lib/components/commitzent/commitzent.d.ts +8 -0
- package/lib/components/commitzent/commitzent.js +100 -0
- package/lib/components/commitzent/index.d.ts +2 -0
- package/lib/components/commitzent/index.js +19 -0
- package/lib/components/commitzent/interfaces/Icommitzent.d.ts +34 -0
- package/lib/components/commitzent/interfaces/Icommitzent.js +3 -0
- package/lib/components/index.d.ts +4 -0
- package/lib/components/index.js +21 -0
- package/lib/components/k3d/index.d.ts +3 -0
- package/lib/components/k3d/index.js +20 -0
- package/lib/components/k3d/k3d.d.ts +33 -0
- package/lib/components/k3d/k3d.js +109 -0
- package/lib/components/k3d/k3dBase.d.ts +4 -0
- package/lib/components/k3d/k3dBase.js +23 -0
- package/lib/components/k3d/types.d.ts +64 -0
- package/lib/components/k3d/types.js +8 -0
- package/lib/index.d.ts +5 -1
- package/lib/index.js +6 -2
- package/lib/monorepo/components/NxConfiguration.d.ts +17 -0
- package/lib/monorepo/components/NxConfiguration.js +105 -0
- package/lib/monorepo/components/index.d.ts +2 -0
- package/lib/monorepo/components/index.js +19 -0
- package/lib/monorepo/components/publish-release.d.ts +5 -0
- package/lib/monorepo/components/publish-release.js +80 -0
- package/lib/monorepo/index.d.ts +3 -0
- package/lib/monorepo/index.js +20 -0
- package/lib/monorepo/interfaces/Nx.d.ts +130 -0
- package/lib/monorepo/interfaces/Nx.js +3 -0
- package/lib/monorepo/interfaces/NxMonorepo.d.ts +3 -0
- package/lib/monorepo/interfaces/NxMonorepo.js +3 -0
- package/lib/monorepo/interfaces/index.d.ts +2 -0
- package/lib/monorepo/interfaces/index.js +19 -0
- package/lib/monorepo/monorepo.d.ts +16 -0
- package/lib/monorepo/monorepo.js +131 -0
- package/lib/terraform/components/index.d.ts +2 -0
- package/lib/terraform/components/index.js +19 -0
- package/lib/terraform/components/terraform-deploy-github-workflow.d.ts +26 -0
- package/lib/terraform/components/terraform-deploy-github-workflow.js +92 -0
- package/lib/terraform/components/terraform-plan-github-workflow.d.ts +31 -0
- package/lib/terraform/components/terraform-plan-github-workflow.js +155 -0
- package/lib/terraform/index.d.ts +5 -0
- package/lib/terraform/index.js +22 -0
- package/lib/terraform/providers/hetzner-provider.d.ts +105 -0
- package/lib/terraform/providers/hetzner-provider.js +83 -0
- package/lib/terraform/providers/index.d.ts +2 -0
- package/lib/terraform/providers/index.js +19 -0
- package/lib/terraform/providers/provider-strategy.d.ts +44 -0
- package/lib/terraform/providers/provider-strategy.js +38 -0
- package/lib/terraform/terraform-base-project.d.ts +38 -0
- package/lib/terraform/terraform-base-project.js +97 -0
- package/lib/terraform/terraform-module-project.d.ts +24 -0
- package/lib/terraform/terraform-module-project.js +77 -0
- package/lib/terraform/terraform-stack-project.d.ts +28 -0
- package/lib/terraform/terraform-stack-project.js +83 -0
- package/mkdocs.yml +8 -0
- package/package.json +9 -8
|
@@ -57,31 +57,22 @@ project.synth();
|
|
|
57
57
|
|
|
58
58
|
## Features
|
|
59
59
|
|
|
60
|
-
###
|
|
60
|
+
### Common Configurations
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
This project type includes the same common configurations as other project types:
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
69
|
-
- **Semicolons** required
|
|
70
|
-
|
|
71
|
-
!!! tip "View Complete Configuration"
|
|
72
|
-
See the [Default Configurations](../default-configurations.md#prettier-configuration) page for the complete prettier setup and customization options.
|
|
73
|
-
|
|
74
|
-
### VSCode Integration
|
|
75
|
-
|
|
76
|
-
When enabled, the project automatically sets up VSCode configuration with settings and recommended extensions optimized for CDK development. For complete details about VSCode configuration, see [Default Configurations](../default-configurations.md#vscode-configuration).
|
|
64
|
+
!!! info "Default Configurations"
|
|
65
|
+
For complete details about Prettier and VSCode configurations, see [Default Configurations](../default-configurations.md). This includes:
|
|
66
|
+
|
|
67
|
+
- [Prettier Configuration](../default-configurations.md#prettier-configuration) - Code formatting rules and customization
|
|
68
|
+
- [VSCode Configuration](../default-configurations.md#vscode-configuration) - Editor settings and recommended extensions
|
|
77
69
|
|
|
78
|
-
|
|
70
|
+
### CDK-Specific Features
|
|
79
71
|
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
84
|
-
- Proper indentation and editor settings
|
|
72
|
+
- **AWS CDK Integration** with construct library setup
|
|
73
|
+
- **TypeScript configuration** optimized for CDK development
|
|
74
|
+
- **Publishing pipeline** ready for npm/JSR distribution
|
|
75
|
+
- **Testing setup** with Jest and CDK assertions
|
|
85
76
|
|
|
86
77
|
## Configuration Options
|
|
87
78
|
|
|
@@ -103,95 +94,12 @@ const project = new CdkLibrary({
|
|
|
103
94
|
});
|
|
104
95
|
```
|
|
105
96
|
|
|
106
|
-
###
|
|
107
|
-
|
|
108
|
-
#### Enable/Disable Prettier
|
|
109
|
-
|
|
110
|
-
```typescript linenums="1" title="Disable Prettier" hl_lines="3"
|
|
111
|
-
const project = new CdkLibrary({
|
|
112
|
-
// ... other options
|
|
113
|
-
prettier: false,
|
|
114
|
-
});
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
**Highlighted line explanation:**
|
|
118
|
-
|
|
119
|
-
- **Line 3**: Disables prettier entirely - no `.prettierrc.json` file will be created
|
|
120
|
-
|
|
121
|
-
#### Custom Prettier Options
|
|
122
|
-
|
|
123
|
-
```typescript linenums="1" title="Custom Prettier Configuration" hl_lines="5 6 7 8 9"
|
|
124
|
-
const project = new CdkLibrary({
|
|
125
|
-
// ... other options
|
|
126
|
-
prettier: true,
|
|
127
|
-
prettierOptions: {
|
|
128
|
-
settings: {
|
|
129
|
-
singleQuote: false,
|
|
130
|
-
semi: false,
|
|
131
|
-
tabWidth: 4,
|
|
132
|
-
trailingComma: 'none',
|
|
133
|
-
printWidth: 120,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
**Highlighted lines explanation:**
|
|
140
|
-
|
|
141
|
-
- **Line 6**: Use double quotes instead of single quotes
|
|
142
|
-
- **Line 7**: Omit semicolons
|
|
143
|
-
- **Line 8**: Use 4 spaces for indentation instead of 2
|
|
144
|
-
- **Line 9**: No trailing commas
|
|
145
|
-
- **Line 10**: Allow longer lines (120 characters instead of 80)
|
|
146
|
-
|
|
147
|
-
### VSCode Configuration
|
|
148
|
-
|
|
149
|
-
#### Enable/Disable VSCode Setup
|
|
150
|
-
|
|
151
|
-
=== "Default Behavior (Recommended)"
|
|
152
|
-
|
|
153
|
-
```typescript linenums="1" title="VSCode Enabled by Default"
|
|
154
|
-
const project = new CdkLibrary({
|
|
155
|
-
// ... other options
|
|
156
|
-
// vscode: undefined (defaults to enabled)
|
|
157
|
-
});
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
=== "Explicitly Enable"
|
|
161
|
-
|
|
162
|
-
```typescript linenums="1" title="Explicitly Enable VSCode" hl_lines="3"
|
|
163
|
-
const project = new CdkLibrary({
|
|
164
|
-
// ... other options
|
|
165
|
-
vscode: true,
|
|
166
|
-
});
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
**Highlighted line explanation:**
|
|
170
|
-
|
|
171
|
-
- **Line 3**: Same as default behavior, but explicit
|
|
172
|
-
|
|
173
|
-
=== "Disable VSCode"
|
|
174
|
-
|
|
175
|
-
```typescript linenums="1" title="Disable VSCode Configuration" hl_lines="3"
|
|
176
|
-
const project = new CdkLibrary({
|
|
177
|
-
// ... other options
|
|
178
|
-
vscode: false,
|
|
179
|
-
});
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
**Highlighted line explanation:**
|
|
183
|
-
|
|
184
|
-
- **Line 3**: No `.vscode/` folder will be created
|
|
97
|
+
### Common Configuration Options
|
|
185
98
|
|
|
186
|
-
|
|
99
|
+
For Prettier and VSCode configuration options, refer to [Default Configurations](../default-configurations.md):
|
|
187
100
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
| `undefined` | `undefined` | ✅ Created | ✅ Created | Default behavior - both enabled |
|
|
191
|
-
| `true` | `true` | ✅ Created | ✅ Created | Explicitly enabled |
|
|
192
|
-
| `false` | `true` | ❌ Not created | ✅ Created | Only VSCode enabled |
|
|
193
|
-
| `true` | `false` | ✅ Created | ❌ Not created | Only Prettier enabled |
|
|
194
|
-
| `false` | `false` | ❌ Not created | ❌ Not created | Both disabled |
|
|
101
|
+
- **Prettier**: [Customization Guide](../default-configurations.md#customization)
|
|
102
|
+
- **VSCode**: [Configuration Options](../default-configurations.md#customization)
|
|
195
103
|
|
|
196
104
|
## Examples
|
|
197
105
|
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
# CDK8s App Project
|
|
2
|
+
|
|
3
|
+
The CDK8s App Project type provides an opinionated setup for creating CDK8s applications with Kubernetes manifest generation, combining best practices and common configurations.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This project type extends the standard `TypeScriptProject` from projen with additional CDK8s features:
|
|
8
|
+
|
|
9
|
+
- **CDK8s integration** for Kubernetes manifest generation
|
|
10
|
+
- **Multi-version Kubernetes support** (v1.29 to v1.33)
|
|
11
|
+
- **Prettier configuration** and **VSCode settings** - see [Default Configurations](../default-configurations.md)
|
|
12
|
+
- **Common project structure** and tooling setup
|
|
13
|
+
- **Configurable CDK8s options** for custom workflows
|
|
14
|
+
- **Application-focused setup** for deploying Kubernetes applications
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
To create a new CDK8s App project, use the projen CLI:
|
|
19
|
+
|
|
20
|
+
```bash linenums="1"
|
|
21
|
+
npx projen new --from @jttc/projen-project-types cdk8s-app
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
This command will create a new project with the CDK8s App template and prompt you for the required configuration options such as:
|
|
25
|
+
|
|
26
|
+
- Project name
|
|
27
|
+
- Author information
|
|
28
|
+
- Repository URL
|
|
29
|
+
- Default branch
|
|
30
|
+
- Kubernetes version
|
|
31
|
+
|
|
32
|
+
After the project is created, you can customize it further by editing the `.projenrc.ts` file:
|
|
33
|
+
|
|
34
|
+
```typescript linenums="1" title=".projenrc.ts" hl_lines="4 8 12 13 14 15"
|
|
35
|
+
import { Cdk8App } from '@jttc/projen-project-types';
|
|
36
|
+
import { K8sVersion } from '@jttc/projen-project-types';
|
|
37
|
+
|
|
38
|
+
const project = new Cdk8App({
|
|
39
|
+
name: 'my-awesome-cdk8s-app',
|
|
40
|
+
author: 'Your Name',
|
|
41
|
+
authorAddress: 'your.email@example.com',
|
|
42
|
+
repositoryUrl: 'https://github.com/yourusername/my-awesome-cdk8s-app.git',
|
|
43
|
+
defaultReleaseBranch: 'main',
|
|
44
|
+
|
|
45
|
+
// CDK8s specific configuration
|
|
46
|
+
k8sVersion: K8sVersion.V1_31,
|
|
47
|
+
appPath: 'src/k8s',
|
|
48
|
+
appFile: 'main.ts',
|
|
49
|
+
outputPath: 'dist/manifests',
|
|
50
|
+
imports: ['k8s@1.31.0/api/core/v1/configmap', 'k8s@1.31.0/api/apps/v1/deployment'],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
project.synth();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Highlighted lines explanation:**
|
|
57
|
+
|
|
58
|
+
- **Line 4**: Choose a descriptive name for your CDK8s application
|
|
59
|
+
- **Line 8**: Set the repository URL for your project
|
|
60
|
+
- **Line 12**: Set the Kubernetes version for CDK8s imports
|
|
61
|
+
- **Line 13**: Configure custom path for Kubernetes source code
|
|
62
|
+
- **Line 14**: Set the main application file name
|
|
63
|
+
- **Line 15**: Set output directory for generated manifests
|
|
64
|
+
- **Line 16**: Add specific Kubernetes resource imports
|
|
65
|
+
|
|
66
|
+
## Features
|
|
67
|
+
|
|
68
|
+
### CDK8s Integration
|
|
69
|
+
|
|
70
|
+
The CDK8s App project includes full CDK8s integration with:
|
|
71
|
+
|
|
72
|
+
- **Automatic CDK8s setup** with configurable Kubernetes versions
|
|
73
|
+
- **Import generation** from Kubernetes APIs and custom resources
|
|
74
|
+
- **TypeScript-first** Kubernetes manifest authoring
|
|
75
|
+
- **CDK8s tasks** for building and synthesizing manifests
|
|
76
|
+
- **Application structure** optimized for Kubernetes deployments
|
|
77
|
+
|
|
78
|
+
### Kubernetes Version Support
|
|
79
|
+
|
|
80
|
+
Choose from multiple supported Kubernetes versions:
|
|
81
|
+
|
|
82
|
+
| Version | CDK8s Plus Package | Description |
|
|
83
|
+
|---------|-------------------|-------------|
|
|
84
|
+
| v1.29 | `cdk8s-plus-29` | Kubernetes v1.29 support |
|
|
85
|
+
| v1.30 | `cdk8s-plus-30` | Kubernetes v1.30 support |
|
|
86
|
+
| v1.31 | `cdk8s-plus-31` | Kubernetes v1.31 support (default) |
|
|
87
|
+
| v1.32 | `cdk8s-plus-32` | Kubernetes v1.32 support |
|
|
88
|
+
| v1.33 | `cdk8s-plus-33` | Kubernetes v1.33 support |
|
|
89
|
+
|
|
90
|
+
### Common Configurations
|
|
91
|
+
|
|
92
|
+
This project type includes the same common configurations as other project types:
|
|
93
|
+
|
|
94
|
+
!!! info "Default Configurations"
|
|
95
|
+
For complete details about Prettier and VSCode configurations, see [Default Configurations](../default-configurations.md). This includes:
|
|
96
|
+
|
|
97
|
+
- [Prettier Configuration](../default-configurations.md#prettier-configuration) - Code formatting rules and customization
|
|
98
|
+
- [VSCode Configuration](../default-configurations.md#vscode-configuration) - Editor settings and recommended extensions
|
|
99
|
+
|
|
100
|
+
### CDK8s App Structure
|
|
101
|
+
|
|
102
|
+
The CDK8s App project creates a complete application structure with:
|
|
103
|
+
|
|
104
|
+
- **Main application entry point** (`src/main.ts`)
|
|
105
|
+
- **CDK8s configuration** (`cdk8s.yaml`)
|
|
106
|
+
- **Kubernetes source directory** (configurable, default: `src/k8s`)
|
|
107
|
+
- **Output directory** for generated manifests (configurable, default: `kubernetes`)
|
|
108
|
+
- **Import generation setup** for Kubernetes APIs
|
|
109
|
+
- **Proper TypeScript setup** for CDK8s development
|
|
110
|
+
|
|
111
|
+
## Configuration Options
|
|
112
|
+
|
|
113
|
+
### Basic Configuration
|
|
114
|
+
|
|
115
|
+
All standard `TypeScriptProjectOptions` are supported, along with CDK8s-specific options:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
interface Cdk8sAppOptions extends Cdk8sBaseOptions, TypeScriptProjectOptions {
|
|
119
|
+
// Standard TypeScript project options
|
|
120
|
+
name: string;
|
|
121
|
+
defaultReleaseBranch: string;
|
|
122
|
+
|
|
123
|
+
// CDK8s specific options
|
|
124
|
+
k8sVersion?: K8sVersion;
|
|
125
|
+
appPath?: string;
|
|
126
|
+
appFile?: string;
|
|
127
|
+
outputPath?: string;
|
|
128
|
+
imports?: string[];
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### CDK8s Configuration
|
|
133
|
+
|
|
134
|
+
| Option | Type | Default | Description |
|
|
135
|
+
|--------|------|---------|-------------|
|
|
136
|
+
| `k8sVersion` | `K8sVersion` | `V1_31` | Kubernetes version for CDK8s imports |
|
|
137
|
+
| `appPath` | `string` | `"src/k8s"` | Path to CDK8s application source |
|
|
138
|
+
| `appFile` | `string` | `"main.ts"` | Main application file name |
|
|
139
|
+
| `outputPath` | `string` | `"kubernetes"` | Output directory for manifests |
|
|
140
|
+
| `imports` | `string[]` | `[]` | Additional Kubernetes imports |
|
|
141
|
+
|
|
142
|
+
### Advanced Configuration
|
|
143
|
+
|
|
144
|
+
```typescript title="Advanced .projenrc.ts"
|
|
145
|
+
import { Cdk8App } from '@jttc/projen-project-types';
|
|
146
|
+
import { K8sVersion } from '@jttc/projen-project-types';
|
|
147
|
+
|
|
148
|
+
const project = new Cdk8App({
|
|
149
|
+
name: 'advanced-cdk8s-app',
|
|
150
|
+
defaultReleaseBranch: 'main',
|
|
151
|
+
|
|
152
|
+
// CDK8s Configuration
|
|
153
|
+
k8sVersion: K8sVersion.V1_31,
|
|
154
|
+
appPath: 'src/kubernetes',
|
|
155
|
+
appFile: 'app.ts',
|
|
156
|
+
outputPath: 'manifests',
|
|
157
|
+
|
|
158
|
+
// Kubernetes API imports
|
|
159
|
+
imports: [
|
|
160
|
+
'k8s@1.31.0/api/core/v1/pod',
|
|
161
|
+
'k8s@1.31.0/api/core/v1/service',
|
|
162
|
+
'k8s@1.31.0/api/apps/v1/deployment',
|
|
163
|
+
'k8s@1.31.0/api/networking/v1/ingress',
|
|
164
|
+
],
|
|
165
|
+
|
|
166
|
+
// TypeScript project options
|
|
167
|
+
prettier: true,
|
|
168
|
+
vscode: true,
|
|
169
|
+
packageName: '@myorg/k8s-app',
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
project.synth();
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Common Usage Patterns
|
|
176
|
+
|
|
177
|
+
### Simple Web Application
|
|
178
|
+
|
|
179
|
+
```typescript title="Basic web app deployment"
|
|
180
|
+
import { Cdk8App } from '@jttc/projen-project-types';
|
|
181
|
+
import { K8sVersion } from '@jttc/projen-project-types';
|
|
182
|
+
|
|
183
|
+
const project = new Cdk8App({
|
|
184
|
+
name: 'my-web-app',
|
|
185
|
+
defaultReleaseBranch: 'main',
|
|
186
|
+
k8sVersion: K8sVersion.V1_31,
|
|
187
|
+
|
|
188
|
+
imports: [
|
|
189
|
+
'k8s@1.31.0/api/core/v1/service',
|
|
190
|
+
'k8s@1.31.0/api/apps/v1/deployment',
|
|
191
|
+
'k8s@1.31.0/api/networking/v1/ingress',
|
|
192
|
+
],
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
project.synth();
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Microservices Application
|
|
199
|
+
|
|
200
|
+
```typescript title="Multi-service deployment"
|
|
201
|
+
import { Cdk8App } from '@jttc/projen-project-types';
|
|
202
|
+
import { K8sVersion } from '@jttc/projen-project-types';
|
|
203
|
+
|
|
204
|
+
const project = new Cdk8App({
|
|
205
|
+
name: 'microservices-platform',
|
|
206
|
+
defaultReleaseBranch: 'main',
|
|
207
|
+
k8sVersion: K8sVersion.V1_31,
|
|
208
|
+
appPath: 'src/platform',
|
|
209
|
+
outputPath: 'dist/k8s',
|
|
210
|
+
|
|
211
|
+
imports: [
|
|
212
|
+
'k8s@1.31.0/api/core/v1/configmap',
|
|
213
|
+
'k8s@1.31.0/api/core/v1/secret',
|
|
214
|
+
'k8s@1.31.0/api/core/v1/service',
|
|
215
|
+
'k8s@1.31.0/api/apps/v1/deployment',
|
|
216
|
+
'k8s@1.31.0/api/networking/v1/networkpolicy',
|
|
217
|
+
],
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
project.synth();
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Custom Resources Integration
|
|
224
|
+
|
|
225
|
+
```typescript title="With custom Kubernetes operators"
|
|
226
|
+
import { Cdk8App } from '@jttc/projen-project-types';
|
|
227
|
+
import { K8sVersion } from '@jttc/projen-project-types';
|
|
228
|
+
|
|
229
|
+
const project = new Cdk8App({
|
|
230
|
+
name: 'custom-resources-app',
|
|
231
|
+
defaultReleaseBranch: 'main',
|
|
232
|
+
k8sVersion: K8sVersion.V1_31,
|
|
233
|
+
|
|
234
|
+
imports: [
|
|
235
|
+
// Standard Kubernetes resources
|
|
236
|
+
'k8s@1.31.0/api/core/v1',
|
|
237
|
+
'k8s@1.31.0/api/apps/v1',
|
|
238
|
+
// Custom resources from operators
|
|
239
|
+
'prometheus-operator@0.65.1',
|
|
240
|
+
'istio@1.18.0',
|
|
241
|
+
],
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
project.synth();
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Development Workflow
|
|
248
|
+
|
|
249
|
+
### Generated Files
|
|
250
|
+
|
|
251
|
+
The CDK8s App project generates several important files:
|
|
252
|
+
|
|
253
|
+
- **`cdk8s.yaml`**: CDK8s configuration file
|
|
254
|
+
- **`src/k8s/main.ts`**: Main CDK8s application (configurable path)
|
|
255
|
+
- **`kubernetes/`**: Generated Kubernetes manifests (configurable path)
|
|
256
|
+
- **Import files**: Generated TypeScript bindings for Kubernetes APIs
|
|
257
|
+
|
|
258
|
+
### Available Tasks
|
|
259
|
+
|
|
260
|
+
| Task | Command | Description |
|
|
261
|
+
|------|---------|-------------|
|
|
262
|
+
| Build | `npm run build` | Compile TypeScript and generate manifests |
|
|
263
|
+
| Import | `npm run cdk8s:import` | Generate TypeScript bindings for Kubernetes APIs |
|
|
264
|
+
| Synthesize | `npm run cdk8s:synth` | Generate Kubernetes manifests |
|
|
265
|
+
| Test | `npm run test` | Run unit tests |
|
|
266
|
+
|
|
267
|
+
### Typical Development Flow
|
|
268
|
+
|
|
269
|
+
1. **Initial setup**: Run `npm run cdk8s:import` to generate API bindings
|
|
270
|
+
2. **Write CDK8s code**: Create your Kubernetes application in the configured app path
|
|
271
|
+
3. **Build and test**: Run `npm run build` and `npm run test`
|
|
272
|
+
4. **Generate manifests**: Run `npm run cdk8s:synth` to create Kubernetes YAML
|
|
273
|
+
5. **Deploy**: Apply the generated manifests to your Kubernetes cluster
|
|
274
|
+
|
|
275
|
+
## CDK8s Component Integration
|
|
276
|
+
|
|
277
|
+
The CDK8s App project uses the [CDK8s Component](../components/cdk8s.md) internally to provide:
|
|
278
|
+
|
|
279
|
+
- Kubernetes API import management
|
|
280
|
+
- CDK8s task configuration
|
|
281
|
+
- Proper dependency management
|
|
282
|
+
- Custom resource integration
|
|
283
|
+
|
|
284
|
+
For more details on the underlying CDK8s functionality, see the [CDK8s Component documentation](../components/cdk8s.md).
|
|
285
|
+
|
|
286
|
+
## Example Application
|
|
287
|
+
|
|
288
|
+
Here's a simple example of what your `src/k8s/main.ts` might look like:
|
|
289
|
+
|
|
290
|
+
```typescript title="src/k8s/main.ts"
|
|
291
|
+
import { App, Chart, ChartProps } from 'cdk8s';
|
|
292
|
+
import { Construct } from 'constructs';
|
|
293
|
+
import { Deployment, Service, IntOrString } from 'cdk8s-plus-31';
|
|
294
|
+
|
|
295
|
+
export class MyChart extends Chart {
|
|
296
|
+
constructor(scope: Construct, id: string, props: ChartProps = { }) {
|
|
297
|
+
super(scope, id, props);
|
|
298
|
+
|
|
299
|
+
// Create a deployment
|
|
300
|
+
const deployment = new Deployment(this, 'my-app', {
|
|
301
|
+
replicas: 3,
|
|
302
|
+
containers: [{
|
|
303
|
+
image: 'nginx:latest',
|
|
304
|
+
ports: [{ containerPort: 80 }],
|
|
305
|
+
}],
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// Expose the deployment
|
|
309
|
+
new Service(this, 'my-service', {
|
|
310
|
+
selector: deployment,
|
|
311
|
+
ports: [{ port: 80, targetPort: IntOrString.fromNumber(80) }],
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const app = new App();
|
|
317
|
+
new MyChart(app, 'my-chart');
|
|
318
|
+
app.synth();
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
This example creates a simple nginx deployment with a service to expose it.
|
|
322
|
+
|
|
323
|
+
## Best Practices
|
|
324
|
+
|
|
325
|
+
### Project Structure
|
|
326
|
+
|
|
327
|
+
- Keep your CDK8s application code in the configured `appPath` directory
|
|
328
|
+
- Use meaningful names for your charts and constructs
|
|
329
|
+
- Organize complex applications into multiple chart files
|
|
330
|
+
- Leverage TypeScript interfaces for configuration
|
|
331
|
+
|
|
332
|
+
### Configuration Management
|
|
333
|
+
|
|
334
|
+
- Use ConfigMaps and Secrets for application configuration
|
|
335
|
+
- Implement proper resource naming conventions
|
|
336
|
+
- Use labels and annotations for better resource management
|
|
337
|
+
- Consider using CDK8s constructs for common patterns
|
|
338
|
+
|
|
339
|
+
### Testing
|
|
340
|
+
|
|
341
|
+
- Write unit tests for your CDK8s constructs
|
|
342
|
+
- Use snapshot testing for manifest verification
|
|
343
|
+
- Test different configuration scenarios
|
|
344
|
+
- Validate generated manifests against Kubernetes schemas
|
|
345
|
+
|
|
346
|
+
### Deployment
|
|
347
|
+
|
|
348
|
+
- Review generated manifests before deploying
|
|
349
|
+
- Use proper namespacing strategies
|
|
350
|
+
- Implement resource quotas and limits
|
|
351
|
+
- Consider using GitOps workflows for deployment
|
|
352
|
+
|
|
353
|
+
For more advanced CDK8s usage patterns and examples, refer to the [official CDK8s documentation](https://cdk8s.io/).
|