#[SOLVED] Just Copy files and directories without providing the flag

1 messages · Page 1 of 1 (latest)

hollow spoke
#

Sorry if this has been answered somewhere, but I can't seem to find it and can't make much sense of it. Also probably quite noobish question or maybe i'm "holding it the wrong way"

But all I want to do, similar to a Dockerfile is to copy a file or a directory which has a well known, and is not supposed to change I don't want to have to provide the flag as described in the docs at: https://docs.dagger.io/cookbook/#copy-a-local-or-remote-file-to-a-container or the --source=. flags.

What I want to achieve is to do something as simple as this:

func (m *MyProject) Build() *dagger.Container {
    return dag.Container().From("python/3.12.2-alpine").
        WithWorkdir("/app").
        WithDirectory("/src", "/src" ).
        WithFile("./foo.txt", "foo.txt").
        WithEnvVariable("TESTING", "false").
        WithEnvVariable("AURORA_VIDEO_SOURCE").
        WithExposedPort("8000").
        WithExec([]string{"pip", "install", "-r", "requirements.txt"}).
        WithEntrypoint([]string{"python", "./src/detector.py"})
}

My experience with go is still rather limited, And I still can't wrap my head around the *dagger.File and *dagger.Directory requirements in the WithDirecotory() and WithFile() functions.

Thanks a lot for your time!

Filesystem

#

Just Copy files and directories without providing the flag

queen trellis
#

Hi

If I correctly understand, you want to be able to run dagger call your_function and to not be forced to specify a flag like --source your_source_folder.

If so, did you've see this info :https://docs.dagger.io/api/default-paths

You should well specify a flag but, using thanks the DefaultPath argument, you can omit it during your call. I think this is the way to go for your use case.

It is possible to assign a default path for a Directory or File argument in a Dagger Function. Dagger will automatically use this default path when no value is specified for the argument. The Directory or File loaded in this manner is not merely a string, but the actual filesystem state of the directory or file.

hollow spoke
#

Makes some more sense .. but still can't understand how do I specify a particular file to be copied into the image? if the WithFile or WithDirectory functions require a a *dagger.File and a *dagger.Directory ? similar to the code snipet I added.

queen trellis
#

Search for withMountedDirectory and withMountedFile https://docs.dagger.io/api/types/#container examples.

On my own, I'm using Python SDK, I'm using a dagger.Directory as CLI variable and thus using something like this:

ctr = (
   await ctr.with_mounted_directory(
       "/app/src", source_directory
   )
   # [...]   

source_directory is thus my dagger.Directory variable.

In addition to basic types (string, boolean, integer, arrays...), the Dagger API also provides powerful core types which serve as both arguments and return values for Dagger Functions.

hollow spoke
#

either i'm really holding it wrong or i still can't understand it. Both those functions still require a *dagger.File or *dagger.Directory type to be passed as arguments for the source file, and that's exactly my problem.

That doesn't really solve the particular problem, of "I just want to tell dagger to copy foo.txt into the resulting container image" somewhat like the snippet, on the original post)

Perhaps a better question is ... how can I create a var of *dagger.File that points to the foo.txt file? 🤔 not sure ... quite cofused by this bit ...

hollow spoke
#

Think I found what I wanted:

func (m *AuroraDetector) Build(
    // +defaultPath="." 
    source *dagger.Directory,
) (*dagger.Container) {
    return dag.Container().
        From("python:3.12.2").
        WithWorkdir("/app").
        WithDirectory("/src", source).
        WithFile("requirements.txt", source.File("requirements.txt")).
        WithEnvVariable("TESTING", "false").
        WithEnvVariable("AURORA_VIDEO_SOURCE", "").
        WithExposedPort(8000).
        WithExec([]string{"pip", "install", "-r", "requirements.txt"}).
        WithEntrypoint([]string{"python", "./src/detector.py"})
}
hollow spoke
#

[SOLVED] Just Copy files and directories without providing the flag