diff --git a/Dockerfile b/Dockerfile index 92f6427..0711f99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN apk add --update --no-cache ca-certificates tzdata bash SHELL ["/bin/bash", "-c"] -# This is so we can reuse examples in development +# This is so we can reuse presets in development WORKDIR /etc/benthos COPY cloudevents.spec.json /etc/benthos/ diff --git a/ci/build.go b/ci/build.go index f4e9609..38d9509 100644 --- a/ci/build.go +++ b/ci/build.go @@ -1,7 +1,6 @@ package main import ( - "path/filepath" "strings" "time" ) @@ -91,7 +90,7 @@ func (m *Build) binary(platform Platform, version Optional[string]) *File { } func (m *Build) HelmChart(version Optional[string]) *File { - chart := m.helmChartDir() + chart := helmChartDir(m.Source) var opts HelmPackageOpts @@ -103,15 +102,13 @@ func (m *Build) HelmChart(version Optional[string]) *File { return dag.Helm(HelmOpts{Version: helmVersion}).Package(chart, opts) } -func (m *Build) helmChartDir() *Directory { - chart := dag.Host().Directory(filepath.Join(root(), "deploy/charts/benthos-openmeter"), HostDirectoryOpts{ - Exclude: []string{"charts"}, // exclude dependencies - }) +func helmChartDir(source *Directory) *Directory { + chart := source.Directory("deploy/charts/benthos-openmeter") readme := dag.HelmDocs(HelmDocsOpts{Version: helmDocsVersion}).Generate(chart, HelmDocsGenerateOpts{ Templates: []*File{ - dag.Host().File(filepath.Join(root(), "deploy/charts/template.md")), - dag.Host().File(filepath.Join(root(), "deploy/charts/benthos-openmeter/README.tmpl.md")), + source.File("deploy/charts/template.md"), + source.File("deploy/charts/benthos-openmeter/README.tmpl.md"), }, SortValuesOrder: "file", }) diff --git a/ci/lint.go b/ci/lint.go new file mode 100644 index 0000000..30d1985 --- /dev/null +++ b/ci/lint.go @@ -0,0 +1,57 @@ +package main + +import ( + "context" + + "golang.org/x/sync/errgroup" +) + +// Run various linters against the source code. +func (m *Ci) Lint() *Lint { + return &Lint{ + Source: m.Source, + } +} + +type Lint struct { + // +private + Source *Directory +} + +func (m *Lint) All(ctx context.Context) error { + var group errgroup.Group + + group.Go(func() error { + _, err := m.Go().Sync(ctx) + if err != nil { + return err + } + + return nil + }) + + group.Go(func() error { + _, err := m.Helm().Sync(ctx) + if err != nil { + return err + } + + return nil + }) + + return group.Wait() +} + +func (m *Lint) Go() *Container { + return dag.GolangciLint(GolangciLintOpts{ + Version: golangciLintVersion, + GoVersion: goVersion, + }). + Run(m.Source, GolangciLintRunOpts{ + Verbose: true, + }) +} + +func (m *Lint) Helm() *Container { + return dag.Helm(HelmOpts{Version: helmVersion}).Lint(helmChartDir(m.Source)) +} diff --git a/ci/main.go b/ci/main.go index fc55377..3170dda 100644 --- a/ci/main.go +++ b/ci/main.go @@ -72,9 +72,7 @@ func (m *Ci) Ci(ctx context.Context) error { }) group.Go(func() error { - _, err := m.Lint().Sync(ctx) - - return err + return m.Lint().All(ctx) }) // TODO: run trivy scan on container(s?) @@ -110,16 +108,6 @@ func (m *Ci) Test() *Container { Exec([]string{"go", "test", "-v", "./..."}) } -func (m *Ci) Lint() *Container { - return dag.GolangciLint(GolangciLintOpts{ - Version: golangciLintVersion, - GoVersion: goVersion, - }). - Run(m.Source, GolangciLintRunOpts{ - Verbose: true, - }) -} - // Build and publish a snapshot of all artifacts from the current development version. func (m *Ci) Snapshot(ctx context.Context) error { // TODO: capture branch name and push it as tag/version diff --git a/ci/utils.go b/ci/utils.go index 340f7d8..d1e6bd6 100644 --- a/ci/utils.go +++ b/ci/utils.go @@ -19,6 +19,7 @@ var excludes = []string{ ".direnv", ".devenv", "ci", + "deploy/charts/**/charts", } func exclude(paths ...string) []string { diff --git a/deploy/charts/benthos-openmeter/README.md b/deploy/charts/benthos-openmeter/README.md index 3a65775..c566858 100644 --- a/deploy/charts/benthos-openmeter/README.md +++ b/deploy/charts/benthos-openmeter/README.md @@ -27,9 +27,9 @@ helm install --generate-name --wait oci://ghcr.io/openmeterio/helm-charts/bentho | image.tag | string | `""` | Image tag override for the default value (chart appVersion). | | openmeter.url | string | `"https://openmeter.cloud"` | OpenMeter API URL | | openmeter.token | string | `""` | OpenMeter token | -| config | object | `{}` | Benthos configuration Takes precedence over `useExistingConfigFile` and `useExample`. | -| useExistingConfigFile | string | `""` | Use an existing config file mounted via `volumes` and `volumeMounts`. Takes precedence over `useExample`. | -| useExample | string | `""` | Use one of the predefined examples. Note: Read the documentation for the specific example to learn about configuration via env vars. | +| config | object | `{}` | Benthos configuration Takes precedence over `configFile` and `preset`. | +| configFile | string | `""` | Use an existing config file mounted via `volumes` and `volumeMounts`. Takes precedence over `preset`. | +| preset | string | `""` | Use one of the predefined presets. Note: Read the documentation for the specific preset (example) to learn about configuration via env vars. | | imagePullSecrets | list | `[]` | Reference to one or more secrets to be used when [pulling images](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret) (from private registries). | | nameOverride | string | `""` | A name in place of the chart name for `app:` labels. | | fullnameOverride | string | `""` | A name to substitute for the full names of resources. | diff --git a/deploy/charts/benthos-openmeter/templates/_helpers.tpl b/deploy/charts/benthos-openmeter/templates/_helpers.tpl index 358ab5a..287f5e9 100644 --- a/deploy/charts/benthos-openmeter/templates/_helpers.tpl +++ b/deploy/charts/benthos-openmeter/templates/_helpers.tpl @@ -80,17 +80,17 @@ Create args for the deployment {{- define "benthos-openmeter.args" -}} {{- if .Values.config -}} ["benthos", "-c", "/etc/benthos/config.yaml"] -{{- else if .Values.useExistingConfigFile -}} -["benthos", "-c", "{{ .Values.useExistingConfigFile }}"] -{{- else if .Values.useExample }} -{{- if eq .Values.useExample "http-server" -}} +{{- else if .Values.configFile -}} +["benthos", "-c", "{{ .Values.configFile }}"] +{{- else if .Values.preset }} +{{- if eq .Values.preset "http-server" -}} ["benthos", "streams", "--no-api", "/etc/benthos/examples/http-server/input.yaml", "/etc/benthos/examples/http-server/output.yaml"] -{{- else if eq .Values.useExample "kubernetes-pod-exec-time" -}} +{{- else if eq .Values.preset "kubernetes-pod-exec-time" -}} ["benthos", "-c", "/etc/benthos/examples/kubernetes-pod-exec-time/config.yaml"] {{- else }} -{{- fail (printf "Invalid example '%s" .Values.useExample) }} +{{- fail (printf "Invalid example '%s" .Values.preset) }} {{- end }} {{- else }} -{{- fail "One of 'config', 'useExistingConfigFile' or 'useExample' is required" }} +{{- fail "One of 'config', 'configFile' or 'preset' is required" }} {{- end }} {{- end }} diff --git a/deploy/charts/benthos-openmeter/values.yaml b/deploy/charts/benthos-openmeter/values.yaml index 369c84b..67e57eb 100644 --- a/deploy/charts/benthos-openmeter/values.yaml +++ b/deploy/charts/benthos-openmeter/values.yaml @@ -20,16 +20,16 @@ openmeter: token: "" # -- Benthos configuration -# Takes precedence over `useExistingConfigFile` and `useExample`. +# Takes precedence over `configFile` and `preset`. config: {} # -- Use an existing config file mounted via `volumes` and `volumeMounts`. -# Takes precedence over `useExample`. -useExistingConfigFile: "" +# Takes precedence over `preset`. +configFile: "" -# -- Use one of the predefined examples. -# Note: Read the documentation for the specific example to learn about configuration via env vars. -useExample: "" +# -- Use one of the predefined presets. +# Note: Read the documentation for the specific preset (example) to learn about configuration via env vars. +preset: "" # -- Reference to one or more secrets to be used when [pulling images](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret) (from private registries). imagePullSecrets: [] diff --git a/examples/kubernetes-pod-exec-time/README.md b/examples/kubernetes-pod-exec-time/README.md index 8f9a7a9..9a09999 100644 --- a/examples/kubernetes-pod-exec-time/README.md +++ b/examples/kubernetes-pod-exec-time/README.md @@ -43,7 +43,7 @@ kubectl apply -f seed/pod.yaml Deploy Benthos to your cluster: ```shell -helm install --wait --namespace benthos --create-namespace --set useExample=kubernetes-pod-exec-time --set openmeter.url= --set openmeter.token= benthos-openmeter oci://ghcr.io/openmeterio/helm-charts/benthos-openmeter +helm install --wait --namespace benthos --create-namespace --set preset=kubernetes-pod-exec-time --set openmeter.url= --set openmeter.token= benthos-openmeter oci://ghcr.io/openmeterio/helm-charts/benthos-openmeter ``` > [!NOTE]