mirror of
https://github.com/drone-plugins/drone-docker.git
synced 2026-06-04 10:15:30 +08:00
address review comments
This commit is contained in:
@@ -225,17 +225,17 @@ func main() {
|
||||
cli.StringFlag{
|
||||
Name: "docker.baseimageusername",
|
||||
Usage: "Docker username for base image registry",
|
||||
EnvVar: "PLUGIN_DOCKER_USERNAME,PLUGIN_BASE_IMAGE_USERNAME",
|
||||
EnvVar: "PLUGIN_DOCKER_USERNAME,PLUGIN_BASE_IMAGE_USERNAME,DOCKER_BASE_IMAGE_USERNAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.baseimagepassword",
|
||||
Usage: "Docker password for base image registry",
|
||||
EnvVar: "PLUGIN_DOCKER_PASSWORD,PLUGIN_BASE_IMAGE_PASSWORD",
|
||||
EnvVar: "PLUGIN_DOCKER_PASSWORD,PLUGIN_BASE_IMAGE_PASSWORD,DOCKER_BASE_IMAGE_PASSWORD",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.baseimageregistry",
|
||||
Usage: "Docker registry for base image registry",
|
||||
EnvVar: "PLUGIN_DOCKER_REGISTRY,PLUGIN_BASE_IMAGE_REGISTRY",
|
||||
EnvVar: "PLUGIN_DOCKER_REGISTRY,PLUGIN_BASE_IMAGE_REGISTRY,DOCKER_BASE_IMAGE_REGISTRY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.email",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -11,7 +12,6 @@ import (
|
||||
|
||||
"github.com/drone-plugins/drone-docker/internal/docker"
|
||||
"github.com/drone-plugins/drone-plugin-lib/drone"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -163,7 +163,7 @@ func (p Plugin) Exec() error {
|
||||
return fmt.Errorf("Error writing config.json: %s", err)
|
||||
}
|
||||
_, err = file.Write([]byte(p.Login.Config))
|
||||
fmt.Println("Writing p.Login.Config: %s", p.Login.Config)
|
||||
fmt.Println("Writing p.Login.Config")
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error writing config.json: %s", err)
|
||||
@@ -175,7 +175,7 @@ func (p Plugin) Exec() error {
|
||||
json, err := setDockerAuth(p.Login.Username, p.Login.Password, p.Login.Registry,
|
||||
p.BaseImageUsername, p.BaseImagePassword, p.BaseImageRegistry)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to set authentication in docker config")
|
||||
return fmt.Errorf("Failed to set authentication in docker config %s", err)
|
||||
}
|
||||
if json != nil {
|
||||
path := filepath.Join(dockerHome, "config.json")
|
||||
@@ -306,15 +306,15 @@ func setDockerAuth(username, password, registry, baseImageUsername,
|
||||
baseImagePassword, baseImageRegistry string) ([]byte, error) {
|
||||
var credentials []docker.RegistryCredentials
|
||||
// add only docker registry to the config
|
||||
dockerConfig := docker.NewConfig()
|
||||
if password != "" && strings.Contains(registry, "docker") {
|
||||
dockerConfig := docker.NewConfig()
|
||||
pushToRegistryCreds := docker.RegistryCredentials{
|
||||
Registry: registry,
|
||||
Username: username,
|
||||
Password: password,
|
||||
}
|
||||
// push registry auth
|
||||
credentials := append(credentials, pushToRegistryCreds)
|
||||
credentials = append(credentials, pushToRegistryCreds)
|
||||
}
|
||||
|
||||
if baseImageRegistry != "" {
|
||||
|
||||
@@ -3,11 +3,11 @@ package docker
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -43,7 +43,6 @@ func NewConfig() *Config {
|
||||
func (c *Config) SetAuth(registry, username, password string) {
|
||||
authBytes := []byte(username + ":" + password)
|
||||
encodedString := base64.StdEncoding.EncodeToString(authBytes)
|
||||
log.Printf("auth : %s", encodedString)
|
||||
c.Auths[registry] = Auth{Auth: encodedString}
|
||||
}
|
||||
|
||||
@@ -67,7 +66,7 @@ func (c *Config) CreateDockerConfigJson(credentials []RegistryCredentials) ([]by
|
||||
|
||||
jsonBytes, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to serialize docker config json")
|
||||
return nil, errors.New("failed to serialize docker config json")
|
||||
}
|
||||
|
||||
return jsonBytes, nil
|
||||
@@ -77,15 +76,14 @@ func WriteDockerConfig(data []byte, path string) (string error) {
|
||||
err := os.MkdirAll(path, 0600)
|
||||
if err != nil {
|
||||
if !os.IsExist(err) {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to create %s directory", path))
|
||||
return errors.New("failed to create %s directory")
|
||||
}
|
||||
}
|
||||
|
||||
filePath := path + "/config.json"
|
||||
log.Printf("Config data is %s", data)
|
||||
err = ioutil.WriteFile(filePath, data, 0644)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("failed to create docker config file at %s", path))
|
||||
return errors.New("failed to create docker config file at %s")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user