#[SOLVED] Container Build doesn't work on Windows

1 messages Β· Page 1 of 1 (latest)

zealous mesa
#

Building a container with dockerfile doesn't work on Windows (but works fine on macOS).

// using Dagger Go SDK 0.4.0
buildOpts := dagger.ContainerBuildOpts{
    Dockerfile: "dockerfiles/ubuntu_build_env.Dockerfile",
}
container := client.Container().Build(repoDir, buildOpts)

Generates this output on Windows:

input:1: container.build failed to read dockerfile: open /tmp/buildkit-mount464475346/dockerfiles\ubuntu_build_env.Dockerfile: no such file or directory

Note the lone \ (backslash) in the path.
Thanks.

#

Container Build doesn't work on Windows

digital cypress
#

πŸ‘‹ are you running this using go in windows or through WLS2?

zealous mesa
digital cypress
#

hmmm I'm thinking if the path would need some adjustment for windows . I can see in your logs /dockerfiles\ubuntu_build_env.Dockerfile. That backslash seems a bit weird

digital cypress
#

k, I think I know what the problem is. I'll open an issue

#

@zealous mesa LMK if you'd like to help me do some Dagger windows sunday debugging verification :). Particularly since I don't have a Windows OS

zealous mesa
digital cypress
#

k, building and pushing a test version so you can try

zealous mesa
#

from my experience in Go, there is a behavior difference between the path and path/filepath go packages regarding platform-specific spearators (/, \)

#

but I don't know if it's at the Go level here

digital cypress
#

yes, it's exactly that and given how Dagger works where some things run locally in your windows machine and some others in buildkit which is linux

zealous mesa
#

I took a quick look to the dagger Go SDK code, but could not go really deep into it ...

// Initialize this container from a Dockerfile build
func (r *Container) Build(context *Directory, opts ...ContainerBuildOpts) *Container {
    q := r.q.Select("build")
    q = q.Arg("context", context)
    // `dockerfile` optional argument
    for i := len(opts) - 1; i >= 0; i-- {
        if !querybuilder.IsZeroValue(opts[i].Dockerfile) {
            q = q.Arg("dockerfile", opts[i].Dockerfile)
            break
        }
    }

    return &Container{
        q: q,
        c: r.c,
    }
}

the Build function doesn't look to actually do the build ... I was expecting to see where the dockerfile is read here

digital cypress
#

ok @zealous mesa, let's try the following: Can you do go mod vendor in your windows project?

digital cypress
#

We'll try if you can test the change yourself since the codebase I'm lookng is a bit beyond 0.4.0

zealous mesa
#

understood

#

done

digital cypress
#

k, now locate the file vendor/github.com/dagger/dagger/core/container.go

#

and change lines 246 and 248 to use path.Join instead of filepath.Join

zealous mesa
#

done

digital cypress
#

ok, now try running your Dagger pipeline again please

#

you "might" get an error about path/filepath not being used if your editor didn't remove the import automatically. If that happens, go back to container.go and remove line 10 πŸ™

zealous mesa
#

yes haha, I just had that and fixed it manually

#

thanks πŸ™‚

digital cypress
#

πŸš€

#

🀞

#

did it work? :suspense:

zealous mesa
#

apparently yes ...

#
#1 local://C:\Users\voxowl\projects\cubzh
#1 transferring C:\Users\voxowl\projects\cubzh:
#1 transferring C:\Users\voxowl\projects\cubzh: 284.66kB 0.9s done
#1 DONE 1.0s

#2 copy / /
#2 DONE 0.9s

#3 [internal] load metadata for docker.io/library/ubuntu:22.04
#3 ERROR: failed to do request: Head "https://registry-1.docker.io/v2/library/ubuntu/manifests/22.04": net/http: TLS handshake timeout```
digital cypress
#

πŸš€ awesome! I'll send a PR to fix it

zealous mesa
#

the dockerfile is loaded apparently

digital cypress
#

thx for helping to test. It will be fixed in the next Go SDK release

zealous mesa
#

retrying to see the pipeline end successfully... ⏳

zealous mesa
#

please mention me in the PR (@zealous mesa) so I can be notified of the merge, and update our go.mod with the merge commit. Thanks.

zealous mesa
#

my pipeline ended successfully ✨
we can mark this issue as solved πŸ™‚

digital cypress
zealous mesa
#

Thanks πŸ™Œ