@jttc/projen-project-types 1.0.0-beta.0 → 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 +4637 -14
- package/AGENTS.md +132 -0
- package/API.md +31146 -7
- 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/default-configurations.md +267 -0
- package/docs/index.md +86 -1
- package/docs/project-types/cdk-app.md +481 -0
- package/docs/project-types/cdk-library.md +321 -0
- 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 +12 -0
- package/lib/cdk/cdk-library-project.js +28 -0
- 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 +40 -0
- package/lib/common/common-options.js +110 -0
- 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 -3
- package/lib/index.js +20 -12
- 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 +12 -0
- package/package.json +14 -7
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# Commitzent Component
|
|
2
|
+
|
|
3
|
+
The Commitzent Component provides standardized **Conventional Commits** support to all project types, enabling consistent and structured commit messages across your development workflow.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
[Conventional Commits](https://www.conventionalcommits.org/) is a specification for adding human and machine-readable meaning to commit messages. The Commitzent component integrates [Commitizen](https://commitizen.github.io/cz-cli/) with a customizable configuration to enforce this standard in your projects.
|
|
8
|
+
|
|
9
|
+
Key benefits:
|
|
10
|
+
- **Consistent commit format** across team members
|
|
11
|
+
- **Automated changelog generation** support
|
|
12
|
+
- **Semantic versioning** integration
|
|
13
|
+
- **Interactive prompts** to guide commit creation
|
|
14
|
+
- **Customizable scopes** for different project areas
|
|
15
|
+
|
|
16
|
+
!!! info "Universal Integration"
|
|
17
|
+
This component is automatically included in **all** project types (CDK App, CDK Library, CDK8s App, CDK8s Library) by default and can be easily disabled if not needed.
|
|
18
|
+
|
|
19
|
+
## Key Features
|
|
20
|
+
|
|
21
|
+
### 🔧 **Automatic Setup**
|
|
22
|
+
- Installs Commitizen and cz-customizable dependencies
|
|
23
|
+
- Generates `.czrc` configuration file
|
|
24
|
+
- Creates customizable `.cz-config.js` with project-specific settings
|
|
25
|
+
- Adds `commit` script to package.json
|
|
26
|
+
|
|
27
|
+
### 📝 **Interactive Commit Workflow**
|
|
28
|
+
- Guided prompts for commit type, scope, and description
|
|
29
|
+
- Built-in validation for conventional commit format
|
|
30
|
+
- Support for breaking changes and issue references
|
|
31
|
+
- Consistent formatting across all commits
|
|
32
|
+
|
|
33
|
+
### 🎯 **Customizable Scopes**
|
|
34
|
+
- Pre-configured default scopes for each project type
|
|
35
|
+
- Ability to add custom scopes programmatically
|
|
36
|
+
- Project-specific scope suggestions
|
|
37
|
+
|
|
38
|
+
### ⚡ **Easy Usage**
|
|
39
|
+
- Simple `yarn commit` command replaces `git commit`
|
|
40
|
+
- No need to remember conventional commit syntax
|
|
41
|
+
- Automatic formatting and validation
|
|
42
|
+
|
|
43
|
+
## Default Configuration
|
|
44
|
+
|
|
45
|
+
### Commit Types
|
|
46
|
+
The component includes standard conventional commit types:
|
|
47
|
+
|
|
48
|
+
| Type | Description | Example |
|
|
49
|
+
|------|-------------|---------|
|
|
50
|
+
| `feat` | New feature | `feat(api): add user authentication` |
|
|
51
|
+
| `fix` | Bug fix | `fix(ui): resolve navigation issue` |
|
|
52
|
+
| `docs` | Documentation | `docs(readme): update installation guide` |
|
|
53
|
+
| `style` | Code style changes | `style(components): format with prettier` |
|
|
54
|
+
| `refactor` | Code refactoring | `refactor(utils): simplify helper functions` |
|
|
55
|
+
| `perf` | Performance improvements | `perf(api): optimize database queries` |
|
|
56
|
+
| `test` | Tests | `test(auth): add unit tests for login` |
|
|
57
|
+
| `build` | Build system | `build(webpack): update configuration` |
|
|
58
|
+
| `ci` | CI/CD changes | `ci(github): add automated testing` |
|
|
59
|
+
| `chore` | Maintenance tasks | `chore(deps): update dependencies` |
|
|
60
|
+
| `revert` | Revert previous commit | `revert: undo previous feature` |
|
|
61
|
+
|
|
62
|
+
### Default Scopes
|
|
63
|
+
Each project type includes relevant default scopes:
|
|
64
|
+
|
|
65
|
+
=== "CDK App"
|
|
66
|
+
- `stack` - CloudFormation stacks
|
|
67
|
+
- `construct` - CDK constructs
|
|
68
|
+
- `config` - Configuration changes
|
|
69
|
+
- `infra` - Infrastructure components
|
|
70
|
+
|
|
71
|
+
=== "CDK Library"
|
|
72
|
+
- `construct` - Library constructs
|
|
73
|
+
- `api` - Public API changes
|
|
74
|
+
- `examples` - Usage examples
|
|
75
|
+
- `config` - Configuration
|
|
76
|
+
|
|
77
|
+
=== "CDK8s Projects"
|
|
78
|
+
- `manifest` - Kubernetes manifests
|
|
79
|
+
- `chart` - Helm charts
|
|
80
|
+
- `config` - Configuration
|
|
81
|
+
- `docs` - Documentation
|
|
82
|
+
|
|
83
|
+
## Usage
|
|
84
|
+
|
|
85
|
+
### Basic Commit Workflow
|
|
86
|
+
|
|
87
|
+
Instead of using `git commit`, use the interactive commit command:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Stage your changes
|
|
91
|
+
git add .
|
|
92
|
+
|
|
93
|
+
# Use interactive commit
|
|
94
|
+
yarn commit
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Interactive Prompt Example
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
$ yarn commit
|
|
101
|
+
|
|
102
|
+
? Select the type of change that you're committing: (Use arrow keys)
|
|
103
|
+
❯ feat: A new feature
|
|
104
|
+
fix: A bug fix
|
|
105
|
+
docs: Documentation only changes
|
|
106
|
+
style: Changes that do not affect the meaning of the code
|
|
107
|
+
refactor: A code change that neither fixes a bug nor adds a feature
|
|
108
|
+
perf: A code change that improves performance
|
|
109
|
+
test: Adding missing tests or correcting existing tests
|
|
110
|
+
|
|
111
|
+
? What is the scope of this change (e.g. component or file name): (press enter to skip)
|
|
112
|
+
api
|
|
113
|
+
|
|
114
|
+
? Write a short, imperative tense description of the change (max 72 chars):
|
|
115
|
+
add user authentication endpoint
|
|
116
|
+
|
|
117
|
+
? Provide a longer description of the change: (press enter to skip)
|
|
118
|
+
Implement JWT-based authentication with login and logout endpoints
|
|
119
|
+
|
|
120
|
+
? Are there any breaking changes? (y/N)
|
|
121
|
+
|
|
122
|
+
? Does this change affect any open issues? (y/N)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Result:** `feat(api): add user authentication endpoint`
|
|
126
|
+
|
|
127
|
+
## Customization
|
|
128
|
+
|
|
129
|
+
### Adding Custom Scopes
|
|
130
|
+
|
|
131
|
+
You can add project-specific scopes programmatically:
|
|
132
|
+
|
|
133
|
+
```typescript title=".projenrc.ts" hl_lines="12-14"
|
|
134
|
+
import { CdkApp } from '@jttc/projen-project-types';
|
|
135
|
+
|
|
136
|
+
const project = new CdkApp({
|
|
137
|
+
name: 'my-cdk-app',
|
|
138
|
+
cdkVersion: '2.1.0',
|
|
139
|
+
defaultReleaseBranch: 'main',
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Add custom scopes for your project
|
|
143
|
+
project.commitzent?.addScope({ name: 'database' });
|
|
144
|
+
project.commitzent?.addScope({ name: 'auth' });
|
|
145
|
+
project.commitzent?.addScope({ name: 'ui' });
|
|
146
|
+
|
|
147
|
+
project.synth();
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Disabling Commitzent
|
|
151
|
+
|
|
152
|
+
If you prefer not to use conventional commits, you can disable the component:
|
|
153
|
+
|
|
154
|
+
```typescript title=".projenrc.ts" hl_lines="6"
|
|
155
|
+
import { CdkLibrary } from '@jttc/projen-project-types';
|
|
156
|
+
|
|
157
|
+
const project = new CdkLibrary({
|
|
158
|
+
name: 'my-library',
|
|
159
|
+
// ... other options
|
|
160
|
+
commitzent: false, // Disable conventional commits
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
project.synth();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
When disabled:
|
|
167
|
+
- ❌ No Commitizen dependencies are installed
|
|
168
|
+
- ❌ No `.czrc` or `.cz-config.js` files are generated
|
|
169
|
+
- ❌ No `commit` script in package.json
|
|
170
|
+
- ✅ Regular `git commit` workflow is preserved
|
|
171
|
+
|
|
172
|
+
## Generated Files
|
|
173
|
+
|
|
174
|
+
### `.czrc`
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"path": "./node_modules/cz-customizable"
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### `.cz-config.js` (example for CDK App)
|
|
182
|
+
```javascript
|
|
183
|
+
module.exports = {
|
|
184
|
+
types: [
|
|
185
|
+
{ value: 'feat', name: 'feat: A new feature' },
|
|
186
|
+
{ value: 'fix', name: 'fix: A bug fix' },
|
|
187
|
+
// ... more types
|
|
188
|
+
],
|
|
189
|
+
scopes: [
|
|
190
|
+
{ name: 'stack' },
|
|
191
|
+
{ name: 'construct' },
|
|
192
|
+
{ name: 'config' },
|
|
193
|
+
{ name: 'infra' },
|
|
194
|
+
// ... custom scopes
|
|
195
|
+
],
|
|
196
|
+
messages: {
|
|
197
|
+
type: "Select the type of change that you're committing:",
|
|
198
|
+
scope: 'What is the scope of this change (e.g. component or file name):',
|
|
199
|
+
customScope: 'Denote the SCOPE of this change:',
|
|
200
|
+
subject: 'Write a short, imperative tense description of the change (max 72 chars):\n',
|
|
201
|
+
body: 'Provide a longer description of the change: (press enter to skip)\n',
|
|
202
|
+
breaking: 'Are there any breaking changes? (y/N)',
|
|
203
|
+
footer: 'Does this change affect any open issues? (y/N)',
|
|
204
|
+
confirmCommit: 'Are you sure you want to proceed with the commit above?',
|
|
205
|
+
},
|
|
206
|
+
allowBreakingChanges: ['feat', 'fix'],
|
|
207
|
+
skipQuestions: [],
|
|
208
|
+
subjectLimit: 72,
|
|
209
|
+
};
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Package.json Integration
|
|
213
|
+
|
|
214
|
+
The component automatically adds the commit script to your package.json:
|
|
215
|
+
|
|
216
|
+
```json title="package.json"
|
|
217
|
+
{
|
|
218
|
+
"scripts": {
|
|
219
|
+
"commit": "npx projen commit"
|
|
220
|
+
},
|
|
221
|
+
"devDependencies": {
|
|
222
|
+
"commitizen": "latest",
|
|
223
|
+
"cz-customizable": "latest"
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Best Practices
|
|
229
|
+
|
|
230
|
+
### Commit Message Guidelines
|
|
231
|
+
|
|
232
|
+
1. **Use imperative mood**: "add feature" not "added feature"
|
|
233
|
+
2. **Keep subject line under 72 characters**
|
|
234
|
+
3. **Provide context in scope**: use meaningful scope names
|
|
235
|
+
4. **Include issue numbers** when applicable
|
|
236
|
+
5. **Mark breaking changes** clearly
|
|
237
|
+
|
|
238
|
+
### Scope Naming
|
|
239
|
+
|
|
240
|
+
- Use **lowercase** scope names
|
|
241
|
+
- Keep scopes **short and descriptive**
|
|
242
|
+
- Group related changes under **consistent scopes**
|
|
243
|
+
- Avoid **too many scopes** - keep it simple
|
|
244
|
+
|
|
245
|
+
### Example Good Commits
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
feat(auth): implement JWT token validation
|
|
249
|
+
fix(api): handle null response in user endpoint
|
|
250
|
+
docs(readme): add deployment instructions
|
|
251
|
+
style(components): apply consistent formatting
|
|
252
|
+
refactor(utils): extract common helper functions
|
|
253
|
+
test(auth): add integration tests for login flow
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
## Related Resources
|
|
258
|
+
|
|
259
|
+
- [Conventional Commits Specification](https://www.conventionalcommits.org/)
|
|
260
|
+
- [Commitizen CLI Documentation](https://commitizen.github.io/cz-cli/)
|
|
261
|
+
- [Angular Commit Guidelines](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#commit)
|
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
# K3d Component
|
|
2
|
+
|
|
3
|
+
The K3d Component enables you to set up **local Kubernetes development environments** using K3d (K3s in Docker) in any projen TypeScript project. K3d creates lightweight Kubernetes clusters perfect for development, testing, and learning.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
K3d is a lightweight wrapper to run K3s (Rancher Lab's minimal Kubernetes distribution) in Docker. This component automatically configures and manages K3d clusters for your development workflow, providing:
|
|
8
|
+
|
|
9
|
+
- **Local Kubernetes clusters** running in Docker containers
|
|
10
|
+
- **Fast cluster creation and destruction** for development iterations
|
|
11
|
+
- **Load balancer configuration** for accessing your applications
|
|
12
|
+
- **Automated cluster management** through projen tasks
|
|
13
|
+
- **Configurable cluster settings** for different development scenarios
|
|
14
|
+
|
|
15
|
+
!!! info "Universal Compatibility"
|
|
16
|
+
This component works with **any** projen TypeScript project, including CDK apps, libraries, or standalone applications. It's particularly useful when integrated with CDK8s applications for local testing.
|
|
17
|
+
|
|
18
|
+
## Key Features
|
|
19
|
+
|
|
20
|
+
### 🚀 **Quick Setup**
|
|
21
|
+
- Generates `k3d.yaml` configuration file automatically
|
|
22
|
+
- Creates projen tasks for cluster lifecycle management
|
|
23
|
+
- Configures load balancer for application access
|
|
24
|
+
- Sets up development-optimized defaults
|
|
25
|
+
|
|
26
|
+
### ⚙️ **Cluster Management Tasks**
|
|
27
|
+
- **`k3d:create`**: Create and start the K3d cluster
|
|
28
|
+
- **`k3d:start`**: Start an existing stopped cluster
|
|
29
|
+
- **`k3d:stop`**: Stop a running cluster (preserves data)
|
|
30
|
+
- **`k3d:delete`**: Completely remove the cluster
|
|
31
|
+
|
|
32
|
+
### 🎯 **Development Optimized**
|
|
33
|
+
- Disables Traefik by default (reduces resource usage)
|
|
34
|
+
- Disables metrics-server by default (faster startup)
|
|
35
|
+
- Configures load balancer on port 8080 by default
|
|
36
|
+
- Updates local kubeconfig automatically
|
|
37
|
+
|
|
38
|
+
### 📁 **Flexible Configuration**
|
|
39
|
+
- Custom cluster names and network settings
|
|
40
|
+
- Configurable server and agent node counts
|
|
41
|
+
- Custom K3s arguments and options
|
|
42
|
+
- Load balancer port configuration
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
### Adding to a CDK8s App
|
|
47
|
+
|
|
48
|
+
K3d is automatically included in CDK8s applications for local development:
|
|
49
|
+
|
|
50
|
+
```typescript linenums="1" title=".projenrc.ts"
|
|
51
|
+
import { Cdk8App } from '@jttc/projen-project-types';
|
|
52
|
+
|
|
53
|
+
const project = new Cdk8App({
|
|
54
|
+
name: 'my-k8s-app',
|
|
55
|
+
defaultReleaseBranch: 'main',
|
|
56
|
+
// K3d is enabled by default
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
project.synth();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Adding to Any TypeScript Project
|
|
63
|
+
|
|
64
|
+
```typescript linenums="1" title=".projenrc.ts" hl_lines="2 11-15"
|
|
65
|
+
import { TypeScriptProject } from 'projen/lib/typescript';
|
|
66
|
+
import { K3d } from '@jttc/projen-project-types';
|
|
67
|
+
|
|
68
|
+
const project = new TypeScriptProject({
|
|
69
|
+
name: 'my-project',
|
|
70
|
+
defaultReleaseBranch: 'main',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Add K3d component
|
|
74
|
+
new K3d(project, 'k3d', {
|
|
75
|
+
k3d: {
|
|
76
|
+
metadata: { name: 'my-dev-cluster' }
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
project.synth();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Configuration Options
|
|
84
|
+
|
|
85
|
+
The K3d component accepts a `K3dOptions` configuration object with the following structure:
|
|
86
|
+
|
|
87
|
+
### Basic Configuration
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
const k3dOptions = {
|
|
91
|
+
k3d: {
|
|
92
|
+
metadata: { name: 'my-cluster' },
|
|
93
|
+
servers: 1, // Number of server nodes
|
|
94
|
+
agents: 0, // Number of worker nodes
|
|
95
|
+
network: 'k3s', // Docker network name
|
|
96
|
+
ports: [{ // Port mappings
|
|
97
|
+
port: '8080:80',
|
|
98
|
+
nodeFilters: ['loadbalancer']
|
|
99
|
+
}],
|
|
100
|
+
options: {
|
|
101
|
+
k3s: {
|
|
102
|
+
extraArgs: [ // Custom K3s arguments
|
|
103
|
+
{
|
|
104
|
+
arg: '--disable=servicelb',
|
|
105
|
+
nodeFilters: ['server:*']
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
kubeconfig: {
|
|
110
|
+
updateDefaultKubeconfig: true
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Advanced Configuration
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const advancedK3dOptions = {
|
|
121
|
+
k3d: {
|
|
122
|
+
metadata: { name: 'production-like-cluster' },
|
|
123
|
+
servers: 3, // HA control plane
|
|
124
|
+
agents: 2, // Worker nodes
|
|
125
|
+
network: 'custom-net',
|
|
126
|
+
image: 'docker.io/rancher/k3s:v1.30.8-k3s1',
|
|
127
|
+
ports: [
|
|
128
|
+
{
|
|
129
|
+
port: '8080:80',
|
|
130
|
+
nodeFilters: ['loadbalancer']
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
port: '8443:443',
|
|
134
|
+
nodeFilters: ['loadbalancer']
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
options: {
|
|
138
|
+
k3s: {
|
|
139
|
+
extraArgs: [
|
|
140
|
+
{
|
|
141
|
+
arg: '--disable=traefik',
|
|
142
|
+
nodeFilters: ['server:*']
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
arg: '--disable=servicelb',
|
|
146
|
+
nodeFilters: ['server:*']
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
},
|
|
150
|
+
kubeconfig: {
|
|
151
|
+
updateDefaultKubeconfig: true
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Generated Files
|
|
159
|
+
|
|
160
|
+
### k3d.yaml
|
|
161
|
+
|
|
162
|
+
The component generates a `k3d.yaml` configuration file in your project root:
|
|
163
|
+
|
|
164
|
+
```yaml title="k3d.yaml"
|
|
165
|
+
apiVersion: k3d.io/v1alpha5
|
|
166
|
+
kind: Simple
|
|
167
|
+
metadata:
|
|
168
|
+
name: my-cluster
|
|
169
|
+
servers: 1
|
|
170
|
+
agents: 0
|
|
171
|
+
network: k3s
|
|
172
|
+
image: docker.io/rancher/k3s:v1.30.8-k3s1
|
|
173
|
+
ports:
|
|
174
|
+
- port: 8080:80
|
|
175
|
+
nodeFilters:
|
|
176
|
+
- loadbalancer
|
|
177
|
+
options:
|
|
178
|
+
k3s:
|
|
179
|
+
extraArgs:
|
|
180
|
+
- arg: --disable=traefik
|
|
181
|
+
nodeFilters:
|
|
182
|
+
- server:*
|
|
183
|
+
- arg: --disable=metrics-server
|
|
184
|
+
nodeFilters:
|
|
185
|
+
- server:*
|
|
186
|
+
kubeconfig:
|
|
187
|
+
updateDefaultKubeconfig: true
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Development Workflow
|
|
191
|
+
|
|
192
|
+
### 1. Create Development Cluster
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Create and start the cluster
|
|
196
|
+
yarn k3d:create
|
|
197
|
+
|
|
198
|
+
# Verify cluster is running
|
|
199
|
+
kubectl cluster-info
|
|
200
|
+
kubectl get nodes
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### 2. Deploy Your Applications
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# If using CDK8s
|
|
207
|
+
yarn cdk8s:synth
|
|
208
|
+
kubectl apply -f dist/
|
|
209
|
+
|
|
210
|
+
# Or apply any Kubernetes manifests
|
|
211
|
+
kubectl apply -f manifests/
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 3. Access Applications
|
|
215
|
+
|
|
216
|
+
With the default configuration, applications are accessible at:
|
|
217
|
+
- HTTP: `http://localhost:8080`
|
|
218
|
+
- HTTPS: `https://localhost:8443` (if configured)
|
|
219
|
+
|
|
220
|
+
### 4. Manage Cluster Lifecycle
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
# Stop cluster (preserves data)
|
|
224
|
+
yarn k3d:stop
|
|
225
|
+
|
|
226
|
+
# Start stopped cluster
|
|
227
|
+
yarn k3d:start
|
|
228
|
+
|
|
229
|
+
# Delete cluster completely
|
|
230
|
+
yarn k3d:delete
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## Projen Tasks
|
|
234
|
+
|
|
235
|
+
The component creates the following projen tasks:
|
|
236
|
+
|
|
237
|
+
| Task | Description | Command |
|
|
238
|
+
|------|-------------|---------|
|
|
239
|
+
| `k3d:create` | Create and start K3d cluster | `k3d cluster create --config k3d.yaml` |
|
|
240
|
+
| `k3d:start` | Start existing cluster | `k3d cluster start <cluster-name>` |
|
|
241
|
+
| `k3d:stop` | Stop running cluster | `k3d cluster stop <cluster-name>` |
|
|
242
|
+
| `k3d:delete` | Delete cluster | `k3d cluster delete <cluster-name>` |
|
|
243
|
+
|
|
244
|
+
## Integration Examples
|
|
245
|
+
|
|
246
|
+
### With CDK8s Application
|
|
247
|
+
|
|
248
|
+
K3d works seamlessly with CDK8s applications for local development:
|
|
249
|
+
|
|
250
|
+
```typescript title="src/main.ts"
|
|
251
|
+
import { App, Chart } from 'cdk8s';
|
|
252
|
+
import { KubeDeployment, KubeService } from 'cdk8s-plus-30/lib/imports/k8s';
|
|
253
|
+
|
|
254
|
+
const app = new App();
|
|
255
|
+
const chart = new Chart(app, 'MyChart');
|
|
256
|
+
|
|
257
|
+
// Define your Kubernetes resources
|
|
258
|
+
new KubeDeployment(chart, 'nginx', {
|
|
259
|
+
spec: {
|
|
260
|
+
replicas: 3,
|
|
261
|
+
selector: { matchLabels: { app: 'nginx' } },
|
|
262
|
+
template: {
|
|
263
|
+
metadata: { labels: { app: 'nginx' } },
|
|
264
|
+
spec: {
|
|
265
|
+
containers: [{
|
|
266
|
+
name: 'nginx',
|
|
267
|
+
image: 'nginx:latest',
|
|
268
|
+
ports: [{ containerPort: 80 }]
|
|
269
|
+
}]
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
new KubeService(chart, 'nginx-service', {
|
|
276
|
+
spec: {
|
|
277
|
+
selector: { app: 'nginx' },
|
|
278
|
+
ports: [{ port: 80, targetPort: 80 }],
|
|
279
|
+
type: 'LoadBalancer'
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
app.synth();
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Development workflow:
|
|
287
|
+
```bash
|
|
288
|
+
# 1. Create cluster
|
|
289
|
+
yarn k3d:create
|
|
290
|
+
|
|
291
|
+
# 2. Synthesize and deploy
|
|
292
|
+
yarn cdk8s:synth
|
|
293
|
+
kubectl apply -f dist/
|
|
294
|
+
|
|
295
|
+
# 3. Access application
|
|
296
|
+
curl http://localhost:8080
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Custom Network Configuration
|
|
300
|
+
|
|
301
|
+
For projects requiring custom networking:
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
new K3d(project, 'k3d', {
|
|
305
|
+
k3d: {
|
|
306
|
+
metadata: { name: 'custom-cluster' },
|
|
307
|
+
network: 'my-custom-network',
|
|
308
|
+
ports: [
|
|
309
|
+
{ port: '3000:80', nodeFilters: ['loadbalancer'] },
|
|
310
|
+
{ port: '3001:8080', nodeFilters: ['loadbalancer'] }
|
|
311
|
+
]
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Prerequisites
|
|
317
|
+
|
|
318
|
+
Before using the K3d component, ensure you have:
|
|
319
|
+
|
|
320
|
+
1. **Docker Desktop** or **Docker Engine** running
|
|
321
|
+
2. **K3d installed** on your system
|
|
322
|
+
3. **kubectl** for cluster interaction
|
|
323
|
+
|
|
324
|
+
### Installation Instructions
|
|
325
|
+
|
|
326
|
+
=== "macOS (Homebrew)"
|
|
327
|
+
```bash
|
|
328
|
+
# Install K3d
|
|
329
|
+
brew install k3d
|
|
330
|
+
|
|
331
|
+
# Install kubectl if not already installed
|
|
332
|
+
brew install kubectl
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
=== "Linux"
|
|
336
|
+
```bash
|
|
337
|
+
# Install K3d
|
|
338
|
+
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
|
|
339
|
+
|
|
340
|
+
# Install kubectl
|
|
341
|
+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
|
342
|
+
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
=== "Windows (Chocolatey)"
|
|
346
|
+
```powershell
|
|
347
|
+
# Install K3d
|
|
348
|
+
choco install k3d
|
|
349
|
+
|
|
350
|
+
# Install kubectl
|
|
351
|
+
choco install kubernetes-cli
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## Common Use Cases
|
|
355
|
+
|
|
356
|
+
### 1. Microservices Development
|
|
357
|
+
|
|
358
|
+
Test multiple services in a local Kubernetes environment:
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
new K3d(project, 'k3d', {
|
|
362
|
+
k3d: {
|
|
363
|
+
metadata: { name: 'microservices-dev' },
|
|
364
|
+
servers: 1,
|
|
365
|
+
agents: 2, // More resources for multiple services
|
|
366
|
+
ports: [
|
|
367
|
+
{ port: '8080:80', nodeFilters: ['loadbalancer'] },
|
|
368
|
+
{ port: '8443:443', nodeFilters: ['loadbalancer'] },
|
|
369
|
+
{ port: '5432:5432', nodeFilters: ['loadbalancer'] } // Database
|
|
370
|
+
]
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### 2. CI/CD Testing
|
|
376
|
+
|
|
377
|
+
Lightweight clusters for automated testing:
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
new K3d(project, 'k3d', {
|
|
381
|
+
k3d: {
|
|
382
|
+
metadata: { name: 'ci-test-cluster' },
|
|
383
|
+
servers: 1,
|
|
384
|
+
agents: 0, // Minimal resource usage
|
|
385
|
+
options: {
|
|
386
|
+
k3s: {
|
|
387
|
+
extraArgs: [
|
|
388
|
+
{ arg: '--disable=traefik', nodeFilters: ['server:*'] },
|
|
389
|
+
{ arg: '--disable=servicelb', nodeFilters: ['server:*'] },
|
|
390
|
+
{ arg: '--disable=metrics-server', nodeFilters: ['server:*'] }
|
|
391
|
+
]
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### 3. Production Simulation
|
|
399
|
+
|
|
400
|
+
Multi-node setup for testing HA configurations:
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
new K3d(project, 'k3d', {
|
|
404
|
+
k3d: {
|
|
405
|
+
metadata: { name: 'prod-simulation' },
|
|
406
|
+
servers: 3, // HA control plane
|
|
407
|
+
agents: 3, // Multiple workers
|
|
408
|
+
network: 'production-net'
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## Troubleshooting
|
|
414
|
+
|
|
415
|
+
### Common Issues
|
|
416
|
+
|
|
417
|
+
1. **Port Already in Use**
|
|
418
|
+
```bash
|
|
419
|
+
# Check what's using port 8080
|
|
420
|
+
lsof -i :8080
|
|
421
|
+
|
|
422
|
+
# Use different port in configuration
|
|
423
|
+
ports: [{ port: '9090:80', nodeFilters: ['loadbalancer'] }]
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
2. **Cluster Won't Start**
|
|
427
|
+
```bash
|
|
428
|
+
# Check Docker is running
|
|
429
|
+
docker ps
|
|
430
|
+
|
|
431
|
+
# View K3d logs
|
|
432
|
+
k3d cluster list
|
|
433
|
+
docker logs k3d-<cluster-name>-server-0
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
3. **Kubectl Context Issues**
|
|
437
|
+
```bash
|
|
438
|
+
# List available contexts
|
|
439
|
+
kubectl config get-contexts
|
|
440
|
+
|
|
441
|
+
# Switch to K3d context
|
|
442
|
+
kubectl config use-context k3d-<cluster-name>
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
## Resources
|
|
446
|
+
|
|
447
|
+
- [K3d Official Documentation](https://k3d.io/)
|
|
448
|
+
- [K3d GitHub Repository](https://github.com/k3d-io/k3d)
|
|
449
|
+
- [K3s Documentation](https://docs.k3s.io/)
|
|
450
|
+
- [Kubernetes Documentation](https://kubernetes.io/docs/)
|
|
451
|
+
- [CDK8s Documentation](https://cdk8s.io/)
|
|
452
|
+
|
|
453
|
+
## Related Components
|
|
454
|
+
|
|
455
|
+
- **[CDK8s Component](cdk8s.md)**: Perfect companion for defining Kubernetes manifests in TypeScript
|
|
456
|
+
- **[Commitzent Component](commitzent.md)**: Conventional commits for your Kubernetes projects
|