From 80d5a72dda7f455813ddd48aa14f4547cece29a9 Mon Sep 17 00:00:00 2001 From: Christoph Raaflaub Date: Tue, 1 Oct 2024 18:49:14 +0200 Subject: [PATCH] better Version examples --- .github/workflows/test.yml | 4 +- helm/examples/go/dagger.json | 7 +++ helm/examples/go/main.go | 82 +++++++++++++++++++++--------- helm/examples/shell/HelmVersion.sh | 3 ++ 4 files changed, 72 insertions(+), 24 deletions(-) create mode 100644 helm/examples/shell/HelmVersion.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f7ffb79..191d077 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Dagger CLI run: cd /usr/local && { curl -L https://dl.dagger.io/dagger/install.sh | sh; cd -; } - - name: Display module functions + - name: Display Helm module functions run: dagger functions -m helm/ - name: Run module tests run: dagger -m tests/ call all @@ -32,3 +32,5 @@ jobs: --repository ${TEST_HELM_REGISTRY_REPOSITORY} \ --username ${TEST_HELM_REGISTRY_HELM_USER} \ --password env:TEST_HELM_REGISTRY_HELM_PASSWORD + - name: Display go examples module functions + run: dagger -m helm/examples/go/ functions diff --git a/helm/examples/go/dagger.json b/helm/examples/go/dagger.json index afdd13b..7f5c7cb 100644 --- a/helm/examples/go/dagger.json +++ b/helm/examples/go/dagger.json @@ -1,5 +1,12 @@ { "name": "go", "sdk": "go", + "dependencies": [ + { + "name": "helm", + "source": "../.." + } + ], + "source": ".", "engineVersion": "v0.13.3" } diff --git a/helm/examples/go/main.go b/helm/examples/go/main.go index d120107..1aae420 100644 --- a/helm/examples/go/main.go +++ b/helm/examples/go/main.go @@ -1,16 +1,6 @@ -// A generated module for Go functions +// Go examples for the Helm module. // -// This module has been generated via dagger init and serves as a reference to -// basic module structure as you get started with Dagger. -// -// Two functions have been pre-created. You can modify, delete, or add to them, -// as needed. They demonstrate usage of arguments and return types using simple -// echo and grep commands. The functions can be called from the dagger CLI or -// from one of the SDKs. -// -// The first line in this comment block is a short description line and the -// rest is a long description with more detail on the module's purpose or usage, -// if appropriate. All modules should have a short description. +// This module defines the examples for the Daggerverse. package main @@ -21,17 +11,63 @@ import ( type Go struct{} -// Returns a container that echoes whatever string argument is provided -func (m *Go) ContainerEcho(stringArg string) *dagger.Container { - return dag.Container().From("alpine:latest").WithExec([]string{"echo", stringArg}) +func (h *Go) HelmPackagepush( + // method call context + ctx context.Context, + // URL of the registry + registry string, + // name of the repository + repository string, + // registry login username + username string, + // registry login password + password *dagger.Secret, +) error { + // dagger call package-push \ + // --registry registry.puzzle.ch \ + // --repository helm \ + // --username $REGISTRY_HELM_USER \ + // --password env:REGISTRY_HELM_PASSWORD \ + // --directory ./examples/testdata/mychart/ + + // directory that contains the Helm Chart + directory := dag.CurrentModule().Source().Directory("./testdata/mychart/") + _, err := dag.Helm().PackagePush(ctx, directory, registry, repository, username, password) + + if err != nil { + return err + } + + return nil +} + +func (m *Go) HelmTest( + // method call context + ctx context.Context, +) error { + args := []string{"."} + + // dagger call test --directory ./examples/testdata/mychart/ --args "." + directory := dag.CurrentModule().Source().Directory("./testdata/mychart/") + _, err := dag.Helm().Test(ctx, directory, args) + + if err != nil { + return err + } + + return nil } -// Returns lines that match a pattern in the files of the provided Directory -func (m *Go) GrepDir(ctx context.Context, directoryArg *dagger.Directory, pattern string) (string, error) { - return dag.Container(). - From("alpine:latest"). - WithMountedDirectory("/mnt", directoryArg). - WithWorkdir("/mnt"). - WithExec([]string{"grep", "-R", pattern, "."}). - Stdout(ctx) +// Example on how to call the Version method. +// +// Get and display the version of the Helm Chart located inside the directory referenced by the chart parameter. +func (m *Go) HelmVersion( + // method call context + ctx context.Context, + // directory that contains the Helm Chart, e.g. "./tests/testdata/mychart/" + chart *dagger.Directory, +) (string, error) { + return dag. + Helm(). + Version(ctx, chart) } diff --git a/helm/examples/shell/HelmVersion.sh b/helm/examples/shell/HelmVersion.sh new file mode 100644 index 0000000..e1aeca0 --- /dev/null +++ b/helm/examples/shell/HelmVersion.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +dagger call version --directory ./examples/testdata/mychart/