#How to use a local docker image that is not pushed into a registry. go sdk

1 messages ยท Page 1 of 1 (latest)

mellow sonnet
#

I am trying to setup some ci jobs using the go sdk, I want to build a local docker image for when working with the jobs locally so I can have all the go modules cached. Reasons for this:

  • my local go mod cache is massive so using mounting it takes forever
  • my internet is horribly slow so every time I want to run the job it takes forever to download the image
  • my internet is horribly slow so pushing up the built cache image to a registry takes forever and then takes forever to download

My code currently looks like:

    client, err := dagger.Connect(ctx)
    if err != nil {
        return err
    }
    defer client.Close()
    client.Container()

    src := client.Host().Directory(".")
    container := client.Container().
        From("golang:1.21").
        WithDirectory("/src", src).
        WithWorkdir("/src")

But I would like to instead use a container from image go_cache:latest that only exists on my local. It always seems to want to pull from a registry and I so far have not found a way to configure it to allow this. I hope I am just overlooking something simple in the documentation.

sick mango
#

๐Ÿ‘‹ the most straightforward to do this currently is to do a docker save of your image, sending it to your pipeline and then use client.Container().Import() to actually load it

mellow sonnet
#

Just want to make sure I am doing this correctly. I ran:
docker save -o local_ci_cache local_ci_cache:latest
To save off the image as a tar
I have updated my code to look like:

func GetGolangContainer(client *dagger.Client, golangVersion string) (*dagger.Container, error) {
    src := client.Host().Directory(".")
    container := client.Container()

    // if we want to use a local cache to speed up tests use a prebuilt tar file
    if len(os.Getenv("USE_LOCAL_CACHE")) > 0 {
        cacheFile := client.Host().File("./local_ci_cache")
        container = container.Import(cacheFile)
    } else {
        container = container.From(golangVersion)
    }
    container = container.WithDirectory("/src", src).
        WithWorkdir("/src")

    return container, nil
}

This works but is still very slow. It takes over 15 minutes to transfer the file via Import to then run 2 minutes worth of tests. So still not a viable option yet unless I am doing something wrong.

sick mango
#

how big is the file?

#

can you see in your dagger output that the upload takes effectively 15m?

sick mango
mellow sonnet
#

I am working with my smaller image that is 3GB. It also takes just as long on subsequent runs sadly. I am on:

$dagger version
dagger v0.9.6 (registry.dagger.io/engine) darwin/amd64

I don't know how to tell how long each part took specifically but by the time it got through this it had been 15 minutes:

dagger run go run ci/main.go
โ”ฃโ”€โ•ฎ 
โ”‚ โ–ฝ init
โ”‚ โ–ˆ [3.28s] connect
โ”‚ โ”ฃ [0.50s] starting engine
โ”‚ โ”ฃ [0.83s] starting session
โ”‚ โ”ƒ OK!                                                                                                                                    
โ”‚ โ”ป 
โ”ฃโ”€โ•ฎ 
โ”‚ โ–ฝ host.directory .
โ”‚ โ–ˆ [6m28.4s] upload . from MB-T (client id: b9f3hmae89s0qrcrpp6w9sav6)
โ”‚ โ”ฃ [6m28.3s] transferring .:
โ”ฃโ”€โ”ผโ”€โ•ฎ 
โ”‚ โ”‚ โ–ฝ host.file .
โ”‚ โ”‚ โ–ˆ [6m13.5s] upload . from MB-T (client id: b9f3hmae89s0qrcrpp6w9sav6) (include: local_ci_cache)
โ”‚ โ”‚ โ”ฃ [6m13.5s] transferring .:
โ”‚ โ”‚ โ–ˆ [0.00s] blob://sha256:c77a42e077b9f7804c1403638d3af1675f2a90d6e1935d9a9de54f78f3a47654
โ”‚ โ”‚ โ”ป 
โ”‚ โ–ˆ [0.00s] blob://sha256:050512fe471595b96575ad6e2d885cfff786145cf5ecb9c4d2dd331213bc220b
โ”‚ โ”ฃโ”€โ•ฎ blob://sha256:050512fe471595b96575ad6e2d885cfff786145cf5ecb9c4d2dd331213bc220b
โ”‚ โ”ป โ”‚ 
โ–ˆ   โ”‚ [0.00s] oci-layout://dagger/import@sha256:b55a8acf15af459248f2c2f116d41d9f9564ace164cc44a0f6be184a0e0eaf88
โ”ฃ   โ”‚ [0.20s] resolve dagger/import@sha256:b55a8acf15af459248f2c2f116d41d9f9564ace164cc44a0f6be184a0e0eaf88
โ–ˆโ—€โ”€โ”€โ•ฏ [0.22s] rm /local_ci_cache
โ–ˆ [10.65s] copy / /src
sick mango
#

weird.. it took 6m to upload a 3gb file from your machine to the engine?

#

what systme are you currently running on? Mac, Linux?

#

took 15s on my linux machine:

7: transferring .: 
7: transferring .: 2.93GiB [14.2s]
7: upload . from xps (client id: nzo1w9z2mh5o5mnpbnc4vid5w) (include: bar) DONE

8: blob://sha256:2534ceee1d0b74d456ad7c529df544a2ed76230d2a9c440253be74f8d8f6f5e5 DONE
8: > in host.file .
8: blob://sha256:2534ceee1d0b74d456ad7c529df544a2ed76230d2a9c440253be74f8d8f6f5e5 DONE

8: blob://sha256:2534ceee1d0b74d456ad7c529df544a2ed76230d2a9c440253be74f8d8f6f5e5 CACHED
8: > in host.file .
8: blob://sha256:2534ceee1d0b74d456ad7c529df544a2ed76230d2a9c440253be74f8d8f6f5e5 CACHED

12: resolve image config for docker.io/library/alpine:latest
12: > in from alpine
12: resolve image config for docker.io/library/alpine:latest DONE

18: pull docker.io/library/alpine:latest
18: > in from alpine
18: resolve docker.io/library/alpine@sha256:51b67269f354137895d43f3b3d810bfacd3945438e94dc5ac55fdac340352f48 
18: resolve docker.io/library/alpine@sha256:51b67269f354137895d43f3b3d810bfacd3945438e94dc5ac55fdac340352f48 [0.01s]
18: pull docker.io/library/alpine:latest DONE

18: pull docker.io/library/alpine:latest CACHED
18: > in from alpine
18: pull docker.io/library/alpine:latest CACHED

16: exec ls -la /tmp/
16: [0.10s] total 3072012
16: [0.10s] drwxrwxrwt    1 root     root          4096 Jan 17 19:35 .
16: [0.10s] drwxr-xr-x    1 root     root          4096 Jan 17 19:35 ..
16: [0.10s] -rw-rw-r--    1 root     root     3145728000 Jan 17 19:33 image
16: exec ls -la /tmp/ DONE
mellow sonnet
#

2019 intel Macbook pro macos 14.2.1

sick mango
#

having said that, it surprises me a bit that even if I re-run the pipeline, the transferring... step seems to be taking quite some time very call even though Dagger shows the blob as cached afterwards. cc @dusty chasm @quiet fulcrum ?

7: transferring .: 2.93GiB [14.7s]
7: upload . from xps (client id: petpqbuusux6m6ke132aqpaxs) (include: bar) DONE

8: blob://sha256:2534ceee1d0b74d456ad7c529df544a2ed76230d2a9c440253be74f8d8f6f5e5 DONE
8: > in host.file .
8: blob://sha256:2534ceee1d0b74d456ad7c529df544a2ed76230d2a9c440253be74f8d8f6f5e5 DONE

8: blob://sha256:2534ceee1d0b74d456ad7c529df544a2ed76230d2a9c440253be74f8d8f6f5e5 CACHED
8: > in host.file .
8: blob://sha256:2534ceee1d0b74d456ad7c529df544a2ed76230d2a9c440253be74f8d8f6f5e5 CACHED

blob shows as CACHED, but transferring takes 14s every time

sick mango
mellow sonnet
#

Oh nice, was hoping it was just user error on my part. I can jump into audio whenever

#

Although thinking this through it doesn't seem like it solves my issue because the image just contains all the tools and go mod cached to be able to run the tests and such. I then want to reuse that image for several different repositories to run tests so I would need to upload the image and the source.

sick mango
#

we did the registry dancing thing and we managed to get unblocked.