fix: flags for logging in
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
321ba1e0ec
commit
9c281d8608
|
@ -59,13 +59,15 @@ var CatalogueSkipList = map[string]bool{
|
||||||
var catalogueGenerateCommand = &cli.Command{
|
var catalogueGenerateCommand = &cli.Command{
|
||||||
Name: "generate",
|
Name: "generate",
|
||||||
Aliases: []string{"g"},
|
Aliases: []string{"g"},
|
||||||
Usage: "Generate a new copy of the catalogue",
|
Usage: "Generate a new copy of the recipe catalogue",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
internal.PushFlag,
|
internal.PushFlag,
|
||||||
internal.CommitFlag,
|
internal.CommitFlag,
|
||||||
internal.CommitMessageFlag,
|
internal.CommitMessageFlag,
|
||||||
internal.DryFlag,
|
internal.DryFlag,
|
||||||
internal.SkipUpdatesFlag,
|
internal.SkipUpdatesFlag,
|
||||||
|
internal.RegistryUsernameFlag,
|
||||||
|
internal.RegistryPasswordFlag,
|
||||||
},
|
},
|
||||||
Description: `
|
Description: `
|
||||||
This command generates a new copy of the recipe catalogue which can be found on:
|
This command generates a new copy of the recipe catalogue which can be found on:
|
||||||
|
@ -73,8 +75,8 @@ This command generates a new copy of the recipe catalogue which can be found on:
|
||||||
https://recipes.coopcloud.tech
|
https://recipes.coopcloud.tech
|
||||||
|
|
||||||
It polls the entire git.coopcloud.tech/coop-cloud/... recipe repository
|
It polls the entire git.coopcloud.tech/coop-cloud/... recipe repository
|
||||||
listing, parses README and tags to produce recipe metadata and produces a
|
listing, parses README.md and git tags of those repositories to produce recipe
|
||||||
apps.json file which is placed in your ~/.abra/catalogue/recipes.json.
|
metadata and produces a recipes JSON file.
|
||||||
|
|
||||||
It is possible to generate new metadata for a single recipe by passing
|
It is possible to generate new metadata for a single recipe by passing
|
||||||
<recipe>. The existing local catalogue will be updated, not overwritten.
|
<recipe>. The existing local catalogue will be updated, not overwritten.
|
||||||
|
@ -84,6 +86,9 @@ A new catalogue copy can be published to the recipes repository by passing the
|
||||||
|
|
||||||
https://git.coopcloud.tech/coop-cloud/recipes
|
https://git.coopcloud.tech/coop-cloud/recipes
|
||||||
|
|
||||||
|
It is quite easy to get rate limited by Docker Hub when running this command.
|
||||||
|
If you have a Hub account you can have Abra log you in to avoid this. Pass
|
||||||
|
"--username" and "--password".
|
||||||
`,
|
`,
|
||||||
ArgsUsage: "[<recipe>]",
|
ArgsUsage: "[<recipe>]",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
@ -133,7 +138,11 @@ A new catalogue copy can be published to the recipes repository by passing the
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
versions, err := catalogue.GetRecipeVersions(recipeMeta.Name)
|
versions, err := catalogue.GetRecipeVersions(
|
||||||
|
recipeMeta.Name,
|
||||||
|
internal.RegistryUsername,
|
||||||
|
internal.RegistryPassword,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -455,6 +455,26 @@ var SkipUpdatesFlag = &cli.BoolFlag{
|
||||||
Destination: &SkipUpdates,
|
Destination: &SkipUpdates,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var RegistryUsername string
|
||||||
|
var RegistryUsernameFlag = &cli.StringFlag{
|
||||||
|
Name: "username",
|
||||||
|
Aliases: []string{"u"},
|
||||||
|
Value: "",
|
||||||
|
Usage: "Registry username",
|
||||||
|
EnvVars: []string{"REGISTRY_USERNAME"},
|
||||||
|
Destination: &RegistryUsername,
|
||||||
|
}
|
||||||
|
|
||||||
|
var RegistryPassword string
|
||||||
|
var RegistryPasswordFlag = &cli.StringFlag{
|
||||||
|
Name: "password",
|
||||||
|
Aliases: []string{"p"},
|
||||||
|
Value: "",
|
||||||
|
Usage: "Registry password",
|
||||||
|
EnvVars: []string{"REGISTRY_PASSWORD"},
|
||||||
|
Destination: &RegistryUsername,
|
||||||
|
}
|
||||||
|
|
||||||
// SSHFailMsg is a hopefully helpful SSH failure message
|
// SSHFailMsg is a hopefully helpful SSH failure message
|
||||||
var SSHFailMsg = `
|
var SSHFailMsg = `
|
||||||
Woops, Abra is unable to connect to connect to %s.
|
Woops, Abra is unable to connect to connect to %s.
|
||||||
|
|
|
@ -362,7 +362,7 @@ func ReadReposMetadata() (RepoCatalogue, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRecipeVersions retrieves all recipe versions.
|
// GetRecipeVersions retrieves all recipe versions.
|
||||||
func GetRecipeVersions(recipeName string) (RecipeVersions, error) {
|
func GetRecipeVersions(recipeName, registryUsername, registryPassword string) (RecipeVersions, error) {
|
||||||
versions := RecipeVersions{}
|
versions := RecipeVersions{}
|
||||||
|
|
||||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||||
|
@ -439,7 +439,7 @@ func GetRecipeVersions(recipeName string) (RecipeVersions, error) {
|
||||||
if digest, exists = queryCache[img]; !exists {
|
if digest, exists = queryCache[img]; !exists {
|
||||||
logrus.Debugf("looking up image: %s from %s", img, path)
|
logrus.Debugf("looking up image: %s from %s", img, path)
|
||||||
var err error
|
var err error
|
||||||
digest, err = client.GetTagDigest(cl, img)
|
digest, err = client.GetTagDigest(cl, img, registryUsername, registryPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Warn(err)
|
logrus.Warn(err)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"coopcloud.tech/abra/pkg/web"
|
"coopcloud.tech/abra/pkg/web"
|
||||||
|
@ -42,7 +41,7 @@ func basicAuth(username, password string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getRegv2Token retrieves a registry v2 authentication token.
|
// getRegv2Token retrieves a registry v2 authentication token.
|
||||||
func getRegv2Token(cl *client.Client, image reference.Named) (string, error) {
|
func getRegv2Token(cl *client.Client, image reference.Named, registryUsername, registryPassword string) (string, error) {
|
||||||
img := reference.Path(image)
|
img := reference.Path(image)
|
||||||
tokenURL := "https://auth.docker.io/token"
|
tokenURL := "https://auth.docker.io/token"
|
||||||
values := fmt.Sprintf("service=registry.docker.io&scope=repository:%s:pull", img)
|
values := fmt.Sprintf("service=registry.docker.io&scope=repository:%s:pull", img)
|
||||||
|
@ -53,11 +52,10 @@ func getRegv2Token(cl *client.Client, image reference.Named) (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
username, userOk := os.LookupEnv("DOCKER_USERNAME")
|
if registryUsername != "" && registryPassword != "" {
|
||||||
password, passOk := os.LookupEnv("DOCKER_PASSWORD")
|
logrus.Debugf("using registry log in credentials for token request")
|
||||||
if userOk && passOk {
|
auth := basicAuth(registryUsername, registryPassword)
|
||||||
logrus.Debugf("using docker log in credentials for registry token request")
|
req.Header.Add("Authorization", fmt.Sprintf("Basic %s", auth))
|
||||||
req.Header.Add("Authorization", fmt.Sprintf("Basic %s", basicAuth(username, password)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client := web.NewHTTPRetryClient()
|
client := web.NewHTTPRetryClient()
|
||||||
|
@ -94,7 +92,7 @@ func getRegv2Token(cl *client.Client, image reference.Named) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTagDigest retrieves an image digest from a v2 registry
|
// GetTagDigest retrieves an image digest from a v2 registry
|
||||||
func GetTagDigest(cl *client.Client, image reference.Named) (string, error) {
|
func GetTagDigest(cl *client.Client, image reference.Named, registryUsername, registryPassword string) (string, error) {
|
||||||
img := reference.Path(image)
|
img := reference.Path(image)
|
||||||
tag := image.(reference.NamedTagged).Tag()
|
tag := image.(reference.NamedTagged).Tag()
|
||||||
manifestURL := fmt.Sprintf("https://index.docker.io/v2/%s/manifests/%s", img, tag)
|
manifestURL := fmt.Sprintf("https://index.docker.io/v2/%s/manifests/%s", img, tag)
|
||||||
|
@ -104,7 +102,7 @@ func GetTagDigest(cl *client.Client, image reference.Named) (string, error) {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := getRegv2Token(cl, image)
|
token, err := getRegv2Token(cl, image, registryUsername, registryPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue