forked from toolshed/abra
@ -252,13 +252,13 @@ func Get(recipeName string, conf *runtime.Config) (Recipe, error) {
|
||||
|
||||
// EnsureExists ensures that a recipe is locally cloned
|
||||
func EnsureExists(recipeName string, conf *runtime.Config) error {
|
||||
if !conf.EnsureRecipeExists {
|
||||
return nil
|
||||
}
|
||||
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
if _, err := os.Stat(recipeDir); os.IsNotExist(err) {
|
||||
if conf.Offline {
|
||||
return fmt.Errorf("no local copy of %s available, network access required", recipeName)
|
||||
}
|
||||
|
||||
logrus.Debugf("%s does not exist, attemmpting to clone", recipeDir)
|
||||
url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipeName)
|
||||
if err := gitPkg.Clone(recipeDir, url); err != nil {
|
||||
@ -339,10 +339,6 @@ func EnsureVersion(recipeName, version string) error {
|
||||
|
||||
// EnsureLatest makes sure the latest commit is checked out for a local recipe repository
|
||||
func EnsureLatest(recipeName string, conf *runtime.Config) error {
|
||||
if !conf.EnsureRecipeLatest {
|
||||
return nil
|
||||
}
|
||||
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
isClean, err := gitPkg.IsClean(recipeDir)
|
||||
@ -588,10 +584,6 @@ func GetStringInBetween(recipeName, str, start, end string) (result string, err
|
||||
|
||||
// EnsureUpToDate ensures that the local repo is synced to the remote
|
||||
func EnsureUpToDate(recipeName string, conf *runtime.Config) error {
|
||||
if !conf.EnsureRecipeLatest {
|
||||
return nil
|
||||
}
|
||||
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
isClean, err := gitPkg.IsClean(recipeDir)
|
||||
@ -604,6 +596,11 @@ func EnsureUpToDate(recipeName string, conf *runtime.Config) error {
|
||||
return fmt.Errorf(msg, recipeName, recipeDir)
|
||||
}
|
||||
|
||||
if conf.Offline {
|
||||
logrus.Debug("attempting to use local recipe without access network (\"--offline\")")
|
||||
return nil
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(recipeDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to open %s: %s", recipeDir, err)
|
||||
@ -659,14 +656,14 @@ func EnsureUpToDate(recipeName string, conf *runtime.Config) error {
|
||||
}
|
||||
|
||||
// ReadRecipeCatalogue reads the recipe catalogue.
|
||||
func ReadRecipeCatalogue() (RecipeCatalogue, error) {
|
||||
func ReadRecipeCatalogue(conf *runtime.Config) (RecipeCatalogue, error) {
|
||||
recipes := make(RecipeCatalogue)
|
||||
|
||||
if err := catalogue.EnsureCatalogue(); err != nil {
|
||||
if err := catalogue.EnsureCatalogue(conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := catalogue.EnsureUpToDate(); err != nil {
|
||||
if err := catalogue.EnsureUpToDate(conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -694,10 +691,10 @@ func readRecipeCatalogueFS(target interface{}) error {
|
||||
}
|
||||
|
||||
// VersionsOfService lists the version of a service.
|
||||
func VersionsOfService(recipe, serviceName string) ([]string, error) {
|
||||
func VersionsOfService(recipe, serviceName string, conf *runtime.Config) ([]string, error) {
|
||||
var versions []string
|
||||
|
||||
catalogue, err := ReadRecipeCatalogue()
|
||||
catalogue, err := ReadRecipeCatalogue(conf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -724,7 +721,7 @@ func VersionsOfService(recipe, serviceName string) ([]string, error) {
|
||||
|
||||
// GetRecipeMeta retrieves the recipe metadata from the recipe catalogue.
|
||||
func GetRecipeMeta(recipeName string, conf *runtime.Config) (RecipeMeta, error) {
|
||||
catl, err := ReadRecipeCatalogue()
|
||||
catl, err := ReadRecipeCatalogue(conf)
|
||||
if err != nil {
|
||||
return RecipeMeta{}, err
|
||||
}
|
||||
@ -821,7 +818,11 @@ type InternalTracker struct {
|
||||
type RepoCatalogue map[string]RepoMeta
|
||||
|
||||
// ReadReposMetadata retrieves coop-cloud/... repo metadata from Gitea.
|
||||
func ReadReposMetadata() (RepoCatalogue, error) {
|
||||
func ReadReposMetadata(conf *runtime.Config) (RepoCatalogue, error) {
|
||||
if conf.Offline {
|
||||
return nil, fmt.Errorf("network access required to query recipes metadata")
|
||||
}
|
||||
|
||||
reposMeta := make(RepoCatalogue)
|
||||
|
||||
pageIdx := 1
|
||||
@ -1002,6 +1003,10 @@ func GetRecipeCatalogueVersions(recipeName string, catl RecipeCatalogue) ([]stri
|
||||
|
||||
// UpdateRepositories clones and updates all recipe repositories locally.
|
||||
func UpdateRepositories(repos RepoCatalogue, recipeName string, conf *runtime.Config) error {
|
||||
if conf.Offline {
|
||||
return fmt.Errorf("network access required to update recipes")
|
||||
}
|
||||
|
||||
var barLength int
|
||||
if recipeName != "" {
|
||||
barLength = 1
|
||||
|
Reference in New Issue
Block a user