#Inconsistent cache behaviour when exporting directory to runtime container

1 messages · Page 1 of 1 (latest)

ripe vortex
#

When exporting a directory to a runtime container, we are seeing that the runtime container results don't match the results of other regular steps that follow the directory in the DAG.

Setup
We have a custom git module which uses go-git to parse and read information from a git repo. It is called git-repo. To test this module we set up a temporary git repository using the git cli, we then pass the .git directory to our git module and test that the HEAD commit hashes match. This is done using the container API (aka .WithExec())`. It should be noted that the temp git repo is slightly different every test run (when not cached), because the commit hash is dependent on the time.

A picture illustrating the setup is attached.

The basic flow is:

  1. git-tests module creates a temporary repo (files added and commit is made)
  2. repo is passed by the dagger.Directory type to the git-repo module
  3. git-repo module does .Export() to export the directory to it's runtime container
  4. git-repo module analyses the git repo with go-git
  5. git-tests module calls the git-repo's .versionInfo().commit() method to obtain the commit hash of the HEAD commit
  6. git-tests module compares this commit with the result obtained by running git rev-parse --short HEAD on the temporary git repo.
#

The issue
Generally this works pretty well. However ocassionally we have noticed that the tests start to fail complaining that the commit hashes don't match (image attached).
Once in this state, subsequent runs of the test fail with exactly the same error. Each time it complains that the same commit hashes don't match.

Upon further inspection it appears that the results of the git rev-parse --short HEAD and the git-repo's .versionInfo().commit() don't match.

Some interesting things I have noticed about the trace:

  • the stage that runs the creates the temporary repo (/setup.sh in the trace) doesn't appear to be cached. It runs every time although I don't believe its results are being used due to the fact that on each run, the test fails with the same commit hashes as the previous run.
  • the step git rev-parse --short HEAD appears to be cached.
  • the export of the directory appears to be cached (screenshot attached)

Conclusion
For now, we are moving to a way where we can create the temporary git repo deterministically so that it yields the same commit hashes every time.
However I posted this here in case the behaviour we are seeing is not expected. If it is expected, would be nice to understand why it is.

Thank you!!!
I can DM a trace URL to anyone interested in the raw trace.

delicate bough
#

cc @scenic violet .

naive pivot
ripe vortex
#
func repository(ctx context.Context, src *dagger.Directory) (*git.Repository, error) {
    _, err := src.Directory(".git").Export(ctx, "./src/.git")
    if err != nil {
        return nil, err
    }

    return git.PlainOpen("./src")
}