mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-03 01:23:53 +08:00 
			
		
		
		
	buildflags: skip empty cache entries when parsing
Broken in 11c84973ef. The section to skip
an empty input was accidentally removed when some code was refactored to
fix a separate issue.
This skips empty cache entries which allows disabling the `cache-from` and
`cache-to` entries from the command line overrides.
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
			
			
This commit is contained in:
		@@ -38,6 +38,7 @@ func bakeCmd(sb integration.Sandbox, opts ...cmdOpt) (string, error) {
 | 
				
			|||||||
var bakeTests = []func(t *testing.T, sb integration.Sandbox){
 | 
					var bakeTests = []func(t *testing.T, sb integration.Sandbox){
 | 
				
			||||||
	testBakePrint,
 | 
						testBakePrint,
 | 
				
			||||||
	testBakePrintSensitive,
 | 
						testBakePrintSensitive,
 | 
				
			||||||
 | 
						testBakePrintOverrideEmpty,
 | 
				
			||||||
	testBakeLocal,
 | 
						testBakeLocal,
 | 
				
			||||||
	testBakeLocalMulti,
 | 
						testBakeLocalMulti,
 | 
				
			||||||
	testBakeRemote,
 | 
						testBakeRemote,
 | 
				
			||||||
@@ -286,6 +287,47 @@ RUN echo "Hello ${HELLO}"
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func testBakePrintOverrideEmpty(t *testing.T, sb integration.Sandbox) {
 | 
				
			||||||
 | 
						dockerfile := []byte(`
 | 
				
			||||||
 | 
					FROM scratch
 | 
				
			||||||
 | 
					COPY foo /foo
 | 
				
			||||||
 | 
						`)
 | 
				
			||||||
 | 
						bakefile := []byte(`
 | 
				
			||||||
 | 
					target "default" {
 | 
				
			||||||
 | 
						cache-to = ["type=gha,mode=min,scope=integration-tests"]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					`)
 | 
				
			||||||
 | 
						dir := tmpdir(
 | 
				
			||||||
 | 
							t,
 | 
				
			||||||
 | 
							fstest.CreateFile("docker-bake.hcl", bakefile, 0600),
 | 
				
			||||||
 | 
							fstest.CreateFile("Dockerfile", dockerfile, 0600),
 | 
				
			||||||
 | 
							fstest.CreateFile("foo", []byte("foo"), 0600),
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cmd := buildxCmd(sb, withDir(dir), withArgs("bake", "--print", "--set", "*.cache-to="))
 | 
				
			||||||
 | 
						stdout := bytes.Buffer{}
 | 
				
			||||||
 | 
						stderr := bytes.Buffer{}
 | 
				
			||||||
 | 
						cmd.Stdout = &stdout
 | 
				
			||||||
 | 
						cmd.Stderr = &stderr
 | 
				
			||||||
 | 
						require.NoError(t, cmd.Run(), stdout.String(), stderr.String())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						require.JSONEq(t, `{
 | 
				
			||||||
 | 
						"group": {
 | 
				
			||||||
 | 
							"default": {
 | 
				
			||||||
 | 
								"targets": [
 | 
				
			||||||
 | 
									"default"
 | 
				
			||||||
 | 
								]
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						"target": {
 | 
				
			||||||
 | 
							"default": {
 | 
				
			||||||
 | 
								"context": ".",
 | 
				
			||||||
 | 
								"dockerfile": "Dockerfile"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}`, stdout.String())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func testBakeLocal(t *testing.T, sb integration.Sandbox) {
 | 
					func testBakeLocal(t *testing.T, sb integration.Sandbox) {
 | 
				
			||||||
	dockerfile := []byte(`
 | 
						dockerfile := []byte(`
 | 
				
			||||||
FROM scratch
 | 
					FROM scratch
 | 
				
			||||||
@@ -871,6 +913,7 @@ target "default" {
 | 
				
			|||||||
		})
 | 
							})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func testBakeSetNonExistingOutsideNoParallel(t *testing.T, sb integration.Sandbox) {
 | 
					func testBakeSetNonExistingOutsideNoParallel(t *testing.T, sb integration.Sandbox) {
 | 
				
			||||||
	for _, ent := range []bool{true, false} {
 | 
						for _, ent := range []bool{true, false} {
 | 
				
			||||||
		t.Run(fmt.Sprintf("ent=%v", ent), func(t *testing.T) {
 | 
							t.Run(fmt.Sprintf("ent=%v", ent), func(t *testing.T) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -175,6 +175,10 @@ func ParseCacheEntry(in []string) (CacheOptions, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	opts := make(CacheOptions, 0, len(in))
 | 
						opts := make(CacheOptions, 0, len(in))
 | 
				
			||||||
	for _, in := range in {
 | 
						for _, in := range in {
 | 
				
			||||||
 | 
							if in == "" {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if !strings.Contains(in, "=") {
 | 
							if !strings.Contains(in, "=") {
 | 
				
			||||||
			// This is ref only format. Each field in the CSV is its own entry.
 | 
								// This is ref only format. Each field in the CSV is its own entry.
 | 
				
			||||||
			fields, err := csvvalue.Fields(in, nil)
 | 
								fields, err := csvvalue.Fields(in, nil)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user