Skip to content

Commit 124b090

Browse files
authored
Merge pull request #129 from deploystackio/feat/helm
feat: help kubernetes
2 parents fd3218c + a3c9fec commit 124b090

9 files changed

Lines changed: 336 additions & 2 deletions

File tree

docs/deploystack/docker-compose-requirements.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,24 @@ The infrastructure templates we generate require specific, immutable container i
5555

5656
We currently support these Docker Compose properties -> please check [Supported Docker Compose Variables](/docs/docker-to-iac/supported-docker-compose-variables.md).
5757

58+
### Kubernetes/Helm
59+
60+
When generating Helm charts for Kubernetes:
61+
62+
- Database services (MySQL, PostgreSQL, Redis, etc.) are converted to Bitnami Helm chart dependencies
63+
- Environment variables are split between ConfigMaps (regular variables) and Secrets (sensitive data)
64+
- Each service in your Docker Compose becomes a separate Deployment and Service
65+
- Volume mounts are supported and configured as needed
66+
67+
This allows for better security practices and easier management of your application on Kubernetes.
68+
5869
## Multiple Services Support
5970

6071
DeployStack can handle Docker Compose files with multiple services, but support varies by cloud provider:
6172

6273
- Some providers support deploying all services at once
6374
- Others will only deploy the first service in your compose file
75+
- Kubernetes (Helm) supports multi-service deployments with each service becoming a separate Deployment
6476

6577
Check the specific [Multi Services Support](/docs/docker-to-iac/multi-services-support.md) for details about multi-service support.
6678

docs/deploystack/one-click-deploy.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ We create a dedicated branch for each project to support one-click deployment fu
4040
We integrate with cloud providers' native deployment systems. For example:
4141

4242
- **DigitalOcean**: Uses the "Deploy to DigitalOcean" functionality as documented in their [official guide](https://docs.digitalocean.com/products/app-platform/how-to/add-deploy-do-button/)
43+
- **Kubernetes**: Generates Helm charts that can be deployed to any Kubernetes cluster
4344
- Check [supported cloud providers](/docs/docker-to-iac/index.md) for full list
4445

4546
### Provider-Specific Templates
@@ -50,6 +51,7 @@ Each cloud provider may require specific template formats:
5051
- DigitalOcean App Spec
5152
- Render Blueprints
5253
- And more based on provider requirements
54+
- Kubernetes Helm charts with all necessary templates
5355

5456
## Using Deploy Buttons
5557

docs/docker-to-iac/api.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ console.log(parsers);
4949
diskSizeGB: 10
5050
}
5151
},
52+
{
53+
providerWebsite: 'https://www.digitalocean.com/',
54+
providerName: 'DigitalOcean',
55+
providerNameAbbreviation: 'DO',
56+
languageOfficialDocs: 'https://docs.digitalocean.com/products/app-platform/',
57+
languageAbbreviation: 'DOP',
58+
languageName: 'DigitalOcean App Spec',
59+
defaultParserConfig: { files: [Array], region: 'nyc', subscriptionName: 'basic-xxs' }
60+
},
61+
{
62+
providerWebsite: 'https://helm.sh/',
63+
providerName: 'Kubernetes',
64+
providerNameAbbreviation: 'K8S',
65+
languageOfficialDocs: 'https://helm.sh/docs/',
66+
languageAbbreviation: 'HELM',
67+
languageName: 'Helm Chart',
68+
defaultParserConfig: {
69+
files: [Array],
70+
cpu: '100m',
71+
memory: '128Mi'
72+
}
73+
},
5274
{
5375
providerWebsite: 'https://www.digitalocean.com/',
5476
providerName: 'DigitalOcean',
@@ -217,6 +239,67 @@ Object.entries(result.files).forEach(([path, fileData]) => {
217239
});
218240
```
219241

242+
#### Translating Docker Compose to Helm Chart
243+
244+
```javascript
245+
import { translate } from '@deploystack/docker-to-iac';
246+
import { writeFileSync, mkdirSync, existsSync } from 'fs';
247+
import { join, dirname } from 'path';
248+
249+
const dockerComposeContent = `
250+
version: '3'
251+
services:
252+
web:
253+
image: nginx:latest
254+
ports:
255+
- "80:80"
256+
db:
257+
image: postgres:13
258+
environment:
259+
POSTGRES_USER: myuser
260+
POSTGRES_PASSWORD: mypassword
261+
POSTGRES_DB: myapp
262+
`;
263+
264+
const result = translate(dockerComposeContent, {
265+
source: 'compose',
266+
target: 'HELM',
267+
templateFormat: 'yaml'
268+
});
269+
270+
// Access and save all generated files to create a complete Helm Chart
271+
Object.entries(result.files).forEach(([path, fileData]) => {
272+
const fullPath = join('helm-chart', path);
273+
const dir = dirname(fullPath);
274+
275+
if (!existsSync(dir)) {
276+
mkdirSync(dir, { recursive: true });
277+
}
278+
279+
writeFileSync(fullPath, fileData.content);
280+
console.log(`Created: ${path}`);
281+
});
282+
```
283+
284+
#### Example Output (Partial - Chart.yaml)
285+
286+
```yaml
287+
apiVersion: v2
288+
name: deploystack-app
289+
description: A Helm chart for DeployStack application generated from Docker configuration
290+
type: application
291+
version: 0.1.0
292+
appVersion: 1.0.0
293+
maintainers:
294+
- name: DeployStack
295+
email: hello@deploystack.io
296+
dependencies:
297+
- name: db
298+
repository: https://charts.bitnami.com/bitnami
299+
version: ^12.0.0
300+
condition: dependencies.db.enabled
301+
```
302+
220303
#### Configuring Service Connections
221304
222305
```javascript
@@ -435,6 +518,7 @@ This option is currently supported by:
435518

436519
- Render.com (RND): Uses Blueprint's `fromService` syntax
437520
- DigitalOcean App Platform (DOP): Uses direct service names
521+
- Kubernetes Helm Charts (HELM): Uses Kubernetes DNS service discovery
438522

439523
Example:
440524

docs/docker-to-iac/multi-file-configuration.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ mychart/
5656
└── _helpers.tpl # Template helpers
5757
```
5858

59+
The docker-to-iac module now includes a Helm parser that generates this exact structure when translating Docker configurations to Helm Charts:
60+
61+
```javascript
62+
const result = translate(dockerComposeContent, {
63+
source: 'compose',
64+
target: 'HELM',
65+
templateFormat: 'yaml'
66+
});
67+
68+
// Result contains all files needed for a complete Helm Chart
69+
console.log(Object.keys(result.files));
70+
// [
71+
// 'Chart.yaml',
72+
// 'values.yaml',
73+
// 'templates/deployment.yaml',
74+
// 'templates/service.yaml',
75+
// 'templates/configmap.yaml',
76+
// 'templates/secret.yaml',
77+
// 'templates/NOTES.txt',
78+
// 'templates/_helpers.tpl'
79+
// ]
80+
```
81+
5982
With the multi-file support, a Helm Chart parser configuration might look like:
6083

6184
```typescript

docs/docker-to-iac/parser/helm.md

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
---
2+
description: Translate Docker Compose files into Kubernetes Helm Charts with DeployStack docker-to-iac module
3+
menuTitle: Helm
4+
---
5+
6+
# Helm - Parser Full Documentation
7+
8+
The parser for Helm translates Docker configurations into Kubernetes Helm Charts. The parser logic can be found in GitHub inside the [docker-to-iac repo](https://github.com/deploystackio/docker-to-iac/blob/main/src/parsers/helm.ts).
9+
10+
## Parser language abbreviation for API
11+
12+
- `languageAbbreviation`: `HELM`.
13+
14+
## Prerequisite to deploy Helm Charts
15+
16+
To deploy the generated Helm Charts, you need:
17+
18+
- A Kubernetes cluster (local or cloud-based)
19+
- Helm CLI installed (version 3.x recommended)
20+
- Appropriate RBAC permissions to deploy resources in your target namespace
21+
22+
### Kubernetes Resources
23+
24+
The generated Helm Chart creates the following Kubernetes resources for each service in your Docker configuration:
25+
26+
- **Deployments**: Container specifications, replica count, resource limits
27+
- **Services**: Network access to your pods with appropriate ports
28+
- **ConfigMaps**: Non-sensitive environment variables
29+
- **Secrets**: Sensitive environment variables (passwords, tokens, etc.)
30+
31+
### Database Support
32+
33+
For database services, the parser leverages Helm's dependency management to incorporate official Bitnami charts:
34+
35+
- **MySQL/MariaDB**: Uses Bitnami's MySQL/MariaDB chart
36+
- **PostgreSQL**: Uses Bitnami's PostgreSQL chart
37+
- **Redis**: Uses Bitnami's Redis chart
38+
- **MongoDB**: Uses Bitnami's MongoDB chart
39+
40+
Each database dependency is configured with appropriate defaults and includes persistent storage for data.
41+
42+
## Default output format
43+
44+
- The default output format for this parser: `YAML`.
45+
46+
## File Configuration
47+
48+
The Helm parser generates a complete Helm Chart directory structure:
49+
50+
- `Chart.yaml` - The main chart definition with metadata and dependencies
51+
- `values.yaml` - Configuration values that can be customized at deployment time
52+
- `templates/` - Directory containing Kubernetes YAML templates:
53+
- `deployment.yaml` - Deployment specifications for each service
54+
- `service.yaml` - Service definitions for network access
55+
- `configmap.yaml` - ConfigMap for non-sensitive environment variables
56+
- `secret.yaml` - Secret for sensitive environment variables
57+
- `_helpers.tpl` - Helper functions for template generation
58+
- `NOTES.txt` - Usage instructions displayed after installation
59+
60+
This multi-file approach follows the standard Helm Chart structure and allows for maximum flexibility when deploying to Kubernetes.
61+
62+
## Supported Docker Compose Variables
63+
64+
This parser supports the following Docker Compose variables:
65+
66+
- `image`
67+
- `environment`
68+
- `ports`
69+
- `command`
70+
- `volumes`
71+
72+
::content-alert{type="note"}
73+
The parser automatically detects sensitive environment variables (containing keywords like "password", "secret", "key", "token", or "auth") and places them in Kubernetes Secrets instead of ConfigMaps.
74+
::
75+
76+
## Volume Support
77+
78+
The parser supports Docker volume mappings by converting them to Kubernetes volume mounts:
79+
80+
- Each volume is converted to a hostPath volume by default
81+
- Volume names are sanitized to conform to Kubernetes naming conventions
82+
- For production use, you should modify the generated templates to use more appropriate volume types (PersistentVolumeClaims, etc.)
83+
84+
## Database Integration
85+
86+
When a database service is detected (MySQL, PostgreSQL, Redis, MongoDB), the parser:
87+
88+
1. Adds the corresponding Bitnami Helm chart as a dependency in `Chart.yaml`
89+
2. Configures database settings in `values.yaml`
90+
3. Maps environment variables to the expected format for the database chart
91+
4. Sets up appropriate persistence configurations
92+
93+
### Example Database Configuration
94+
95+
For a PostgreSQL database in your Docker Compose file:
96+
97+
```yaml
98+
services:
99+
db:
100+
image: postgres:13
101+
environment:
102+
POSTGRES_USER: myuser
103+
POSTGRES_PASSWORD: mypassword
104+
POSTGRES_DB: myapp
105+
```
106+
107+
The parser will create:
108+
109+
```yaml
110+
# In Chart.yaml
111+
dependencies:
112+
- name: db
113+
repository: https://charts.bitnami.com/bitnami
114+
version: ^12.0.0
115+
condition: dependencies.db.enabled
116+
117+
# In values.yaml
118+
dependencies:
119+
db:
120+
enabled: true
121+
auth:
122+
postgres:
123+
password: mypassword
124+
database: myapp
125+
username: myuser
126+
password: mypassword
127+
primary:
128+
service:
129+
ports:
130+
postgresql: 5432
131+
persistence:
132+
enabled: true
133+
size: 8Gi
134+
```
135+
136+
## Service Connections
137+
138+
The parser supports service-to-service connections by leveraging Kubernetes DNS for service discovery. When a service refers to another service in an environment variable, the parser automatically configures the appropriate DNS references.
139+
140+
For example, if your `app` service connects to a `db` service:
141+
142+
```yaml
143+
# Docker Compose
144+
services:
145+
app:
146+
image: myapp
147+
environment:
148+
DATABASE_URL: postgresql://postgres:password@db:5432/mydb
149+
150+
db:
151+
image: postgres
152+
environment:
153+
POSTGRES_PASSWORD: password
154+
POSTGRES_DB: mydb
155+
```
156+
157+
The parser will create:
158+
159+
```yaml
160+
# In ConfigMap template
161+
data:
162+
DATABASE_URL: {{ include "deploystack.serviceReference" (dict "service" (index $.Values.services "db") "serviceKey" "db") }}
163+
```
164+
165+
Which resolves to the Kubernetes DNS name: `db.{{ .Release.Namespace }}.svc.cluster.local:5432`
166+
167+
## Multi Services Support
168+
169+
Multi `services` support for Helm: **yes**
170+
171+
Helm Charts are designed to handle multiple services and dependencies in a single deployment, making them ideal for complex applications. The parser transforms all services from your Docker Compose file into corresponding Kubernetes resources.
172+
173+
Please read more about [multi service support here](/docs/docker-to-iac/multi-services-support.md).
174+
175+
## Deployment Instructions
176+
177+
To deploy the generated Helm Chart:
178+
179+
1. Navigate to the directory containing the generated chart
180+
2. Install dependencies:
181+
182+
```bash
183+
helm dependency update
184+
```
185+
186+
3. Install the chart:
187+
188+
```bash
189+
helm install my-release .
190+
```
191+
192+
4. For custom configurations:
193+
194+
```bash
195+
helm install my-release . --set services.app.replicaCount=2
196+
```
197+
198+
## Production Considerations
199+
200+
For production deployments, consider the following modifications to the generated chart:
201+
202+
1. Replace hostPath volumes with appropriate persistent volume claims
203+
2. Adjust resource limits in `values.yaml`
204+
3. Configure proper ingress settings for external access
205+
4. Enable and configure horizontal pod autoscaling
206+
5. Set up proper liveness and readiness probes
207+
208+
::content-alert{type="important"}
209+
The generated Helm Chart is a starting point that you should review and customize to match your production requirements and security best practices.
210+
::

docs/docker-to-iac/parser/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Here you can find the list of available [parsers](/docs/docker-to-iac/parser-exp
1010
- [AWS CloudFormation](/docs/docker-to-iac/parser/aws-cloudformation.md)
1111
- [Render.com](/docs/docker-to-iac/parser/render.com.md)
1212
- [DigitalOcean](/docs/docker-to-iac/parser/digitalocean.md)
13+
- [Helm (Kubernetes)](/docs/docker-to-iac/parser/helm.md)

0 commit comments

Comments
 (0)