Artifact Export
Just-in-time artifacts such as containers, directories and files expose an Export()
function, enabling them to be exported to the host filesystem from the Dagger Function that produced them. The destination path on the host is passed to the function using the --path
argument.
Here is an example of exporting the directory returned by a Go builder Dagger Function to the ./my-build
directory on the host:
dagger -m github.com/kpenfound/dagger-modules/golang@v0.2.0 call build --source=https://github.com/dagger/dagger --args=./cmd/dagger export --path=./my-build
By default, the Export()
function exports the files that exist in the returned directory to the host, but it does not modify or delete any files that already exist at that host path. To replace the contents of the target host directory, such that it exactly matches the directory being exported, add the --wipe
argument.
Here is an example of exporting the build directory returned by the same Dagger Function above, deleting and replacing files as needed in the ./my-build
directory on the host:
dagger -m github.com/kpenfound/dagger-modules/golang@v0.2.0 call build --source=https://github.com/dagger/dagger --args=./cmd/dagger export --path=./my-build --wipe
Instead of exporting an entire directory, you can also export a file. Here is an example of exporting a single file from the directory returned by the same Go builder Dagger Function, as ./my-binary-file
on the host:
dagger -m github.com/kpenfound/dagger-modules/golang@v0.2.0 call build --source=https://github.com/dagger/dagger --args=./cmd/dagger file --path=dagger export --path=./my-binary-file
Here is another example, this time exporting the results of a ruff
linter Dagger Function as /tmp/report.json
on the host:
dagger call -m github.com/dagger/dagger/dev/ruff@a29dadbb5d9968784847a15fccc5629daf2985ae lint --source https://github.com/dagger/dagger report export --path=/tmp/report.json
Here is an example of exporting a container returned by a Wolfi container builder Dagger Function as an OCI tarball named /tmp/tarball.tar.gz
on the host:
dagger call -m github.com/shykes/daggerverse/wolfi@v0.1.4 container export --path=./tarball.tar.gz