go
Copyright © 2024 Patrick Hermann patrick.hermann@sva.de
Installation
dagger install github.com/stuttgart-things/dagger/go@v0.128.0Entrypoint
Return Type
Go !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| goLangContainer | Container | - | golang container It need contain golang |
| koContainer | Container | - | No description provided |
| goLangVersion | String | "1.25.5" | No description provided |
| variant | String | "alpine" | No description provided |
| src | Directory | - | 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 \
srcfunc (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-containerfunc (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-containerfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | No description provided |
| opts | BuildOpts ! | - | 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
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | No description provided |
| goVersion | String | "1.25.5" | No description provided |
| os | String | "linux" | No description provided |
| arch | String | "amd64" | No description provided |
| goMainFile | String | "main.go" | No description provided |
| binName | String | "main" | No description provided |
| ldflags | String | - | No description provided |
| packageName | String | "" | No description provided |
| variant | String | "alpine" | No description provided |
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
build-binary --src DIR_PATHfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| goVersion | String | "1.25.5" | No description provided |
| variant | String | "alpine" | alpine | bookworm | bullseye | “” |
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
get-go-lang-containerfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| koVersion | String | "v0.18.0" | No description provided |
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
get-ko-containerfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| releaserVersion | String | "v2.13.2" | No description provided |
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
get-releaser-containerfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | No description provided |
| govulncheckVersion | String | "v1.7.0" | No description provided |
| format | String | "text" | text | json | sarif | openvex |
| goVersion | String | "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. |
| variant | String | "alpine" | No description provided |
| failOnFinding | Boolean | false | No description provided |
| noCache | Boolean | 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_PATHfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | No description provided |
| tokenName | String | "GITHUB_TOKEN" | No description provided |
| token | Secret | - | No description provided |
| repo | String | "ko.local" | No description provided |
| buildArg | String | "." | No description provided |
| koVersion | String | "v0.18.0" | No description provided |
| push | String | "true" | No description provided |
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
ko-build --src DIR_PATHfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | No description provided |
| timeout | String | "500s" | No description provided |
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
lint --src DIR_PATHfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | Source code directory |
| token | Secret ! | - | GitHub token for authentication |
| releaserVersion | String | "v2.13.2" | No description provided |
| snapshot | Boolean | false | Perform a dry run (snapshot) without publishing |
| skipValidate | Boolean | false | Skip validation checks |
| checkOnly | Boolean | false | Run only goreleaser check without releasing |
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
release --src DIR_PATH --token env:MYSECRETfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | No description provided |
| secureGoVersion | String | "2.24.6" | No description provided |
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
security-scan --src DIR_PATHfunc (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
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | No description provided |
| goVersion | String | "1.24.4" | Go version to use for testing |
| testArg | String | "./..." | Test arguments to pass to |
Example
dagger -m github.com/stuttgart-things/dagger/go@e9949d2da5ffc94d5d703686b418e4ca35a9c95c call \
test --src DIR_PATHfunc (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 moduleFunction GoBuildOpts.goVersion is not accessible from the go moduleFunction GoBuildOpts.goVersion is not accessible from the go moduleFunction GoBuildOpts.goVersion is not accessible from the go moduleos() 🔗
Return Type
String ! Example
Function GoBuildOpts.os is not accessible from the go moduleFunction GoBuildOpts.os is not accessible from the go moduleFunction GoBuildOpts.os is not accessible from the go moduleFunction GoBuildOpts.os is not accessible from the go modulearch() 🔗
Return Type
String ! Example
Function GoBuildOpts.arch is not accessible from the go moduleFunction GoBuildOpts.arch is not accessible from the go moduleFunction GoBuildOpts.arch is not accessible from the go moduleFunction GoBuildOpts.arch is not accessible from the go modulegoMainFile() 🔗
Return Type
String ! Example
Function GoBuildOpts.goMainFile is not accessible from the go moduleFunction GoBuildOpts.goMainFile is not accessible from the go moduleFunction GoBuildOpts.goMainFile is not accessible from the go moduleFunction GoBuildOpts.goMainFile is not accessible from the go modulebinName() 🔗
Return Type
String ! Example
Function GoBuildOpts.binName is not accessible from the go moduleFunction GoBuildOpts.binName is not accessible from the go moduleFunction GoBuildOpts.binName is not accessible from the go moduleFunction GoBuildOpts.binName is not accessible from the go moduleldflags() 🔗
Return Type
String ! Example
Function GoBuildOpts.ldflags is not accessible from the go moduleFunction GoBuildOpts.ldflags is not accessible from the go moduleFunction GoBuildOpts.ldflags is not accessible from the go moduleFunction GoBuildOpts.ldflags is not accessible from the go modulepackageName() 🔗
Return Type
String ! Example
Function GoBuildOpts.packageName is not accessible from the go moduleFunction GoBuildOpts.packageName is not accessible from the go moduleFunction GoBuildOpts.packageName is not accessible from the go moduleFunction GoBuildOpts.packageName is not accessible from the go modulevariant() 🔗
Return Type
String ! Example
Function GoBuildOpts.variant is not accessible from the go moduleFunction GoBuildOpts.variant is not accessible from the go moduleFunction GoBuildOpts.variant is not accessible from the go moduleFunction GoBuildOpts.variant is not accessible from the go module