Merge pull request #6311 from flouthoc/correctly-burst-cache
build: `--mount=type=bind` ignore `modTime` for cache candidates
This commit is contained in:
commit
4ac53d21ac
|
@ -6,6 +6,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/buildah"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
|
@ -69,6 +70,11 @@ func generatePathChecksum(sourcePath string) (string, error) {
|
|||
}
|
||||
header.Name = filepath.ToSlash(relPath)
|
||||
|
||||
// Zero out timestamp fields to ignore modification time in checksum calculation
|
||||
header.ModTime = time.Time{}
|
||||
header.AccessTime = time.Time{}
|
||||
header.ChangeTime = time.Time{}
|
||||
|
||||
if err := tarWriter.WriteHeader(header); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/opencontainers/go-digest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -52,6 +53,11 @@ func TestGeneratePathChecksum(t *testing.T) {
|
|||
}
|
||||
header.Name = filepath.ToSlash(relPath)
|
||||
|
||||
// Zero out timestamp fields to match the modified generatePathChecksum function
|
||||
header.ModTime = time.Time{}
|
||||
header.AccessTime = time.Time{}
|
||||
header.ChangeTime = time.Time{}
|
||||
|
||||
if err := tarWriter.WriteHeader(header); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -662,6 +662,38 @@ _EOF
|
|||
expect_output --substring "Cache burst add diff"
|
||||
}
|
||||
|
||||
@test "bud --layers with --mount type bind should preserve cache when file mod time changes but content stays same" {
|
||||
_prefetch alpine
|
||||
local contextdir=${TEST_SCRATCH_DIR}/bud/platform
|
||||
mkdir -p $contextdir
|
||||
|
||||
cat > $contextdir/samplefile << _EOF
|
||||
samplefile content unchanged
|
||||
_EOF
|
||||
|
||||
cat > $contextdir/Containerfile << _EOF
|
||||
FROM alpine
|
||||
RUN --mount=type=bind,source=samplefile,target=file,Z cat file
|
||||
_EOF
|
||||
|
||||
# on first run since there is no cache so content must be printed
|
||||
run_buildah build $WITH_POLICY_JSON --layers -t source -f $contextdir/Containerfile $contextdir
|
||||
expect_output --substring "samplefile content unchanged"
|
||||
|
||||
# on second run since there is cache so content should not be printed
|
||||
run_buildah build $WITH_POLICY_JSON --layers -t source -f $contextdir/Containerfile $contextdir
|
||||
# output should not contain content from the file since entire build is cached
|
||||
assert "$output" !~ "samplefile content unchanged"
|
||||
|
||||
# Change mod time of this file (this changes modification time)
|
||||
touch -d "@1577836800" $contextdir/samplefile
|
||||
|
||||
# on third run since content is unchanged, cache should still be used despite different mod time
|
||||
run_buildah build $WITH_POLICY_JSON --layers -t source -f $contextdir/Containerfile $contextdir
|
||||
# output should not contain content from the file since cache should still be valid
|
||||
assert "$output" !~ "samplefile content unchanged"
|
||||
}
|
||||
|
||||
@test "bud --layers should not hit cache if heredoc is changed - with ARG" {
|
||||
_prefetch alpine
|
||||
local contextdir=${TEST_SCRATCH_DIR}/bud/platform
|
||||
|
|
Loading…
Reference in New Issue