mirror of
https://github.com/drone/drone-kaniko.git
synced 2026-06-04 10:14:55 +08:00
feat: [CI-17953]: Add warning if base image connector is not provided (#152)
* [CI-17953]: Add warning if base image connector is not provided * [CI-17953]: Add warning if base image connector is not provided * [CI-17953]: Add warning if base image connector is not provided
This commit is contained in:
+12
-7
@@ -711,15 +711,20 @@ func setDockerAuth(username, password, registry, dockerUsername, dockerPassword,
|
||||
Password: password,
|
||||
}
|
||||
|
||||
pullFromRegistryCreds := docker.RegistryCredentials{
|
||||
Registry: dockerRegistry,
|
||||
Username: dockerUsername,
|
||||
Password: dockerPassword,
|
||||
credentials := []docker.RegistryCredentials{pushToRegistryCreds}
|
||||
|
||||
if dockerRegistry != "" {
|
||||
pullFromRegistryCreds := docker.RegistryCredentials{
|
||||
Registry: dockerRegistry,
|
||||
Username: dockerUsername,
|
||||
Password: dockerPassword,
|
||||
}
|
||||
credentials = append(credentials, pullFromRegistryCreds)
|
||||
} else {
|
||||
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
|
||||
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
|
||||
}
|
||||
|
||||
credentials := []docker.RegistryCredentials{pushToRegistryCreds, pullFromRegistryCreds}
|
||||
return dockerConfig.CreateDockerConfig(credentials, dockerConfigPath)
|
||||
|
||||
}
|
||||
|
||||
func encodeParam(s string) string {
|
||||
|
||||
@@ -153,4 +153,4 @@ func TestCreateDockerConfigWithoutBaseRegistry(t *testing.T) {
|
||||
// Check if the public Docker Hub auth is not set
|
||||
_, exists := config.Auths[""]
|
||||
assert.False(t, exists)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -508,6 +509,9 @@ func setDockerAuth(username, password, registry, baseImageUsername, baseImagePas
|
||||
Password: baseImagePassword,
|
||||
}
|
||||
credentials = append(credentials, pullFromRegistryCreds)
|
||||
} else {
|
||||
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
|
||||
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
|
||||
}
|
||||
// Creates docker config for both the regustries used for authentication
|
||||
return dockerConfig.CreateDockerConfig(credentials, dockerPath)
|
||||
|
||||
@@ -585,6 +585,9 @@ func setDockerAuth(dockerRegistry, dockerUsername, dockerPassword, accessKey, se
|
||||
Password: dockerPassword,
|
||||
}
|
||||
credentials = append(credentials, pullFromRegistryCreds)
|
||||
} else {
|
||||
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
|
||||
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
|
||||
}
|
||||
|
||||
if assumeRole != "" && oidcToken != "" {
|
||||
|
||||
@@ -42,4 +42,4 @@ func TestCreateDockerConfigForECRWithBaseRegistry(t *testing.T) {
|
||||
|
||||
expectedDockerAuth := docker.Auth{Auth: base64.StdEncoding.EncodeToString([]byte(dockerUsername + ":" + dockerPassword))}
|
||||
assert.Equal(t, expectedDockerAuth, config.Auths[dockerRegistry])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,6 +384,9 @@ func run(c *cli.Context) error {
|
||||
); err != nil {
|
||||
return errors.Wrap(err, "failed to create docker config")
|
||||
}
|
||||
} else {
|
||||
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
|
||||
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ import (
|
||||
const (
|
||||
dockerConfigPath string = "/kaniko/.docker"
|
||||
// GCR JSON key file path
|
||||
gcrKeyPath string = "/kaniko/config.json"
|
||||
gcrEnvVariable string = "GOOGLE_APPLICATION_CREDENTIALS"
|
||||
gcrKeyPath string = "/kaniko/config.json"
|
||||
gcrEnvVariable string = "GOOGLE_APPLICATION_CREDENTIALS"
|
||||
|
||||
defaultDigestFile string = "/kaniko/digest-file"
|
||||
)
|
||||
@@ -353,7 +353,7 @@ func run(c *cli.Context) error {
|
||||
}
|
||||
|
||||
// setup docker config only when base image registry is specified
|
||||
if c.String("base-image-registry") != ""{
|
||||
if c.String("base-image-registry") != "" {
|
||||
if err := setDockerAuth(
|
||||
c.String("base-image-username"),
|
||||
c.String("base-image-password"),
|
||||
@@ -361,6 +361,9 @@ func run(c *cli.Context) error {
|
||||
); err != nil {
|
||||
return errors.Wrap(err, "failed to create docker config")
|
||||
}
|
||||
} else {
|
||||
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
|
||||
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,7 +442,7 @@ func run(c *cli.Context) error {
|
||||
return plugin.Exec()
|
||||
}
|
||||
|
||||
func setDockerAuth(dockerUsername, dockerPassword, dockerRegistry string) (error) {
|
||||
func setDockerAuth(dockerUsername, dockerPassword, dockerRegistry string) error {
|
||||
dockerConfig := docker.NewConfig()
|
||||
dockerRegistryCreds := docker.RegistryCredentials{
|
||||
Registry: dockerRegistry,
|
||||
|
||||
Reference in New Issue
Block a user