Skip to content

Commit

Permalink
Generate docker config in temp dir during image signing
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew McNew <[email protected]>
  • Loading branch information
tomkennedy513 and Matthew McNew committed Feb 27, 2023
1 parent 26781c2 commit 61baf85
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions cmd/completion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ func main() {
log.Fatal(err)
}
}

homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(errors.Wrapf(err, "error obtaining home directory"))
}

err = creds.Save(filepath.Join(homeDir, ".docker", "config.json"))
if err != nil {
log.Fatal(errors.Wrapf(err, "error writing docker creds"))
}

keychain := authn.NewMultiKeychain(k8sNodeKeychain, creds)

metadataRetriever := cnb.RemoteMetadataRetriever{
Expand Down Expand Up @@ -140,6 +129,21 @@ func main() {
}

if hasCosign() || notaryV1URL != "" {
tempDir, err := os.MkdirTemp("", "")
if err != nil {
log.Fatal(errors.Wrapf(err, "error creating temprary directory"))
}

err = creds.Save(filepath.Join(tempDir, ".docker", "config.json"))
if err != nil {
log.Fatal(errors.Wrapf(err, "error writing docker creds"))
}

err = os.Setenv("DOCKER_CONFIG", filepath.Join(tempDir, ".docker"))
if err != nil {
log.Fatal(errors.Wrapf(err, "error setting DOCKER_CONFIG env"))
}

if err := signImage(report, keychain); err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 61baf85

Please sign in to comment.