120 lines
3.0 KiB
Markdown
120 lines
3.0 KiB
Markdown
# helm-dagger
|
|
|
|
helm-dagger is a lightweight library that helps users to compile Helm charts
|
|
using custom values files. It simplifies the process of customizing Kubernetes
|
|
deployments for different environments or configurations. This library uses a
|
|
custom delimiter in the values files to avoid conflicts with Helm's default
|
|
delimiter.
|
|
|
|
## Features
|
|
|
|
- Customizable delimiters for the values files
|
|
- Lightweight and easy to integrate into your projects
|
|
- Allows using Helm charts with custom values files programmatically
|
|
|
|
## Dependencies
|
|
|
|
This library requires Docker to be installed.
|
|
|
|
## Usage
|
|
|
|
### 1. Import Helm-Dagger
|
|
|
|
Import the helm-dagger library into your project:
|
|
|
|
```bash
|
|
go get git.front.kjuulh.io/kjuulh/helm-dagger
|
|
```
|
|
|
|
```go
|
|
import (
|
|
"context"
|
|
helmdagger "git.front.kjuulh.io/kjuulh/helm-dagger"
|
|
)
|
|
```
|
|
|
|
### 2. Prepare your chart and values files
|
|
|
|
Store your chart and values files in a known directory. In this example, the
|
|
chart files are stored in the "test_data/nginx" directory, and the custom values
|
|
file is stored in the "test_data/nginx.values.yaml" file.
|
|
|
|
### 3. Call the Compile function
|
|
|
|
The Compile function is the main function to generate an output directory with
|
|
the customized chart. It accepts the following parameters:
|
|
|
|
- `ctx`: a context.Context instance
|
|
- `client`: a dagger.Client instance
|
|
- `chartPath`: the path to the chart directory
|
|
- `valuesFilePath`: the path to the custom values file
|
|
|
|
```go
|
|
helmOutput, err := helmdagger.Compile(ctx, client, "test_data/nginx", "test_data/nginx.values.yaml")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
```
|
|
|
|
### 4. Export the customized chart
|
|
|
|
To export the customized chart, call the `Export` method on the returned
|
|
helmOutput:
|
|
|
|
```go
|
|
exported, err := helmOutput.Export(ctx, "test_data/dist")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
if exported {
|
|
log.Println("Helm chart successfully exported to test_data/dist")
|
|
} else {
|
|
log.Fatal("Failed to export Helm chart")
|
|
}
|
|
```
|
|
|
|
### 5. Verify the chart
|
|
|
|
Check the output directory to see the compiled Helm chart:
|
|
|
|
```go
|
|
dir, err := os.ReadDir("test_data/dist/nginx/templates")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
log.Printf("Found %d templates in the output directory", len(dir))
|
|
```
|
|
|
|
## Example
|
|
|
|
An example of using helm-dagger to compile a Helm chart with a custom values
|
|
file can be found in the test file:
|
|
|
|
```go
|
|
package helmdagger_test
|
|
|
|
import (
|
|
(...) // Import statements
|
|
|
|
func TestHelmDagger(t *testing.T) {
|
|
(...) // Test setup
|
|
|
|
helmoutput, err := daggerhelm.Compile(ctx, client, "test/test_data/nginx", "test/test_data/nginx.values.yaml")
|
|
assert.NoError(t, err)
|
|
|
|
exported, err := helmoutput.Export(ctx, "test/test_data/dist")
|
|
assert.NoError(t, err)
|
|
assert.True(t, exported)
|
|
|
|
dir, err := os.ReadDir("test/test_data/dist/nginx/templates")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, 2, len(dir))
|
|
}
|
|
```
|
|
|
|
Now you can use Helm-Dagger to compile Helm charts with custom values files
|
|
programmatically, making it easier to manage different configurations for your
|
|
Kubernetes deployments.
|