#Why doesn't excluding my rust target directory work? To to exclude my rust target directory?

1 messages · Page 1 of 1 (latest)

limpid ridge
#

Hi, I am trying out Dagger for the first time. I have the following script which runs my library tests just fine:

import { connect } from "@dagger.io/dagger"

// Initialize Dagger client
connect(async (client) => {
    // Use a rust container with the latest stable version to test the library
    const libSource = client.container().from("rust:latest")
        .withDirectory("/lib", client.host().directory("lib"), { exclude: ["target/**"] })

    // Set the corking directory of the container to the lib directory
    // run cargo test
    const libOutput = await libSource.withWorkdir("/lib").withExec(["cargo", "test"]).stdout()

    // print output
    console.log(libOutput)
}, { LogOutput: process.stdout })

However whenever I run this I see a lot of data being copied

4: transferring /home/rolf/dev/pacosako/lib: 1.857GiB

Which I am quite sure is mostly the lib/target directory that I am trying to exclude. I have also tried excluding "target" or "target/" to no avail.

How do I properly exclude the target directory from being copied into my container?

primal ether
waxen arch
primal ether
#

Notice the removed ) after "lib".

waxen arch
limpid ridge
#

Thanks @primal ether! This works now and I am getting:

transferring /home/rolf/dev/pacosako/lib: 30.33MiB

#

What does the thing I have written even mean though? What am I excluding target from?

primal ether
#

Host().directory() reads a directory from your host computer into dagger. So by using exclude here, you're excluding it from being sent to the dagger runner.

limpid ridge
#

"Retrieves this directory plus a directory written at the given path." -> I guess this means we are actually combining two directories here and the "outer" filter only applies to the stuff that is already on the container.

primal ether
#

Yes, let's say you have a monorepo. You can get everything you need from Host, then further split from there to test component A and component B.