(dockerClient docker.Client, image string)
| 221 | } |
| 222 | |
| 223 | func (m *manager) addPullSecretConfig(dockerClient docker.Client, image string) (string, error) { |
| 224 | var err error |
| 225 | image, _, err = dockerfile.GetStrippedDockerImageName(strings.ToLower(image)) |
| 226 | if err != nil { |
| 227 | return "", err |
| 228 | } |
| 229 | |
| 230 | registryHostname, err := pullsecrets.GetRegistryFromImageName(image) |
| 231 | if err != nil { |
| 232 | return "", err |
| 233 | } |
| 234 | |
| 235 | registryHostnamePrintable := registryHostname |
| 236 | if registryHostnamePrintable == "" { |
| 237 | registryHostnamePrintable = dockerHubHostname |
| 238 | } |
| 239 | |
| 240 | usernameQuestion := fmt.Sprintf("What is your username for %s? (optional, Enter to skip)", registryHostnamePrintable) |
| 241 | passwordQuestion := fmt.Sprintf("What is your password for %s? (optional, Enter to skip)", registryHostnamePrintable) |
| 242 | if strings.Contains(registryHostname, "ghcr.io") || strings.Contains(registryHostname, "github.com") { |
| 243 | usernameQuestion = "What is your GitHub username? (optional, Enter to skip)" |
| 244 | passwordQuestion = "Please enter a GitHub personal access token (optional, Enter to skip)" |
| 245 | } |
| 246 | |
| 247 | registryUsername := "" |
| 248 | registryPassword := "" |
| 249 | retry := false |
| 250 | |
| 251 | m.log.WriteString(logrus.WarnLevel, "\n") |
| 252 | |
| 253 | for { |
| 254 | m.log.Info("Checking registry authentication for " + registryHostnamePrintable + "...") |
| 255 | authConfig, err := dockerClient.Login(context.TODO(), registryHostname, registryUsername, registryPassword, true, retry, retry) |
| 256 | if err == nil && (authConfig.Username != "" || authConfig.Password != "") { |
| 257 | registryUsername = authConfig.Username |
| 258 | |
| 259 | m.log.Donef("Great! You are authenticated with %s", registryHostnamePrintable) |
| 260 | break |
| 261 | } |
| 262 | |
| 263 | m.log.WriteString(logrus.WarnLevel, "\n") |
| 264 | m.log.Warnf("Unable to find registry credentials for %s", registryHostnamePrintable) |
| 265 | m.log.Warnf("Running `%s` for you to authenticate with the registry (optional)", strings.TrimSpace("docker login "+registryHostname)) |
| 266 | |
| 267 | registryUsername, err = m.log.Question(&survey.QuestionOptions{ |
| 268 | Question: usernameQuestion, |
| 269 | ValidationRegexPattern: "^[^A-Z\\s]+\\.[^A-Z\\s]+$", |
| 270 | ValidationMessage: "Error parsing registry username: must only include lowercase letters.", |
| 271 | }) |
| 272 | |
| 273 | if err != nil { |
| 274 | return "", err |
| 275 | } |
| 276 | if registryUsername != "" { |
| 277 | registryPassword, err = m.log.Question(&survey.QuestionOptions{ |
| 278 | Question: passwordQuestion, |
| 279 | ValidationRegexPattern: "^.*$", |
| 280 | IsPassword: true, |
no test coverage detected