# See file
ls
go.mod go.sum main.go
# Start buildkit daemon
docker run --net=host -d --restart always -v dagger-buildkitd:/var/lib/buildkit --name dagger-buildkitd --privileged moby/buildkit:v0.9.3
d0368480d7f2ee03d55ffae5474eeee7a8c7a44453fa978f90825137d9ca1261
# Override host value
export BUILDKIT_HOST=docker-container://dagger-buildkitd
# Run main.go
time go run ./main.go
WARN[0000] local cache import at store not found due to err: could not read store/index.json: open store/index.json: no such file or directory
go run ./main.go 0.81s user 1.09s system 18% cpu 10.214 total
# List file to see store appear
ls
go.mod go.sum main.go result store
# Check result
cat result/test
test%
# Check cache
l store/
total 8
drwxr-xr-x 3 tomchauveau staff 96B Feb 4 15:34 blobs
-rw-r--r-- 1 tomchauveau staff 244B Feb 4 15:34 index.json
drwxr-xr-x 2 tomchauveau staff 64B Feb 4 15:34 ingest
# Check blob
l store/blobs/sha256
total 1648
-r--r--r-- 1 tomchauveau staff 571B Feb 4 15:34 1c294434ba7679ee1f7c9e32c29880b3ad5981058cb54884b4cdc1de37d30e31
-r--r--r-- 1 tomchauveau staff 894B Feb 4 15:34 2a086a3ea822a281c45bc43fecc343ef5ffe721fd58f972ed46a0dcc6c810833
-r--r--r-- 1 tomchauveau staff 150B Feb 4 15:34 82789c089c26861754a6fd11f46dcd053aefe99abbf093d9d10f1a1ec1877b68
-r--r--r-- 1 tomchauveau staff 809K Feb 4 15:34 a01966dde7f8d5ba10b6d87e776c7c8fb5a5f6bfa678874bd28b33b1fc6dba34
# Rerun to verify that ephemeral cache works
time go run ./main.go
go run ./main.go 0.76s user 1.21s system 85% cpu 2.318 total
# Remove container && volume
docker container stop dagger-buildkitd && docker container rm dagger-buildkitd && docker volume rm dagger-buildkitd
dagger-buildkitd
dagger-buildkitd
dagger-buildkitd
# Restart container
docker run --net=host -d --restart always -v dagger-buildkitd:/var/lib/buildkit --name dagger-buildkitd --privileged moby/buildkit:v0.9.3
c7352ffec6d3fecbbcfa802d3ac8cb3ecd977125c84fadb328d89b3f584e9fbc
# Verify that cache is stll there
l store/blobs/sha256
total 1648
-r--r--r-- 1 tomchauveau staff 571B Feb 4 15:34 1c294434ba7679ee1f7c9e32c29880b3ad5981058cb54884b4cdc1de37d30e31
-r--r--r-- 1 tomchauveau staff 894B Feb 4 15:34 2a086a3ea822a281c45bc43fecc343ef5ffe721fd58f972ed46a0dcc6c810833
-r--r--r-- 1 tomchauveau staff 150B Feb 4 15:34 82789c089c26861754a6fd11f46dcd053aefe99abbf093d9d10f1a1ec1877b68
-r--r--r-- 1 tomchauveau staff 809K Feb 4 15:34 a01966dde7f8d5ba10b6d87e776c7c8fb5a5f6bfa678874bd28b33b1fc6dba34
# Rerun
time go run ./main.go
ERRO[0009] (*service).Write failed error="rpc error: code = Canceled desc = context canceled" expected="sha256:c4f68cac3b6805a14eef6e8812915bc64f81990df1667d1d97b720bfc05aaff7" ref="sha256:c4f68cac3b6805a14eef6e8812915bc64f81990df1667d1d97b720bfc05aaff7" total=894
go run ./main.go 0.79s user 1.24s system 20% cpu 10.021 total
As you see, cache is found because there is no import warning but it's not used by buildkit. And sometime, the following error is thrown, it can be on first run, second or whatever.
ERRO[0009] (*service).Write failed error="rpc error: code = Canceled desc = context canceled" expected="sha256:c4f68cac3b6805a14eef6e8812915bc64f81990df1667d1d97b720bfc05aaff7" ref="sha256:c4f68cac3b6805a14eef6e8812915bc64f81990df1667d1d97b720bfc05aaff7" total=894