mirror of
https://github.com/drone-plugins/drone-docker.git
synced 2026-06-16 14:50:37 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f202de1604 | |||
| 60929c782c | |||
| 90280c9c7b |
@@ -158,34 +158,32 @@ func (p Plugin) Exec() error {
|
|||||||
os.MkdirAll(dockerHome, 0600)
|
os.MkdirAll(dockerHome, 0600)
|
||||||
|
|
||||||
path := filepath.Join(dockerHome, "config.json")
|
path := filepath.Join(dockerHome, "config.json")
|
||||||
file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
|
err := os.WriteFile(path, []byte(p.Login.Config), 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error writing config.json: %s", err)
|
return fmt.Errorf("Error writing config.json: %s", err)
|
||||||
}
|
}
|
||||||
err = os.WriteFile(path, []byte(p.Login.Config), 0600)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Error writing config.json: %s", err)
|
|
||||||
}
|
|
||||||
file.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add base image docker credentials to the existing config file, else create new
|
// instead of writing to config file directly, using docker's login func
|
||||||
|
// is better to integrate with various credential helpers,
|
||||||
|
// it also handles different registry specific logic in a better way,
|
||||||
|
// as opposed to config write where different registries need to be addressed differently.
|
||||||
|
// It handles any changes in the authentication process across different Docker versions.
|
||||||
|
|
||||||
if p.BaseImagePassword != "" {
|
if p.BaseImagePassword != "" {
|
||||||
json, err := setDockerAuth(p.Login.Username, p.Login.Password, p.Login.Registry,
|
var baseConnectorLogin Login
|
||||||
p.BaseImageUsername, p.BaseImagePassword, p.BaseImageRegistry)
|
baseConnectorLogin.Registry = p.BaseImageRegistry
|
||||||
|
baseConnectorLogin.Username = p.BaseImageUsername
|
||||||
|
baseConnectorLogin.Password = p.BaseImagePassword
|
||||||
|
|
||||||
|
cmd := commandLogin(baseConnectorLogin)
|
||||||
|
|
||||||
|
raw, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to set authentication in docker config %s", err)
|
out := string(raw)
|
||||||
}
|
out = strings.Replace(out, "WARNING! Using --password via the CLI is insecure. Use --password-stdin.", "", -1)
|
||||||
os.MkdirAll(dockerHome, 0600)
|
fmt.Println(out)
|
||||||
path := filepath.Join(dockerHome, "config.json")
|
return fmt.Errorf("Error authenticating base connector: exit status 1")
|
||||||
file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Error opening config.json: %s", err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
_, err = file.Write(json)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Error writing config.json: %s", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user