@@ -1699,32 +1699,17 @@ func parseGoCoverOutput(input string) (coverage, funcsWithoutTest, funcsWithTest
16991699 return
17001700}
17011701
1702- // buildDocker implements the build process for Docker packages.
1703- // If you change anything in this process that's not backwards compatible, make sure you increment buildProcessVersions accordingly.
1704- func (p * Package ) buildDocker (buildctx * buildContext , wd , result string ) (res * packageBuild , err error ) {
1705- cfg , ok := p .Config .(DockerPkgConfig )
1706- if ! ok {
1707- return nil , xerrors .Errorf ("package should have Docker config" )
1708- }
1709-
1710- if cfg .Dockerfile == "" {
1711- return nil , xerrors .Errorf ("dockerfile is required" )
1712- }
1713-
1714- dockerfile := filepath .Join (p .C .Origin , cfg .Dockerfile )
1715- if _ , err := os .Stat (dockerfile ); os .IsNotExist (err ) {
1716- return nil , err
1717- }
1718-
1719- // Determine final exportToCache value with proper precedence
1720- //
1721- // Precedence (highest to lowest):
1722- // 1. CLI flag (--docker-export-to-cache)
1723- // 2. User environment variable (set before workspace loading)
1724- // 3. Package config (exportToCache in BUILD.yaml)
1725- // 4. Workspace default (auto-set by provenance.slsa: true)
1726- // 5. Global default (false - legacy behavior)
1727-
1702+ // determineDockerExportMode determines the final exportToCache value using a 5-layer precedence hierarchy.
1703+ //
1704+ // Precedence (highest to lowest):
1705+ // 1. CLI flag (--docker-export-to-cache)
1706+ // 2. User environment variable (set before workspace loading)
1707+ // 3. Package config (exportToCache in BUILD.yaml)
1708+ // 4. Workspace default (auto-set by provenance.slsa: true)
1709+ // 5. Global default (false - legacy behavior)
1710+ //
1711+ // The function updates cfg.ExportToCache with the final determined value.
1712+ func determineDockerExportMode (p * Package , cfg * DockerPkgConfig , buildctx * buildContext ) {
17281713 var exportToCache bool
17291714 var source string // Track decision source for logging
17301715
@@ -1782,6 +1767,27 @@ func (p *Package) buildDocker(buildctx *buildContext, wd, result string) (res *p
17821767
17831768 // Update cfg for use in the rest of the function
17841769 cfg .ExportToCache = & exportToCache
1770+ }
1771+
1772+ // buildDocker implements the build process for Docker packages.
1773+ // If you change anything in this process that's not backwards compatible, make sure you increment buildProcessVersions accordingly.
1774+ func (p * Package ) buildDocker (buildctx * buildContext , wd , result string ) (res * packageBuild , err error ) {
1775+ cfg , ok := p .Config .(DockerPkgConfig )
1776+ if ! ok {
1777+ return nil , xerrors .Errorf ("package should have Docker config" )
1778+ }
1779+
1780+ if cfg .Dockerfile == "" {
1781+ return nil , xerrors .Errorf ("dockerfile is required" )
1782+ }
1783+
1784+ dockerfile := filepath .Join (p .C .Origin , cfg .Dockerfile )
1785+ if _ , err := os .Stat (dockerfile ); os .IsNotExist (err ) {
1786+ return nil , err
1787+ }
1788+
1789+ // Determine final exportToCache value with proper precedence
1790+ determineDockerExportMode (p , & cfg , buildctx )
17851791
17861792 var (
17871793 commands = make (map [PackageBuildPhase ][][]string )
0 commit comments