From fe5496b3ffee2eec3c0b3ef2470935ff955fc019 Mon Sep 17 00:00:00 2001 From: vgjm Date: Thu, 7 Apr 2022 10:15:10 +0800 Subject: [PATCH] feat: support helm Signed-off-by: vgjm --- .../x/vgjm456@qq.com/helm/image.cue | 13 ++++ .../x/vgjm456@qq.com/helm/install.cue | 64 +++++++++++++++++++ .../x/vgjm456@qq.com/helm/test/test.cue | 33 ++++++++++ 3 files changed, 110 insertions(+) create mode 100644 pkg/universe.dagger.io/x/vgjm456@qq.com/helm/image.cue create mode 100644 pkg/universe.dagger.io/x/vgjm456@qq.com/helm/install.cue create mode 100644 pkg/universe.dagger.io/x/vgjm456@qq.com/helm/test/test.cue diff --git a/pkg/universe.dagger.io/x/vgjm456@qq.com/helm/image.cue b/pkg/universe.dagger.io/x/vgjm456@qq.com/helm/image.cue new file mode 100644 index 00000000..ba0a48bf --- /dev/null +++ b/pkg/universe.dagger.io/x/vgjm456@qq.com/helm/image.cue @@ -0,0 +1,13 @@ +package helm + +import ( + "universe.dagger.io/docker" +) + +#Image: { + version: string | *"latest" + + docker.#Pull & { + source: "index.docker.io/alpine/helm:\(version)" + } +} diff --git a/pkg/universe.dagger.io/x/vgjm456@qq.com/helm/install.cue b/pkg/universe.dagger.io/x/vgjm456@qq.com/helm/install.cue new file mode 100644 index 00000000..e2dbac4f --- /dev/null +++ b/pkg/universe.dagger.io/x/vgjm456@qq.com/helm/install.cue @@ -0,0 +1,64 @@ +package helm + +import ( + "dagger.io/dagger" + "universe.dagger.io/docker" +) + +#Install: { + // Name of your release + name: string | *"" + kubeconfig: dagger.#Secret + source: *"repository" | "URL" + { + source: "repository" + chart: string + repoName: string + repository: string + run: { + env: { + CHART: chart + REPO_NAME: repoName + REPOSITORY: repository + } + _script: #""" + helm repo add $REPO_NAME $REPOSITORY + helm repo update + helm install $NAME $REPO_NAME/$CHART $GENERATE_NAME + """# + } + } | { + source: "URL" + URL: string + run: { + env: "URL": URL + _script: #""" + helm install $NAME $URL $GENERATE_NAME + """# + } + } + + _base: #Image + run: docker.#Run & { + input: _base.output + env: { + NAME: name + GENERATE_NAME: _generateName + } + mounts: "/root/.kube/config": { + dest: "/root/.kube/config" + type: "secret" + contents: kubeconfig + } + entrypoint: ["/bin/sh"] + command: { + name: "-c" + args: [run._script] + } + } + + _generateName: string | *"" + if name == "" { + _generateName: "--generate-name" + } +} diff --git a/pkg/universe.dagger.io/x/vgjm456@qq.com/helm/test/test.cue b/pkg/universe.dagger.io/x/vgjm456@qq.com/helm/test/test.cue new file mode 100644 index 00000000..0f861e69 --- /dev/null +++ b/pkg/universe.dagger.io/x/vgjm456@qq.com/helm/test/test.cue @@ -0,0 +1,33 @@ +package helm + +import ( + "dagger.io/dagger" + "universe.dagger.io/x/vgjm456@qq.com/helm" +) + +dagger.#Plan & { + client: { + env: KUBECONFIG: string + commands: kubeconfig: { + name: "cat" + args: ["\(env.KUBECONFIG)"] + stdout: dagger.#Secret + } + } + actions: test: { + URL: helm.#Install & { + name: "test-pgsql" + source: "URL" + URL: "https://charts.bitnami.com/bitnami/postgresql-11.1.12.tgz" + kubeconfig: client.commands.kubeconfig.stdout + } + repository: helm.#Install & { + name: "test-redis" + source: "repository" + chart: "redis" + repoName: "bitnami" + repository: "https://charts.bitnami.com/bitnami" + kubeconfig: client.commands.kubeconfig.stdout + } + } +}