#exporting build outside container
1 messages · Page 1 of 1 (latest)
- To export the container image to an archive on your local filesystem: you can use
-oto save the result of the pipeline: for exampledagger call my-build -o ./my-image.oci - To export to a local docker engine: https://archive.docs.dagger.io/0.9/252029/load-images-local-docker-engine
My aim is not to export the docker image !
But the dist folder 
Oh sorry! -o also works for directories. What type does your build function return?
If it returns a Directory type, then the same command will work:
dagger call my-build -o ./my-dist
package main
type HelloDagger struct{}
// Build the application container
func (m *HelloDagger) Build(source *Directory) *Container {
// get the build environment container
// by calling another Dagger Function
build := m.BuildEnv(source).
// build the application
WithExec([]string{"npm", "run", "build"}).
// get the build output directory
Directory("./dist")
// start from a slim NGINX container
return dag.Container().From("nginx:1.25-alpine").
// copy the build output directory to the container
WithDirectory("/usr/share/nginx/html", build).
// expose the container port
WithExposedPort(80)
}
i use the basic function that the doc give
I see, this is a function that builds a container, but in your case you're not interested in the container, you want to get the dist directory out of that continaer?
You can split the build function in two parts:
package main
type HelloDagger struct{}
// Build the JS application
func (m *HelloDagger) BuildDist(source *Directory) *Directory {
// get the build environment container
// by calling another Dagger Function
return m.BuildEnv(source).
// build the application
WithExec([]string{"npm", "run", "build"}).
// get the build output directory
Directory("./dist")
}
// Build the application container
func (m *HelloDagger) BuildContainer(source *Directory) *Container {
build := m.BuildDist(source)
// start from a slim NGINX container
return dag.Container().From("nginx:1.25-alpine").
// copy the build output directory to the container
WithDirectory("/usr/share/nginx/html", build).
// expose the container port
WithExposedPort(80)
}
Then you can call one or the other from the CLI.
To get the dist directory:
dagger call build-dist --source=. -o ./dist
yay ! it work ! :)
thanks !!
do you have the link to the doc for this ?
and imagine i need to build some php with composer
how do i return all the project dir ? (cause it change multiples files in the project)
func (m *HelloDagger) BuildDist(source *Directory) *Directory {
// get the build environment container
// by calling another Dagger Function
return m.BuildEnv(source).
// build the application
WithExec([]string{"my composer command"}).
// get the build output directory
Directory(".")
}
with the command
dagger call build-dist --source=. -o .
Yes that's the idea, you can compose any directory you want. You can even copy different parts of different directories, to return a dynamic directory
yeah it will replace files if they are differents and do nothing if they are =
oh or i can -o "an other folder and duplicate"