#exporting build outside container

1 messages · Page 1 of 1 (latest)

gritty furnace
#

Hi, im new on dagger !
My question is :
Im on the hello-dagger project
And i want to make the build command to export the build on my host
How can i do this ?

glass creek
gritty furnace
glass creek
#

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
gritty furnace
# glass creek If it returns a `Directory` type, then the same command will work: ```console d...
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

glass creek
#

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
gritty furnace
#

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 .

glass creek
gritty furnace
#

oh or i can -o "an other folder and duplicate"