dockerhub.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package connect
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/fatih/color"
  6. "github.com/porter-dev/porter/cli/cmd/api"
  7. "github.com/porter-dev/porter/cli/cmd/utils"
  8. )
  9. func Dockerhub(
  10. client *api.Client,
  11. projectID uint,
  12. ) (uint, error) {
  13. // if project ID is 0, ask the user to set the project ID or create a project
  14. if projectID == 0 {
  15. return 0, fmt.Errorf("no project set, please run porter project set [id]")
  16. }
  17. // query for helm repo name
  18. repoName, err := utils.PromptPlaintext(fmt.Sprintf(`Provide the image path: `))
  19. if err != nil {
  20. return 0, err
  21. }
  22. username, err := utils.PromptPlaintext(fmt.Sprintf(`Username: `))
  23. if err != nil {
  24. return 0, err
  25. }
  26. password, err := utils.PromptPasswordWithConfirmation()
  27. if err != nil {
  28. return 0, err
  29. }
  30. // create the basic auth integration
  31. integration, err := client.CreateBasicAuthIntegration(
  32. context.Background(),
  33. projectID,
  34. &api.CreateBasicAuthIntegrationRequest{
  35. Username: username,
  36. Password: password,
  37. },
  38. )
  39. if err != nil {
  40. return 0, err
  41. }
  42. color.New(color.FgGreen).Printf("created basic auth integration with id %d\n", integration.ID)
  43. reg, err := client.CreatePrivateRegistry(
  44. context.Background(),
  45. projectID,
  46. &api.CreatePrivateRegistryRequest{
  47. URL: fmt.Sprintf("docker.io/%s", repoName),
  48. Name: repoName,
  49. BasicIntegrationID: integration.ID,
  50. },
  51. )
  52. if err != nil {
  53. return 0, err
  54. }
  55. color.New(color.FgGreen).Printf("created private registry with id %d and name %s\n", reg.ID, reg.Name)
  56. return reg.ID, nil
  57. }