Skip to content

Commit 494d083

Browse files
committed
write auth.json file
1 parent 904449e commit 494d083

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

docker.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io/ioutil"
66
"os"
77
"os/exec"
8+
"os/user"
89
"path/filepath"
910
"strings"
1011
"time"
@@ -59,18 +60,21 @@ type (
5960
func (p Plugin) Exec() error {
6061
// Create Auth Config File
6162
if p.Login.Config != "" {
62-
homeDir, err := os.UserHomeDir()
63+
user, err := user.Current()
6364
if err != nil {
64-
return fmt.Errorf("failed to find home directory: %s", err)
65+
return fmt.Errorf("Error getting the current user: %s", err)
66+
}
67+
root := fmt.Sprintf("/var/tmp/%s/containers/containers/", user.Uid)
68+
if err := os.MkdirAll(root, 0777); err != nil {
69+
return fmt.Errorf("Error writing runtime dir: %s", err)
6570
}
66-
dockerHome := fmt.Sprintf("%s/.docker/config.json", homeDir)
67-
os.MkdirAll(dockerHome, 0600)
6871

69-
path := filepath.Join(dockerHome, "config.json")
70-
err = ioutil.WriteFile(path, []byte(p.Login.Config), 0600)
71-
if err != nil {
72-
return fmt.Errorf("Error writing config.json: %s", err)
72+
path := filepath.Join(root, "auth.json")
73+
if err := ioutil.WriteFile(path, []byte(p.Login.Config), 0600); err != nil {
74+
return fmt.Errorf("Error writing auth.json: %s", err)
7375
}
76+
77+
fmt.Printf("Config written to %s\n", path)
7478
}
7579

7680
// login to the Docker registry

0 commit comments

Comments
 (0)