Merge pull request #1341 from dgageot/fix-1340

[1340] Disable git labels if `BUILDX_GIT_LABELS` is not `1` or `full`
This commit is contained in:
CrazyMax 2022-10-04 17:04:35 +02:00 committed by GitHub
commit 3a5741f534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -15,8 +15,8 @@ import (
const DockerfileLabel = "com.docker.image.source.entrypoint"
func addGitProvenance(ctx context.Context, contextPath string, dockerfilePath string) (map[string]string, error) {
v, ok := os.LookupEnv("BUILDX_GIT_LABELS")
if !ok || contextPath == "" {
v := os.Getenv("BUILDX_GIT_LABELS")
if (v != "1" && v != "full") || contextPath == "" {
return nil, nil
}
labels := make(map[string]string, 0)

View File

@ -64,6 +64,14 @@ func TestAddGitProvenanceDataWithoutEnv(t *testing.T) {
assert.Nilf(t, labels, "No labels expected")
}
func TestAddGitProvenanceDataWitEmptyEnv(t *testing.T) {
defer setupTest(t)(t)
os.Setenv("BUILDX_GIT_LABELS", "")
labels, err := addGitProvenance(context.Background(), repoDir, filepath.Join(repoDir, "Dockerfile"))
assert.Nilf(t, err, "No error expected")
assert.Nilf(t, labels, "No labels expected")
}
func TestAddGitProvenanceDataWithoutLabels(t *testing.T) {
defer setupTest(t)(t)
os.Setenv("BUILDX_GIT_LABELS", "full")