Merge pull request #8 from drone/ecr_iam
Make access key & secret optional in case of iam role usage on EKS cluster
This commit is contained in:
commit
fa7726153d
@ -117,28 +117,25 @@ func run(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setupECRAuth(accessKey, secretKey, registry string) error {
|
func setupECRAuth(accessKey, secretKey, registry string) error {
|
||||||
if accessKey == "" {
|
|
||||||
return fmt.Errorf("Access key must be specified")
|
|
||||||
}
|
|
||||||
if secretKey == "" {
|
|
||||||
return fmt.Errorf("Secret key must be specified")
|
|
||||||
}
|
|
||||||
if registry == "" {
|
if registry == "" {
|
||||||
return fmt.Errorf("Registry must be specified")
|
return fmt.Errorf("Registry must be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := os.Setenv(accessKeyEnv, accessKey)
|
// If IAM role is used, access key & secret key are not required
|
||||||
if err != nil {
|
if accessKey != "" && secretKey != "" {
|
||||||
return errors.Wrap(err, fmt.Sprintf("failed to set %s environment variable", accessKeyEnv))
|
err := os.Setenv(accessKeyEnv, accessKey)
|
||||||
}
|
if err != nil {
|
||||||
|
return errors.Wrap(err, fmt.Sprintf("failed to set %s environment variable", accessKeyEnv))
|
||||||
|
}
|
||||||
|
|
||||||
err = os.Setenv(secretKeyEnv, secretKey)
|
err = os.Setenv(secretKeyEnv, secretKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, fmt.Sprintf("failed to set %s environment variable", secretKeyEnv))
|
return errors.Wrap(err, fmt.Sprintf("failed to set %s environment variable", secretKeyEnv))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonBytes := []byte(fmt.Sprintf(`{"credStore": "ecr-login", "credHelpers": {"%s": "ecr-login"}}`, registry))
|
jsonBytes := []byte(fmt.Sprintf(`{"credStore": "ecr-login", "credHelpers": {"%s": "ecr-login"}}`, registry))
|
||||||
err = ioutil.WriteFile(dockerConfigPath, jsonBytes, 0644)
|
err := ioutil.WriteFile(dockerConfigPath, jsonBytes, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create docker config file")
|
return errors.Wrap(err, "failed to create docker config file")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user