#[SOLVED] Changes are not reflected on my host machine; well in the container

1 messages · Page 1 of 1 (latest)

hybrid juniper
#

Hi all

I'm trying to reformat my Python codebase using Ruff and after several attempts, here is my current function:

async def __python(self) -> str | None:
    return await (
        dag.container()
        .from_("python:3.13-slim")
        .with_exec(["pip", "install", "ruff"])
        .with_mounted_directory("/app/src", self.source)
        .with_mounted_directory("/app/config", self.config)
        .with_workdir("/app/src")
        .with_exec(
            ["ruff", "format", "--config", "/app/config/pyproject.toml", "."]
        )
        .terminal()
        .stdout()
    )

I've added .terminal() so I can jump in the terminal and do a catof my script and I can confirm that Ruff has well done the reformat job. Nice! but ...

The updated file isn't synchronized with my host.

Still using the terminal (.terminal()), I do a touch TEST_RUFF to create that file and I can see it still in the terminal but that file is not created on my host.

I'm using Docker compose and my yaml file contains this line so, yeah, my current folder is well synchronized with the container.

    volumes: 
      - ./..:/app

By running touch TEST_HOST on my host, I can well see the file in my container. It seems that the container created by dagger isn't synchronized in my case.

Did you know what I'm doing wrong ?

Also: in my .terminal() session, the current user is root (id 0 gid 0) while this is not the one in my Docker container (1000:1000); how can I tell dagger I want to use mine and not root?

Many, many thanks

deft fable
#

Hello 👋

So first, dagger doesn't have volume bind mounts like docker compose does (yet), so that's why you're not seeing your host files get updated. What I'd do in this case is have the function return the directory (the modified self.source). If your function returns a file or directory, you can use the CLI to export it like:
dagger call foo -o ./ where -o is the output path

For the id, there's the with_user function on Container. Maybe user is being set in the compose in your other case?

hybrid juniper
#

Many thanks Kyle ! By chance, did you have some links to documentations or, better, to python examples ?

deft fable
#

of course! Here's that specific thing in the cookbook https://docs.dagger.io/cookbook#export-a-directory-or-file-to-the-host
Lots of other goodies in the cookbook as well!

Something else that might be interesting if you haven't seen it - defaults for directory arguments https://docs.dagger.io/api/arguments#directories-and-files

Filesystem

Dagger Functions, just like regular functions, can accept arguments. In addition to basic types (string, boolean, integer, arrays...), Dagger also defines powerful core types which Dagger Functions can use for their arguments, such as Directory, Container, Service, Secret, and many more.

hybrid juniper
#

For default args, yes, already implemented and it's a very cool feature. Will test tomorrow for the export.

Now, I think, I'm wrong 😋 : the CI should return an alert and, here, Python Black has to be manually fired on the host. It's not the good direction to think that, OK, let's start Dagger CI and keep the changes.

I think Dagger should run Black in a diff mode, and not let the changes happens.

Thank you for the provide links, your time and this discussion.

deft fable
#

Yes I totally agree! We do basically that in dagger's own CI (sorry it's in Go) https://github.com/dagger/dagger/blob/main/.dagger/sdk_python.go#L72

In other places with a similar linter I've seen it implemented where you enable both options. So your black function might have two subcommands like check and fix. check would assert that there's no diff and error if there is a diff, and fix would return the directory that you can export locally

hybrid juniper
#

[SOLVED] Changes are not reflected on my host machine; well in the container