Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: add support/docs for running using Dagger.io #260

Open
senare opened this issue Mar 21, 2024 · 1 comment
Open

request: add support/docs for running using Dagger.io #260

senare opened this issue Mar 21, 2024 · 1 comment

Comments

@senare
Copy link

senare commented Mar 21, 2024

Already have 'go-lang' style integration, would it be possible to create doc's / example for using it with dagger.io ?

REF daggerio i.e. pipeline independent builds ?

@krancour krancour changed the title Add support/docs for running using Dagger.io ? request: add support/docs for running using Dagger.io Mar 21, 2024
@stieglma
Copy link

Integrating with dagger is actually pretty easy, I think. I played around with it today and you can just wrap the kargo-render docker image and directly use it. The kargo-render go library is IMHO not the way to go here, as dagger wants to execute the stuff in a docker image anyway.

As of now there's no module on daggerverse, but you can easily create your own and use it like that. From what I played with, it looks something like this:

// A dagger module for kargo-rendered
package main

import (
	"context"
	"fmt"
)

type DaggerKargo struct{}

// Render plain (json/yaml) manifests for a given repo
// containing either helm or kustomize resources
func (m *DaggerKargo) RenderManifests(
		ctx context.Context,
		// the URL of a remote gitops repo
		repoUrl string,
		// a branch or a precise commit to render from;
		// if this is not provided, Kargo Render renders from the head of the default branch
		// +optional
		baseBranch string,
		// the environment-specific branch to render manifests into
		targetBranch string,
		// username for reading from and writing to the remote gitops repo
		repoUsername string,
		// password for reading from and writing to the remote gitops repo
		repoPassword *Secret,
		// a format for command output (json or yaml)
		// +default="yaml"
		outputFormat string,
		// the version of the kargo-renderer used internally
		// +default="v0.1.0-rc.35"
		kargoRendererVersion string,
) (string, error) {
	plainPassword, err := repoPassword.Plaintext(ctx)
	if err != nil {
		return "", err
	}
	return dag.Container().
		From(fmt.Sprintf("ghcr.io/akuity/kargo-render:%s", kargoRendererVersion)).
		// fix some issues with wrong home variable stuff when it comes to helm templating
		WithEnvVariable("XDG_CONFIG_HOME", "/tmp").
		WithEnvVariable("XDG_CACHE_HOME", "/tmp").
		WithEnvVariable("XDG_DATA_HOME", "/tmp").
		// execute the docker command
		WithExec([]string{
			"kargo-render",
			"render",
			"--repo", repoUrl,
			"--ref", baseBranch,
			"--target-branch", targetBranch,
			"--output", outputFormat,
			"--repo-username", repoUsername,
			"--repo-password", plainPassword,
		}).
		Stdout(ctx)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants