Dagger
Search

go

Copyright © 2024 Patrick Hermann patrick.hermann@sva.de

Installation

dagger install github.com/stuttgart-things/dagger/go@v0.128.0

Entrypoint

Return Type
Go !
Arguments
NameTypeDefault ValueDescription
goLangContainerContainer -golang container It need contain golang
koContainerContainer -No description provided
goLangVersionString "1.25.5"No description provided
variantString "alpine"No description provided
srcDirectory -No description provided
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
func (m *MyModule) Example() *dagger.Go  {
	return dag.
			Go()
}
@function
def example() -> dagger.Go:
	return (
		dag.go()
	)
@func()
example(): Go {
	return dag
		.go()
}

Types

Go 🔗

src() 🔗

Return Type
Directory !
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 src
func (m *MyModule) Example() *dagger.Directory  {
	return dag.
			Go().
			Src()
}
@function
def example() -> dagger.Directory:
	return (
		dag.go()
		.src()
	)
@func()
example(): Directory {
	return dag
		.go()
		.src()
}

goLangContainer() 🔗

Return Type
Container !
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 go-lang-container
func (m *MyModule) Example() *dagger.Container  {
	return dag.
			Go().
			Golangcontainer()
}
@function
def example() -> dagger.Container:
	return (
		dag.go()
		.golangcontainer()
	)
@func()
example(): Container {
	return dag
		.go()
		.goLangContainer()
}

koContainer() 🔗

Return Type
Container !
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 ko-container
func (m *MyModule) Example() *dagger.Container  {
	return dag.
			Go().
			Kocontainer()
}
@function
def example() -> dagger.Container:
	return (
		dag.go()
		.kocontainer()
	)
@func()
example(): Container {
	return dag
		.go()
		.koContainer()
}

build() 🔗

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
srcDirectory !-No description provided
optsBuildOpts !-

Use the struct for parameters

Example
echo 'Custom types are not supported in shell examples'
func (m *MyModule) Example(src *dagger.Directory, opts *dagger.GoBuildOpts) *dagger.Directory  {
	return dag.
			Go().
			Build(src, opts)
}
@function
def example(src: dagger.Directory, opts: dagger.GoBuildOpts) -> dagger.Directory:
	return (
		dag.go()
		.build(src, opts)
	)
@func()
example(src: Directory, opts: GoBuildOpts): Directory {
	return dag
		.go()
		.build(src, opts)
}

buildBinary() 🔗

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
srcDirectory !-No description provided
goVersionString "1.25.5"No description provided
osString "linux"No description provided
archString "amd64"No description provided
goMainFileString "main.go"No description provided
binNameString "main"No description provided
ldflagsString -No description provided
packageNameString ""No description provided
variantString "alpine"No description provided
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 build-binary --src DIR_PATH
func (m *MyModule) Example(src *dagger.Directory) *dagger.Directory  {
	return dag.
			Go().
			Buildbinary(src)
}
@function
def example(src: dagger.Directory) -> dagger.Directory:
	return (
		dag.go()
		.buildbinary(src)
	)
@func()
example(src: Directory): Directory {
	return dag
		.go()
		.buildBinary(src)
}

getGoLangContainer() 🔗

GetGoLangContainer returns the golang build container

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
goVersionString "1.25.5"No description provided
variantString "alpine"

alpine | bookworm | bullseye | “”

Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 get-go-lang-container
func (m *MyModule) Example() *dagger.Container  {
	return dag.
			Go().
			Getgolangcontainer()
}
@function
def example() -> dagger.Container:
	return (
		dag.go()
		.getgolangcontainer()
	)
@func()
example(): Container {
	return dag
		.go()
		.getGoLangContainer()
}

getKoContainer() 🔗

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
koVersionString "v0.18.0"No description provided
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 get-ko-container
func (m *MyModule) Example() *dagger.Container  {
	return dag.
			Go().
			Getkocontainer()
}
@function
def example() -> dagger.Container:
	return (
		dag.go()
		.getkocontainer()
	)
@func()
example(): Container {
	return dag
		.go()
		.getKoContainer()
}

getReleaserContainer() 🔗

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
releaserVersionString "v2.13.2"No description provided
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 get-releaser-container
func (m *MyModule) Example() *dagger.Container  {
	return dag.
			Go().
			Getreleasercontainer()
}
@function
def example() -> dagger.Container:
	return (
		dag.go()
		.getreleasercontainer()
	)
@func()
example(): Container {
	return dag
		.go()
		.getReleaserContainer()
}

govulncheck() 🔗

Govulncheck scans Go source for known vulnerabilities that are reachable from the call graph.

This is not the same question as SecurityScan (gosec: did we write something unsafe) or the trivy module (does this artefact contain a package with a known CVE). govulncheck reads the Go vulnerability database and then does call-graph analysis, so it reports only vulnerabilities on a path the binary can actually reach, and stays quiet about a CVE in a dependency whose affected function is never called. That is what makes it usable as a build gate rather than as noise.

Two behaviours of the tool shape this function.

First, the report is always written, including when vulnerabilities are found. govulncheck exits 3 in that case, and a WithExec that propagated the exit code would leave no file to export – the report would go missing precisely when it is wanted. The exit code is captured separately instead.

Second, that exit code is only meaningful for -format text. With json, sarif and openvex govulncheck exits 0 even when it finds reachable vulnerabilities, on the assumption that the caller parses the output. So when a gate is asked for in one of those formats, a second text-mode pass supplies the verdict; the requested format still produces the report. Both passes run in the same container and share the module cache and the downloaded vulnerability database.

A consequence worth knowing before wiring this into a workflow: with failOnFinding set, this function returns an error, so a dagger call govulncheck ... export --path report.txt never reaches the export. To both keep the report and gate the build, call twice – once to export, once to gate. The second call hits Dagger’s cache and costs nothing.

Return Type
File !
Arguments
NameTypeDefault ValueDescription
srcDirectory !-No description provided
govulncheckVersionString "v1.7.0"No description provided
formatString "text"

text | json | sarif | openvex

goVersionString "1.25.5"

Base toolchain for the scan container. A floor, not a pin: GOTOOLCHAIN is set to auto, so a go.mod requiring something newer wins.

variantString "alpine"No description provided
failOnFindingBoolean falseNo description provided
noCacheBoolean false

Skip Dagger’s result cache. The vulnerability database changes independently of the source, so a cached hit can report a clean tree against a database from weeks ago.

Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 govulncheck --src DIR_PATH
func (m *MyModule) Example(src *dagger.Directory) *dagger.File  {
	return dag.
			Go().
			Govulncheck(src)
}
@function
def example(src: dagger.Directory) -> dagger.File:
	return (
		dag.go()
		.govulncheck(src)
	)
@func()
example(src: Directory): File {
	return dag
		.go()
		.govulncheck(src)
}

koBuild() 🔗

Return Type
String !
Arguments
NameTypeDefault ValueDescription
srcDirectory !-No description provided
tokenNameString "GITHUB_TOKEN"No description provided
tokenSecret -No description provided
repoString "ko.local"No description provided
buildArgString "."No description provided
koVersionString "v0.18.0"No description provided
pushString "true"No description provided
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 ko-build --src DIR_PATH
func (m *MyModule) Example(ctx context.Context, src *dagger.Directory) string  {
	return dag.
			Go().
			Kobuild(ctx, src)
}
@function
async def example(src: dagger.Directory) -> str:
	return await (
		dag.go()
		.kobuild(src)
	)
@func()
async example(src: Directory): Promise<string> {
	return dag
		.go()
		.koBuild(src)
}

lint() 🔗

Lint runs the linter on the provided source code

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
srcDirectory !-No description provided
timeoutString "500s"No description provided
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 lint --src DIR_PATH
func (m *MyModule) Example(src *dagger.Directory) *dagger.Container  {
	return dag.
			Go().
			Lint(src)
}
@function
def example(src: dagger.Directory) -> dagger.Container:
	return (
		dag.go()
		.lint(src)
	)
@func()
example(src: Directory): Container {
	return dag
		.go()
		.lint(src)
}

release() 🔗

Return Type
File !
Arguments
NameTypeDefault ValueDescription
srcDirectory !-

Source code directory

tokenSecret !-

GitHub token for authentication

releaserVersionString "v2.13.2"No description provided
snapshotBoolean false

Perform a dry run (snapshot) without publishing

skipValidateBoolean false

Skip validation checks

checkOnlyBoolean false

Run only goreleaser check without releasing

Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 release --src DIR_PATH --token env:MYSECRET
func (m *MyModule) Example(src *dagger.Directory, token *dagger.Secret) *dagger.File  {
	return dag.
			Go().
			Release(src, token)
}
@function
def example(src: dagger.Directory, token: dagger.Secret) -> dagger.File:
	return (
		dag.go()
		.release(src, token)
	)
@func()
example(src: Directory, token: Secret): File {
	return dag
		.go()
		.release(src, token)
}

securityScan() 🔗

Return Type
File !
Arguments
NameTypeDefault ValueDescription
srcDirectory !-No description provided
secureGoVersionString "2.24.6"No description provided
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 security-scan --src DIR_PATH
func (m *MyModule) Example(src *dagger.Directory) *dagger.File  {
	return dag.
			Go().
			Securityscan(src)
}
@function
def example(src: dagger.Directory) -> dagger.File:
	return (
		dag.go()
		.securityscan(src)
	)
@func()
example(src: Directory): File {
	return dag
		.go()
		.securityScan(src)
}

test() 🔗

Return Type
String !
Arguments
NameTypeDefault ValueDescription
srcDirectory !-No description provided
goVersionString "1.24.4"

Go version to use for testing

testArgString "./..."

Test arguments to pass to go test

Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
 test --src DIR_PATH
func (m *MyModule) Example(ctx context.Context, src *dagger.Directory) string  {
	return dag.
			Go().
			Test(ctx, src)
}
@function
async def example(src: dagger.Directory) -> str:
	return await (
		dag.go()
		.test(src)
	)
@func()
async example(src: Directory): Promise<string> {
	return dag
		.go()
		.test(src)
}

BuildOpts 🔗

goVersion() 🔗

Return Type
String !
Example
Function GoBuildOpts.goVersion is not accessible from the go module
Function GoBuildOpts.goVersion is not accessible from the go module
Function GoBuildOpts.goVersion is not accessible from the go module
Function GoBuildOpts.goVersion is not accessible from the go module

os() 🔗

Return Type
String !
Example
Function GoBuildOpts.os is not accessible from the go module
Function GoBuildOpts.os is not accessible from the go module
Function GoBuildOpts.os is not accessible from the go module
Function GoBuildOpts.os is not accessible from the go module

arch() 🔗

Return Type
String !
Example
Function GoBuildOpts.arch is not accessible from the go module
Function GoBuildOpts.arch is not accessible from the go module
Function GoBuildOpts.arch is not accessible from the go module
Function GoBuildOpts.arch is not accessible from the go module

goMainFile() 🔗

Return Type
String !
Example
Function GoBuildOpts.goMainFile is not accessible from the go module
Function GoBuildOpts.goMainFile is not accessible from the go module
Function GoBuildOpts.goMainFile is not accessible from the go module
Function GoBuildOpts.goMainFile is not accessible from the go module

binName() 🔗

Return Type
String !
Example
Function GoBuildOpts.binName is not accessible from the go module
Function GoBuildOpts.binName is not accessible from the go module
Function GoBuildOpts.binName is not accessible from the go module
Function GoBuildOpts.binName is not accessible from the go module

ldflags() 🔗

Return Type
String !
Example
Function GoBuildOpts.ldflags is not accessible from the go module
Function GoBuildOpts.ldflags is not accessible from the go module
Function GoBuildOpts.ldflags is not accessible from the go module
Function GoBuildOpts.ldflags is not accessible from the go module

packageName() 🔗

Return Type
String !
Example
Function GoBuildOpts.packageName is not accessible from the go module
Function GoBuildOpts.packageName is not accessible from the go module
Function GoBuildOpts.packageName is not accessible from the go module
Function GoBuildOpts.packageName is not accessible from the go module

variant() 🔗

Return Type
String !
Example
Function GoBuildOpts.variant is not accessible from the go module
Function GoBuildOpts.variant is not accessible from the go module
Function GoBuildOpts.variant is not accessible from the go module
Function GoBuildOpts.variant is not accessible from the go module