fix: only use git to update local catalogue
See coop-cloud/organising#321.
This commit is contained in:
parent
4f22228aab
commit
ab64eb2e8d
|
@ -2,7 +2,6 @@ package recipe
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -11,7 +10,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"coopcloud.tech/abra/pkg/catalogue"
|
"coopcloud.tech/abra/pkg/catalogue"
|
||||||
"coopcloud.tech/abra/pkg/compose"
|
"coopcloud.tech/abra/pkg/compose"
|
||||||
|
@ -660,51 +658,6 @@ func EnsureUpToDate(recipeName string, conf *runtime.Config) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type CatalogueOfflineError struct {
|
|
||||||
msg string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *CatalogueOfflineError) Error() string {
|
|
||||||
return fmt.Sprintf("catalogue offline: %s", e.msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
// recipeCatalogueFSIsLatest checks whether the recipe catalogue stored locally
|
|
||||||
// is up to date.
|
|
||||||
func recipeCatalogueFSIsLatest() (bool, error) {
|
|
||||||
httpClient := web.NewHTTPRetryClient()
|
|
||||||
res, err := httpClient.Head(RecipeCatalogueURL)
|
|
||||||
if err != nil {
|
|
||||||
return false, &CatalogueOfflineError{err.Error()}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastModified := res.Header["Last-Modified"][0]
|
|
||||||
parsed, err := time.Parse(time.RFC1123, lastModified)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := os.Stat(config.RECIPES_JSON)
|
|
||||||
if err != nil {
|
|
||||||
if os.IsNotExist(err) {
|
|
||||||
logrus.Debugf("no recipe catalogue found in file system cache")
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
localModifiedTime := info.ModTime().Unix()
|
|
||||||
remoteModifiedTime := parsed.Unix()
|
|
||||||
|
|
||||||
if localModifiedTime < remoteModifiedTime {
|
|
||||||
logrus.Debug("file system cached recipe catalogue is out-of-date")
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Debug("file system cached recipe catalogue is up-to-date")
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadRecipeCatalogue reads the recipe catalogue.
|
// ReadRecipeCatalogue reads the recipe catalogue.
|
||||||
func ReadRecipeCatalogue() (RecipeCatalogue, error) {
|
func ReadRecipeCatalogue() (RecipeCatalogue, error) {
|
||||||
recipes := make(RecipeCatalogue)
|
recipes := make(RecipeCatalogue)
|
||||||
|
@ -713,23 +666,8 @@ func ReadRecipeCatalogue() (RecipeCatalogue, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeFSIsLatest, err := recipeCatalogueFSIsLatest()
|
if err := catalogue.EnsureUpToDate(); err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
var offlineErr *CatalogueOfflineError
|
|
||||||
if errors.As(err, &offlineErr) {
|
|
||||||
logrus.Error(err)
|
|
||||||
logrus.Error("unable to retrieve catalogue from internet, using local copy.")
|
|
||||||
recipeFSIsLatest = true
|
|
||||||
} else {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !recipeFSIsLatest {
|
|
||||||
if err := readRecipeCatalogueWeb(&recipes); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return recipes, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := readRecipeCatalogueFS(&recipes); err != nil {
|
if err := readRecipeCatalogueFS(&recipes); err != nil {
|
||||||
|
@ -755,26 +693,6 @@ func readRecipeCatalogueFS(target interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// readRecipeCatalogueWeb reads the catalogue from the web.
|
|
||||||
func readRecipeCatalogueWeb(target interface{}) error {
|
|
||||||
if err := web.ReadJSON(RecipeCatalogueURL, &target); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
recipesJSON, err := json.MarshalIndent(target, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := ioutil.WriteFile(config.RECIPES_JSON, recipesJSON, 0764); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Debugf("read recipe catalogue from web at %s", RecipeCatalogueURL)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// VersionsOfService lists the version of a service.
|
// VersionsOfService lists the version of a service.
|
||||||
func VersionsOfService(recipe, serviceName string) ([]string, error) {
|
func VersionsOfService(recipe, serviceName string) ([]string, error) {
|
||||||
var versions []string
|
var versions []string
|
||||||
|
@ -1076,7 +994,9 @@ func GetRecipeCatalogueVersions(recipeName string, catl RecipeCatalogue) ([]stri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sortVersionStrings(versions)
|
sortVersionStrings(versions)
|
||||||
|
|
||||||
return versions, nil
|
return versions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue