forked from toolshed/abra
refactor: apps -> recipes
This commit is contained in:
@ -136,7 +136,7 @@ func recipeCatalogueFSIsLatest() (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
info, err := os.Stat(config.APPS_JSON)
|
||||
info, err := os.Stat(config.RECIPES_JSON)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
logrus.Debugf("no recipe catalogue found in file system cache")
|
||||
@ -185,7 +185,7 @@ func ReadRecipeCatalogue() (RecipeCatalogue, error) {
|
||||
|
||||
// readRecipeCatalogueFS reads the catalogue from the file system.
|
||||
func readRecipeCatalogueFS(target interface{}) error {
|
||||
recipesJSONFS, err := ioutil.ReadFile(config.APPS_JSON)
|
||||
recipesJSONFS, err := ioutil.ReadFile(config.RECIPES_JSON)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -194,7 +194,7 @@ func readRecipeCatalogueFS(target interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("read recipe catalogue from file system cache in %s", config.APPS_JSON)
|
||||
logrus.Debugf("read recipe catalogue from file system cache in %s", config.RECIPES_JSON)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -210,7 +210,7 @@ func readRecipeCatalogueWeb(target interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(config.APPS_JSON, recipesJSON, 0764); err != nil {
|
||||
if err := ioutil.WriteFile(config.RECIPES_JSON, recipesJSON, 0764); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -437,7 +437,7 @@ func GetRecipeFeaturesAndCategory(recipeName string) (features, string, error) {
|
||||
|
||||
var category string
|
||||
|
||||
readmePath := path.Join(config.ABRA_DIR, "apps", recipeName, "README.md")
|
||||
readmePath := path.Join(config.RECIPES_DIR, recipeName, "README.md")
|
||||
|
||||
logrus.Debugf("attempting to open %s for recipe metadata parsing", readmePath)
|
||||
|
||||
@ -509,7 +509,7 @@ func GetRecipeFeaturesAndCategory(recipeName string) (features, string, error) {
|
||||
func GetRecipeVersions(recipeName string) (RecipeVersions, error) {
|
||||
versions := RecipeVersions{}
|
||||
|
||||
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
logrus.Debugf("attempting to open git repository in %s", recipeDir)
|
||||
|
||||
|
@ -27,7 +27,7 @@ func UpdateTag(pattern, image, tag, recipeName string) error {
|
||||
for _, composeFile := range composeFiles {
|
||||
opts := stack.Deploy{Composefiles: []string{composeFile}}
|
||||
|
||||
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 err
|
||||
@ -93,7 +93,7 @@ func UpdateLabel(pattern, serviceName, label, recipeName string) error {
|
||||
for _, composeFile := range composeFiles {
|
||||
opts := stack.Deploy{Composefiles: []string{composeFile}}
|
||||
|
||||
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 err
|
||||
|
@ -135,7 +135,7 @@ func LoadAppFiles(servers ...string) (AppFiles, error) {
|
||||
if servers[0] == "" {
|
||||
// Empty servers flag, one string will always be passed
|
||||
var err error
|
||||
servers, err = GetAllFoldersInDirectory(ABRA_SERVER_FOLDER)
|
||||
servers, err = GetAllFoldersInDirectory(SERVERS_DIR)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -145,14 +145,14 @@ func LoadAppFiles(servers ...string) (AppFiles, error) {
|
||||
logrus.Debugf("collecting metadata from %v servers: %s", len(servers), strings.Join(servers, ", "))
|
||||
|
||||
for _, server := range servers {
|
||||
serverDir := path.Join(ABRA_SERVER_FOLDER, server)
|
||||
serverDir := path.Join(SERVERS_DIR, server)
|
||||
files, err := getAllFilesInDirectory(serverDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, file := range files {
|
||||
appName := strings.TrimSuffix(file.Name(), ".env")
|
||||
appFilePath := path.Join(ABRA_SERVER_FOLDER, server, file.Name())
|
||||
appFilePath := path.Join(SERVERS_DIR, server, file.Name())
|
||||
appFiles[appName] = AppFile{
|
||||
Path: appFilePath,
|
||||
Server: server,
|
||||
@ -248,8 +248,8 @@ func GetAppNames() ([]string, error) {
|
||||
}
|
||||
|
||||
// TemplateAppEnvSample copies the example env file for the app into the users env files
|
||||
func TemplateAppEnvSample(recipe, appName, server, domain string) error {
|
||||
envSamplePath := path.Join(ABRA_DIR, "apps", recipe, ".env.sample")
|
||||
func TemplateAppEnvSample(recipeName, appName, server, domain string) error {
|
||||
envSamplePath := path.Join(RECIPES_DIR, recipeName, ".env.sample")
|
||||
envSample, err := ioutil.ReadFile(envSamplePath)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -260,7 +260,7 @@ func TemplateAppEnvSample(recipe, appName, server, domain string) error {
|
||||
return fmt.Errorf("%s already exists?", appEnvPath)
|
||||
}
|
||||
|
||||
envSample = []byte(strings.Replace(string(envSample), fmt.Sprintf("%s.example.com", recipe), domain, -1))
|
||||
envSample = []byte(strings.Replace(string(envSample), fmt.Sprintf("%s.example.com", recipeName), domain, -1))
|
||||
envSample = []byte(strings.Replace(string(envSample), "example.com", domain, -1))
|
||||
|
||||
err = ioutil.WriteFile(appEnvPath, envSample, 0664)
|
||||
@ -336,7 +336,7 @@ func GetAppComposeFiles(recipe string, appEnv AppEnv) ([]string, error) {
|
||||
|
||||
if _, ok := appEnv["COMPOSE_FILE"]; !ok {
|
||||
logrus.Debug("no COMPOSE_FILE detected, loading compose.yml")
|
||||
path := fmt.Sprintf("%s/%s/compose.yml", APPS_DIR, recipe)
|
||||
path := fmt.Sprintf("%s/%s/compose.yml", RECIPES_DIR, recipe)
|
||||
composeFiles = append(composeFiles, path)
|
||||
return composeFiles, nil
|
||||
}
|
||||
@ -345,7 +345,7 @@ func GetAppComposeFiles(recipe string, appEnv AppEnv) ([]string, error) {
|
||||
envVars := strings.Split(composeFileEnvVar, ":")
|
||||
logrus.Debugf("COMPOSE_FILE detected (%s), loading %s", composeFileEnvVar, strings.Join(envVars, ", "))
|
||||
for _, file := range strings.Split(composeFileEnvVar, ":") {
|
||||
path := fmt.Sprintf("%s/%s/%s", APPS_DIR, recipe, file)
|
||||
path := fmt.Sprintf("%s/%s/%s", RECIPES_DIR, recipe, file)
|
||||
composeFiles = append(composeFiles, path)
|
||||
}
|
||||
|
||||
|
@ -15,16 +15,17 @@ import (
|
||||
)
|
||||
|
||||
var ABRA_DIR = os.ExpandEnv("$HOME/.abra")
|
||||
var ABRA_SERVER_FOLDER = path.Join(ABRA_DIR, "servers")
|
||||
var APPS_JSON = path.Join(ABRA_DIR, "catalogue", "recipes.json")
|
||||
var APPS_DIR = path.Join(ABRA_DIR, "apps")
|
||||
var SERVERS_DIR = path.Join(ABRA_DIR, "servers")
|
||||
var RECIPES_DIR = path.Join(ABRA_DIR, "apps")
|
||||
var VENDOR_DIR = path.Join(ABRA_DIR, "vendor")
|
||||
var RECIPES_JSON = path.Join(ABRA_DIR, "catalogue", "recipes.json")
|
||||
var REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud"
|
||||
|
||||
// GetServers retrieves all servers.
|
||||
func GetServers() ([]string, error) {
|
||||
var servers []string
|
||||
|
||||
servers, err := GetAllFoldersInDirectory(ABRA_SERVER_FOLDER)
|
||||
servers, err := GetAllFoldersInDirectory(SERVERS_DIR)
|
||||
if err != nil {
|
||||
return servers, err
|
||||
}
|
||||
@ -50,13 +51,13 @@ func ReadEnv(filePath string) (AppEnv, error) {
|
||||
|
||||
// ReadServerNames retrieves all server names.
|
||||
func ReadServerNames() ([]string, error) {
|
||||
serverNames, err := GetAllFoldersInDirectory(ABRA_SERVER_FOLDER)
|
||||
serverNames, err := GetAllFoldersInDirectory(SERVERS_DIR)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logrus.Debugf("read %s from %s", strings.Join(serverNames, ","), ABRA_SERVER_FOLDER)
|
||||
logrus.Debugf("read %s from %s", strings.Join(serverNames, ","), SERVERS_DIR)
|
||||
|
||||
return serverNames, nil
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
|
||||
// GetRecipeHead retrieves latest HEAD metadata.
|
||||
func GetRecipeHead(recipeName string) (*plumbing.Reference, error) {
|
||||
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
repo, err := git.PlainOpen(recipeDir)
|
||||
if err != nil {
|
||||
@ -35,7 +35,7 @@ func GetRecipeHead(recipeName string) (*plumbing.Reference, error) {
|
||||
|
||||
// IsClean checks if a repo has unstaged changes
|
||||
func IsClean(recipeName string) (bool, error) {
|
||||
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
repo, err := git.PlainOpen(recipeDir)
|
||||
if err != nil {
|
||||
|
@ -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