Dagger
Search

go

A module to develop, build, test Go softwares

Installation

dagger install github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d

Entrypoint

Return Type
Go !
Arguments
NameTypeDefault ValueDescription
sourceDirectory -Project source directory
versionString "1.26"Go version
moduleCacheCacheVolume -Use a custom module cache
buildCacheCacheVolume -Use a custom build cache
baseContainer -Use a custom base container. The container must have Go installed.
ldflags[String ! ] -Pass arguments to 'go build -ldflags'
tags[String ! ] -Pass arguments to 'go build -tags'
values[String ! ] -Add string value definition of the form importpath.name=value Example: "github.com/my/module.Foo=bar"
cgoBoolean -Enable CGO
raceBoolean -Enable race detector. Implies cgo=true
experiment[String ! ] -Enable go experiments https://pkg.go.dev/internal/goexperiment
extraPackages[String ! ] -extra system packages to include in the default base image; only valid if 'base' arg is nil
limitInteger !3max number of parallel jobs to run for tidy/check tidy/lint
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer
func (m *MyModule) Example(limit int) *dagger.Go  {
	return dag.
			Go(limit)
}
@function
def example(limit: int) -> dagger.Go:
	return (
		dag.go(limit)
	)
@func()
example(limit: number): Go {
	return dag
		.go(limit)
}

Types

Go 🔗

A Go project

version() 🔗

Go version

Return Type
String !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer version
func (m *MyModule) Example(ctx context.Context, limit int) string  {
	return dag.
			Go(limit).
			Version(ctx)
}
@function
async def example(limit: int) -> str:
	return await (
		dag.go(limit)
		.version()
	)
@func()
async example(limit: number): Promise<string> {
	return dag
		.go(limit)
		.version()
}

source() 🔗

Project source directory

Return Type
Directory !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer source
func (m *MyModule) Example(limit int) *dagger.Directory  {
	return dag.
			Go(limit).
			Source()
}
@function
def example(limit: int) -> dagger.Directory:
	return (
		dag.go(limit)
		.source()
	)
@func()
example(limit: number): Directory {
	return dag
		.go(limit)
		.source()
}

moduleCache() 🔗

Go module cache

Return Type
CacheVolume !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer module-cache
func (m *MyModule) Example(limit int) *dagger.CacheVolume  {
	return dag.
			Go(limit).
			ModuleCache()
}
@function
def example(limit: int) -> dagger.CacheVolume:
	return (
		dag.go(limit)
		.module_cache()
	)
@func()
example(limit: number): CacheVolume {
	return dag
		.go(limit)
		.moduleCache()
}

buildCache() 🔗

Go build cache

Return Type
CacheVolume !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer build-cache
func (m *MyModule) Example(limit int) *dagger.CacheVolume  {
	return dag.
			Go(limit).
			BuildCache()
}
@function
def example(limit: int) -> dagger.CacheVolume:
	return (
		dag.go(limit)
		.build_cache()
	)
@func()
example(limit: number): CacheVolume {
	return dag
		.go(limit)
		.buildCache()
}

base() 🔗

Base container from which to run all operations

Return Type
Container !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer base
func (m *MyModule) Example(limit int) *dagger.Container  {
	return dag.
			Go(limit).
			Base()
}
@function
def example(limit: int) -> dagger.Container:
	return (
		dag.go(limit)
		.base()
	)
@func()
example(limit: number): Container {
	return dag
		.go(limit)
		.base()
}

ldflags() 🔗

Pass arguments to ‘go build -ldflags’

Return Type
[String ! ] !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer ldflags
func (m *MyModule) Example(ctx context.Context, limit int) []string  {
	return dag.
			Go(limit).
			Ldflags(ctx)
}
@function
async def example(limit: int) -> List[str]:
	return await (
		dag.go(limit)
		.ldflags()
	)
@func()
async example(limit: number): Promise<string[]> {
	return dag
		.go(limit)
		.ldflags()
}

tags() 🔗

Pass arguments to ‘go build -tags’

Return Type
[String ! ] !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer tags
func (m *MyModule) Example(ctx context.Context, limit int) []string  {
	return dag.
			Go(limit).
			Tags(ctx)
}
@function
async def example(limit: int) -> List[str]:
	return await (
		dag.go(limit)
		.tags()
	)
@func()
async example(limit: number): Promise<string[]> {
	return dag
		.go(limit)
		.tags()
}

values() 🔗

Add string value definition of the form importpath.name=value

Return Type
[String ! ] !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer values
func (m *MyModule) Example(ctx context.Context, limit int) []string  {
	return dag.
			Go(limit).
			Values(ctx)
}
@function
async def example(limit: int) -> List[str]:
	return await (
		dag.go(limit)
		.values()
	)
@func()
async example(limit: number): Promise<string[]> {
	return dag
		.go(limit)
		.values()
}

cgo() 🔗

Enable CGO

Return Type
Boolean !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer cgo
func (m *MyModule) Example(ctx context.Context, limit int) bool  {
	return dag.
			Go(limit).
			Cgo(ctx)
}
@function
async def example(limit: int) -> bool:
	return await (
		dag.go(limit)
		.cgo()
	)
@func()
async example(limit: number): Promise<boolean> {
	return dag
		.go(limit)
		.cgo()
}

race() 🔗

Enable race detector

Return Type
Boolean !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer race
func (m *MyModule) Example(ctx context.Context, limit int) bool  {
	return dag.
			Go(limit).
			Race(ctx)
}
@function
async def example(limit: int) -> bool:
	return await (
		dag.go(limit)
		.race()
	)
@func()
async example(limit: number): Promise<boolean> {
	return dag
		.go(limit)
		.race()
}

experiment() 🔗

Enable go experiments

Return Type
[String ! ] !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer experiment
func (m *MyModule) Example(ctx context.Context, limit int) []string  {
	return dag.
			Go(limit).
			Experiment(ctx)
}
@function
async def example(limit: int) -> List[str]:
	return await (
		dag.go(limit)
		.experiment()
	)
@func()
async example(limit: number): Promise<string[]> {
	return dag
		.go(limit)
		.experiment()
}

include() 🔗

Return Type
[String ! ] !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer include
func (m *MyModule) Example(ctx context.Context, limit int) []string  {
	return dag.
			Go(limit).
			Include(ctx)
}
@function
async def example(limit: int) -> List[str]:
	return await (
		dag.go(limit)
		.include()
	)
@func()
async example(limit: number): Promise<string[]> {
	return dag
		.go(limit)
		.include()
}

exclude() 🔗

Return Type
[String ! ] !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer exclude
func (m *MyModule) Example(ctx context.Context, limit int) []string  {
	return dag.
			Go(limit).
			Exclude(ctx)
}
@function
async def example(limit: int) -> List[str]:
	return await (
		dag.go(limit)
		.exclude()
	)
@func()
async example(limit: number): Promise<string[]> {
	return dag
		.go(limit)
		.exclude()
}

limit() 🔗

Max number of parallel jobs to run

Return Type
Integer !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer limit
func (m *MyModule) Example(ctx context.Context, limit int) int  {
	return dag.
			Go(limit).
			Limit(ctx)
}
@function
async def example(limit: int) -> int:
	return await (
		dag.go(limit)
		.limit()
	)
@func()
async example(limit: number): Promise<number> {
	return dag
		.go(limit)
		.limit()
}

binary() 🔗

Build a single main package, and return the compiled binary

Return Type
File !
Arguments
NameTypeDefault ValueDescription
pkgString !-Which package to build
noSymbolsBoolean -Disable symbol table
noDwarfBoolean -Disable DWARF generation
platformScalar -Target build platform
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer binary --pkg string
func (m *MyModule) Example(limit int, pkg string) *dagger.File  {
	return dag.
			Go(limit).
			Binary(pkg)
}
@function
def example(limit: int, pkg: str) -> dagger.File:
	return (
		dag.go(limit)
		.binary(pkg)
	)
@func()
example(limit: number, pkg: string): File {
	return dag
		.go(limit)
		.binary(pkg)
}

build() 🔗

Build the given main packages, and return the build directory

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
pkgs[String ! ] ["./..."]Which targets to build (default all main packages)
noSymbolsBoolean -Disable symbol table
noDwarfBoolean -Disable DWARF generation
platformScalar -Target build platform
outputString "./bin/"Output directory
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer build
func (m *MyModule) Example(limit int) *dagger.Directory  {
	return dag.
			Go(limit).
			Build()
}
@function
def example(limit: int) -> dagger.Directory:
	return (
		dag.go(limit)
		.build()
	)
@func()
example(limit: number): Directory {
	return dag
		.go(limit)
		.build()
}

checkTidy() 🔗

Check if ‘go mod tidy’ is up-to-date

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
include[String ! ] -No description provided
exclude[String ! ] -No description provided
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer check-tidy
func (m *MyModule) Example(ctx context.Context, limit int)   {
	return dag.
			Go(limit).
			CheckTidy(ctx)
}
@function
async def example(limit: int) -> None:
	return await (
		dag.go(limit)
		.check_tidy()
	)
@func()
async example(limit: number): Promise<void> {
	return dag
		.go(limit)
		.checkTidy()
}

download() 🔗

Download dependencies into the module cache

Return Type
Go !
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer download
func (m *MyModule) Example(limit int) *dagger.Go  {
	return dag.
			Go(limit).
			Download()
}
@function
def example(limit: int) -> dagger.Go:
	return (
		dag.go(limit)
		.download()
	)
@func()
example(limit: number): Go {
	return dag
		.go(limit)
		.download()
}

env() 🔗

Prepare a build environment for the given Go source code: - Build a base container with Go tooling installed and configured - Apply configuration - Mount the source code

Return Type
Container !
Arguments
NameTypeDefault ValueDescription
platformScalar -No description provided
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer env
func (m *MyModule) Example(limit int) *dagger.Container  {
	return dag.
			Go(limit).
			Env()
}
@function
def example(limit: int) -> dagger.Container:
	return (
		dag.go(limit)
		.env()
	)
@func()
example(limit: number): Container {
	return dag
		.go(limit)
		.env()
}

generateDaggerRuntime() 🔗

Return Type
Go !
Arguments
NameTypeDefault ValueDescription
startString !-No description provided
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer generate-dagger-runtime --start string
func (m *MyModule) Example(limit int, start string) *dagger.Go  {
	return dag.
			Go(limit).
			GenerateDaggerRuntime(start)
}
@function
def example(limit: int, start: str) -> dagger.Go:
	return (
		dag.go(limit)
		.generate_dagger_runtime(start)
	)
@func()
example(limit: number, start: string): Go {
	return dag
		.go(limit)
		.generateDaggerRuntime(start)
}

lint() 🔗

Lint the project

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
include[String ! ] -No description provided
exclude[String ! ] -No description provided
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer lint
func (m *MyModule) Example(ctx context.Context, limit int)   {
	return dag.
			Go(limit).
			Lint(ctx)
}
@function
async def example(limit: int) -> None:
	return await (
		dag.go(limit)
		.lint()
	)
@func()
async example(limit: number): Promise<void> {
	return dag
		.go(limit)
		.lint()
}

lintModule() 🔗

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
moduleString !-No description provided
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer lint-module --module string
func (m *MyModule) Example(ctx context.Context, limit int, module string)   {
	return dag.
			Go(limit).
			LintModule(ctx, module)
}
@function
async def example(limit: int, module: str) -> None:
	return await (
		dag.go(limit)
		.lint_module(module)
	)
@func()
async example(limit: number, module: string): Promise<void> {
	return dag
		.go(limit)
		.lintModule(module)
}

listPackages() 🔗

List packages matching the specified criteria

Return Type
[String ! ] !
Arguments
NameTypeDefault ValueDescription
pkgs[String ! ] ["./..."]Filter by name or pattern. Example './foo/...'
onlyMainBoolean -Only list main packages
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer list-packages
func (m *MyModule) Example(ctx context.Context, limit int) []string  {
	return dag.
			Go(limit).
			ListPackages(ctx)
}
@function
async def example(limit: int) -> List[str]:
	return await (
		dag.go(limit)
		.list_packages()
	)
@func()
async example(limit: number): Promise<string[]> {
	return dag
		.go(limit)
		.listPackages()
}

modules() 🔗

Scan the source for go modules, and return their paths

Return Type
[String ! ] !
Arguments
NameTypeDefault ValueDescription
include[String ! ] -No description provided
exclude[String ! ] -No description provided
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer modules
func (m *MyModule) Example(ctx context.Context, limit int) []string  {
	return dag.
			Go(limit).
			Modules(ctx)
}
@function
async def example(limit: int) -> List[str]:
	return await (
		dag.go(limit)
		.modules()
	)
@func()
async example(limit: number): Promise<string[]> {
	return dag
		.go(limit)
		.modules()
}

test() 🔗

Run tests for the given packages

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
runString -Only run these tests
skipString -Skip these tests
failfastBoolean -Abort test run on first failure
parallelInteger 0How many tests to run in parallel - defaults to the number of CPUs
timeoutString "30m"How long before timing out the test run
countInteger 1No description provided
pkgs[String ! ] ["./..."]Which packages to test
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer test
func (m *MyModule) Example(ctx context.Context, limit int)   {
	return dag.
			Go(limit).
			Test(ctx)
}
@function
async def example(limit: int) -> None:
	return await (
		dag.go(limit)
		.test()
	)
@func()
async example(limit: number): Promise<void> {
	return dag
		.go(limit)
		.test()
}

tests() 🔗

List tests

Return Type
String !
Arguments
NameTypeDefault ValueDescription
pkgs[String ! ] ["./..."]Packages to list tests from (default all packages)
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer tests
func (m *MyModule) Example(ctx context.Context, limit int) string  {
	return dag.
			Go(limit).
			Tests(ctx)
}
@function
async def example(limit: int) -> str:
	return await (
		dag.go(limit)
		.tests()
	)
@func()
async example(limit: number): Promise<string> {
	return dag
		.go(limit)
		.tests()
}

tidy() 🔗

Return Type
Changeset !
Arguments
NameTypeDefault ValueDescription
include[String ! ] -No description provided
exclude[String ! ] -No description provided
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer tidy
func (m *MyModule) Example(limit int) *dagger.Changeset  {
	return dag.
			Go(limit).
			Tidy()
}
@function
def example(limit: int) -> dagger.Changeset:
	return (
		dag.go(limit)
		.tidy()
	)
@func()
example(limit: number): Changeset {
	return dag
		.go(limit)
		.tidy()
}

tidyModule() 🔗

Return Type
Changeset !
Arguments
NameTypeDefault ValueDescription
moduleString !-No description provided
Example
dagger -m github.com/grouville/dagger/toolchains/go@d918ab25b5808d7f461e4b0a9860b428db17bf5d call \
 --limit integer tidy-module --module string
func (m *MyModule) Example(limit int, module string) *dagger.Changeset  {
	return dag.
			Go(limit).
			TidyModule(module)
}
@function
def example(limit: int, module: str) -> dagger.Changeset:
	return (
		dag.go(limit)
		.tidy_module(module)
	)
@func()
example(limit: number, module: string): Changeset {
	return dag
		.go(limit)
		.tidyModule(module)
}