#How to disable cache while testing builds locally?

1 messages Β· Page 1 of 1 (latest)

onyx plaza
#

How do I disable the cache for the local testing? I'm running withexec ls to test and it's obv always cached and it's a little annoying.

exotic finch
#

Hi πŸ‘‹
Which SDK are you using ? The way I do it ATM is by adding an env variable to the container, whose value is random

#

I have a go function to generate this value, everytime I run it.

onyx plaza
#

GO sdk. Would you share this function?

exotic finch
#

Yes, please give me 5 min πŸ™

onyx plaza
#

Ehy, take your time. Not stressing anyone πŸ˜‰

exotic finch
#
package main

import (
    "context"
    "fmt"

    "dagger.io/dagger"
    "github.com/dchest/uniuri"
)

func main() {
    ctx := context.Background()
    client, err := dagger.Connect(ctx)
    if err != nil {
        panic(err)
    }
    defer client.Close()

    // New returns a new random string of the standard length, consisting of standard characters.
    s := uniuri.New()
    
    // Create a new ctr with inherent bursted cache
    // by relying on env var with generated string to burst cache
    ctr := client.Container().From("alpine:3.17").WithEnvVariable("BURST_CACHE", s)

    stdout, err := ctr.WithExec([]string{"ls", "-la"}).Stdout(ctx)
    if err != nil {
        panic(err)
    }
    fmt.Println("output:", stdout)
}
exotic finch
signal fern
#

πŸ‘‹ instead of using uniuri.New() you can just use time.Now().String(). That doesn't require any external libs