Skip to content

Commit 9a4e1ba

Browse files
committed
address review comments
1 parent ced9875 commit 9a4e1ba

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

cmd/drone-docker/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,17 @@ func main() {
225225
cli.StringFlag{
226226
Name: "docker.baseimageusername",
227227
Usage: "Docker username for base image registry",
228-
EnvVar: "PLUGIN_DOCKER_USERNAME,PLUGIN_BASE_IMAGE_USERNAME",
228+
EnvVar: "PLUGIN_DOCKER_USERNAME,PLUGIN_BASE_IMAGE_USERNAME,DOCKER_BASE_IMAGE_USERNAME",
229229
},
230230
cli.StringFlag{
231231
Name: "docker.baseimagepassword",
232232
Usage: "Docker password for base image registry",
233-
EnvVar: "PLUGIN_DOCKER_PASSWORD,PLUGIN_BASE_IMAGE_PASSWORD",
233+
EnvVar: "PLUGIN_DOCKER_PASSWORD,PLUGIN_BASE_IMAGE_PASSWORD,DOCKER_BASE_IMAGE_PASSWORD",
234234
},
235235
cli.StringFlag{
236236
Name: "docker.baseimageregistry",
237237
Usage: "Docker registry for base image registry",
238-
EnvVar: "PLUGIN_DOCKER_REGISTRY,PLUGIN_BASE_IMAGE_REGISTRY",
238+
EnvVar: "PLUGIN_DOCKER_REGISTRY,PLUGIN_BASE_IMAGE_REGISTRY,DOCKER_BASE_IMAGE_REGISTRY",
239239
},
240240
cli.StringFlag{
241241
Name: "docker.email",

docker.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package docker
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"os/exec"
@@ -11,7 +12,6 @@ import (
1112

1213
"github.com/drone-plugins/drone-docker/internal/docker"
1314
"github.com/drone-plugins/drone-plugin-lib/drone"
14-
"github.com/pkg/errors"
1515
)
1616

1717
type (
@@ -163,7 +163,7 @@ func (p Plugin) Exec() error {
163163
return fmt.Errorf("Error writing config.json: %s", err)
164164
}
165165
_, err = file.Write([]byte(p.Login.Config))
166-
fmt.Println("Writing p.Login.Config: %s", p.Login.Config)
166+
fmt.Println("Writing p.Login.Config")
167167

168168
if err != nil {
169169
return fmt.Errorf("Error writing config.json: %s", err)
@@ -175,7 +175,7 @@ func (p Plugin) Exec() error {
175175
json, err := setDockerAuth(p.Login.Username, p.Login.Password, p.Login.Registry,
176176
p.BaseImageUsername, p.BaseImagePassword, p.BaseImageRegistry)
177177
if err != nil {
178-
return errors.Wrap(err, "Failed to set authentication in docker config")
178+
return fmt.Errorf("Failed to set authentication in docker config %s", err)
179179
}
180180
if json != nil {
181181
path := filepath.Join(dockerHome, "config.json")
@@ -306,15 +306,15 @@ func setDockerAuth(username, password, registry, baseImageUsername,
306306
baseImagePassword, baseImageRegistry string) ([]byte, error) {
307307
var credentials []docker.RegistryCredentials
308308
// add only docker registry to the config
309+
dockerConfig := docker.NewConfig()
309310
if password != "" && strings.Contains(registry, "docker") {
310-
dockerConfig := docker.NewConfig()
311311
pushToRegistryCreds := docker.RegistryCredentials{
312312
Registry: registry,
313313
Username: username,
314314
Password: password,
315315
}
316316
// push registry auth
317-
credentials := append(credentials, pushToRegistryCreds)
317+
credentials = append(credentials, pushToRegistryCreds)
318318
}
319319

320320
if baseImageRegistry != "" {

internal/docker/config.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package docker
33
import (
44
"encoding/base64"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"io/ioutil"
89
"os"
9-
10-
"github.com/pkg/errors"
10+
"strings"
1111
)
1212

1313
const (
@@ -43,7 +43,6 @@ func NewConfig() *Config {
4343
func (c *Config) SetAuth(registry, username, password string) {
4444
authBytes := []byte(username + ":" + password)
4545
encodedString := base64.StdEncoding.EncodeToString(authBytes)
46-
log.Printf("auth : %s", encodedString)
4746
c.Auths[registry] = Auth{Auth: encodedString}
4847
}
4948

@@ -67,7 +66,7 @@ func (c *Config) CreateDockerConfigJson(credentials []RegistryCredentials) ([]by
6766

6867
jsonBytes, err := json.Marshal(c)
6968
if err != nil {
70-
return nil, errors.Wrap(err, "failed to serialize docker config json")
69+
return nil, errors.New("failed to serialize docker config json")
7170
}
7271

7372
return jsonBytes, nil
@@ -77,15 +76,14 @@ func WriteDockerConfig(data []byte, path string) (string error) {
7776
err := os.MkdirAll(path, 0600)
7877
if err != nil {
7978
if !os.IsExist(err) {
80-
return errors.Wrap(err, fmt.Sprintf("failed to create %s directory", path))
79+
return errors.New("failed to create %s directory")
8180
}
8281
}
8382

8483
filePath := path + "/config.json"
85-
log.Printf("Config data is %s", data)
8684
err = ioutil.WriteFile(filePath, data, 0644)
8785
if err != nil {
88-
return errors.Wrap(err, fmt.Sprintf("failed to create docker config file at %s", path))
86+
return errors.New("failed to create docker config file at %s")
8987
}
9088
return nil
9189
}

0 commit comments

Comments
 (0)