forked from toolshed/abra
refactor: apps -> recipes
This commit is contained in:
@ -24,9 +24,14 @@ type Recipe struct {
|
||||
Config *composetypes.Config
|
||||
}
|
||||
|
||||
// Dir retrieves the recipe repository path
|
||||
func (r Recipe) Dir() string {
|
||||
return path.Join(config.RECIPES_DIR, r.Name)
|
||||
}
|
||||
|
||||
// UpdateLabel updates a recipe label
|
||||
func (r Recipe) UpdateLabel(pattern, serviceName, label string) error {
|
||||
fullPattern := fmt.Sprintf("%s/%s/%s", config.APPS_DIR, r.Name, pattern)
|
||||
fullPattern := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, r.Name, pattern)
|
||||
if err := compose.UpdateLabel(fullPattern, serviceName, label, r.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -35,7 +40,7 @@ func (r Recipe) UpdateLabel(pattern, serviceName, label string) error {
|
||||
|
||||
// UpdateTag updates a recipe tag
|
||||
func (r Recipe) UpdateTag(image, tag string) error {
|
||||
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, r.Name)
|
||||
pattern := fmt.Sprintf("%s/%s/compose**yml", config.RECIPES_DIR, r.Name)
|
||||
if err := compose.UpdateTag(pattern, image, tag, r.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -46,8 +51,7 @@ func (r Recipe) UpdateTag(image, tag string) error {
|
||||
func (r Recipe) Tags() ([]string, error) {
|
||||
var tags []string
|
||||
|
||||
recipeDir := path.Join(config.ABRA_DIR, "apps", r.Name)
|
||||
repo, err := git.PlainOpen(recipeDir)
|
||||
repo, err := git.PlainOpen(r.Dir())
|
||||
if err != nil {
|
||||
return tags, err
|
||||
}
|
||||
@ -75,7 +79,7 @@ func Get(recipeName string) (Recipe, error) {
|
||||
return Recipe{}, err
|
||||
}
|
||||
|
||||
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, recipeName)
|
||||
pattern := fmt.Sprintf("%s/%s/compose**yml", config.RECIPES_DIR, recipeName)
|
||||
composeFiles, err := filepath.Glob(pattern)
|
||||
if err != nil {
|
||||
return Recipe{}, err
|
||||
@ -85,7 +89,7 @@ func Get(recipeName string) (Recipe, error) {
|
||||
return Recipe{}, fmt.Errorf("%s is missing a compose.yml or compose.*.yml file?", recipeName)
|
||||
}
|
||||
|
||||
envSamplePath := path.Join(config.ABRA_DIR, "apps", recipeName, ".env.sample")
|
||||
envSamplePath := path.Join(config.RECIPES_DIR, recipeName, ".env.sample")
|
||||
sampleEnv, err := config.ReadEnv(envSamplePath)
|
||||
if err != nil {
|
||||
return Recipe{}, err
|
||||
@ -101,12 +105,12 @@ func Get(recipeName string) (Recipe, error) {
|
||||
}
|
||||
|
||||
// EnsureExists ensures that a recipe is locally cloned
|
||||
func EnsureExists(recipe string) error {
|
||||
recipeDir := path.Join(config.ABRA_DIR, "apps", strings.ToLower(recipe))
|
||||
func EnsureExists(recipeName string) error {
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
if _, err := os.Stat(recipeDir); os.IsNotExist(err) {
|
||||
logrus.Debugf("%s does not exist, attemmpting to clone", recipeDir)
|
||||
url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipe)
|
||||
url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipeName)
|
||||
if err := gitPkg.Clone(recipeDir, url); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -121,7 +125,7 @@ func EnsureExists(recipe string) error {
|
||||
|
||||
// EnsureVersion checks whether a specific version exists for a recipe.
|
||||
func EnsureVersion(recipeName, version string) error {
|
||||
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
isClean, err := gitPkg.IsClean(recipeName)
|
||||
if err != nil {
|
||||
@ -186,7 +190,7 @@ func EnsureVersion(recipeName, version string) error {
|
||||
|
||||
// EnsureLatest makes sure the latest commit is checked out for a local recipe repository
|
||||
func EnsureLatest(recipeName string) error {
|
||||
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
isClean, err := gitPkg.IsClean(recipeName)
|
||||
if err != nil {
|
||||
@ -259,7 +263,7 @@ func ChaosVersion(recipeName string) (string, error) {
|
||||
func GetRecipesLocal() ([]string, error) {
|
||||
var recipes []string
|
||||
|
||||
recipes, err := config.GetAllFoldersInDirectory(config.APPS_DIR)
|
||||
recipes, err := config.GetAllFoldersInDirectory(config.RECIPES_DIR)
|
||||
if err != nil {
|
||||
return recipes, err
|
||||
}
|
||||
@ -288,7 +292,7 @@ func GetVersionLabelLocal(recipe Recipe) (string, error) {
|
||||
|
||||
// EnsureUpToDate ensures that the local repo is synced to the remote
|
||||
func EnsureUpToDate(recipeName string) error {
|
||||
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
repo, err := git.PlainOpen(recipeDir)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user