0
0
forked from toolshed/abra

feat: introduce local recipes

This commit is contained in:
2025-11-04 09:18:29 +01:00
parent cc8703310c
commit 8cbf118f66
4 changed files with 97 additions and 29 deletions

View File

@ -506,7 +506,8 @@ func ExposeAllEnv(
stackName string, stackName string,
compose *composetypes.Config, compose *composetypes.Config,
appEnv envfile.AppEnv, appEnv envfile.AppEnv,
toDeployVersion string) { toDeployVersion string,
) {
for _, service := range compose.Services { for _, service := range compose.Services {
if service.Name == "app" { if service.Name == "app" {
log.Debug(i18n.G("adding env vars to %s service config", stackName)) log.Debug(i18n.G("adding env vars to %s service config", stackName))
@ -633,6 +634,10 @@ func (a App) WipeRecipeVersion() error {
// WriteRecipeVersion writes the recipe version to the app .env file. // WriteRecipeVersion writes the recipe version to the app .env file.
func (a App) WriteRecipeVersion(version string, dryRun bool) error { func (a App) WriteRecipeVersion(version string, dryRun bool) error {
if a.Recipe.Local {
return nil
}
file, err := os.Open(a.Path) file, err := os.Open(a.Path)
if err != nil { if err != nil {
return err return err

View File

@ -486,6 +486,10 @@ func LintSecretLengths(recipe recipe.Recipe) (bool, error) {
} }
func LintValidTags(recipe recipe.Recipe) (bool, error) { func LintValidTags(recipe recipe.Recipe) (bool, error) {
if recipe.Local {
return true, nil
}
repo, err := git.PlainOpen(recipe.Dir) repo, err := git.PlainOpen(recipe.Dir)
if err != nil { if err != nil {
return false, errors.New(i18n.G("unable to open %s: %s", recipe.Dir, err)) return false, errors.New(i18n.G("unable to open %s: %s", recipe.Dir, err))

View File

@ -28,6 +28,10 @@ type EnsureContext struct {
// Ensure makes sure the recipe exists, is up to date and has the specific // Ensure makes sure the recipe exists, is up to date and has the specific
// version checked out. // version checked out.
func (r Recipe) Ensure(ctx EnsureContext) error { func (r Recipe) Ensure(ctx EnsureContext) error {
if r.Local {
return nil
}
if err := r.EnsureExists(); err != nil { if err := r.EnsureExists(); err != nil {
return err return err
} }
@ -68,6 +72,10 @@ func (r Recipe) Ensure(ctx EnsureContext) error {
// EnsureExists ensures that the recipe is locally cloned // EnsureExists ensures that the recipe is locally cloned
func (r Recipe) EnsureExists() error { func (r Recipe) EnsureExists() error {
if r.Local {
return nil
}
if _, err := os.Stat(r.Dir); os.IsNotExist(err) { if _, err := os.Stat(r.Dir); os.IsNotExist(err) {
if err := gitPkg.Clone(r.Dir, r.GitURL); err != nil { if err := gitPkg.Clone(r.Dir, r.GitURL); err != nil {
return err return err
@ -83,6 +91,10 @@ func (r Recipe) EnsureExists() error {
// IsChaosCommit determines if a version sttring is a chaos commit or not. // IsChaosCommit determines if a version sttring is a chaos commit or not.
func (r Recipe) IsChaosCommit(version string) (bool, error) { func (r Recipe) IsChaosCommit(version string) (bool, error) {
if r.Local {
return false, nil
}
isChaosCommit := false isChaosCommit := false
if err := gitPkg.EnsureGitRepo(r.Dir); err != nil { if err := gitPkg.EnsureGitRepo(r.Dir); err != nil {
@ -118,6 +130,10 @@ func (r Recipe) IsChaosCommit(version string) (bool, error) {
// EnsureVersion checks whether a specific version exists for a recipe. // EnsureVersion checks whether a specific version exists for a recipe.
func (r Recipe) EnsureVersion(version string) (bool, error) { func (r Recipe) EnsureVersion(version string) (bool, error) {
if r.Local {
return false, nil
}
isChaosCommit := false isChaosCommit := false
if err := gitPkg.EnsureGitRepo(r.Dir); err != nil { if err := gitPkg.EnsureGitRepo(r.Dir); err != nil {
@ -182,6 +198,10 @@ func (r Recipe) EnsureVersion(version string) (bool, error) {
// EnsureIsClean makes sure that the recipe repository has no unstaged changes. // EnsureIsClean makes sure that the recipe repository has no unstaged changes.
func (r Recipe) EnsureIsClean() error { func (r Recipe) EnsureIsClean() error {
if r.Local {
return nil
}
isClean, err := gitPkg.IsClean(r.Dir) isClean, err := gitPkg.IsClean(r.Dir)
if err != nil { if err != nil {
return errors.New(i18n.G("unable to check git clean status in %s: %s", r.Dir, err)) return errors.New(i18n.G("unable to check git clean status in %s: %s", r.Dir, err))
@ -196,6 +216,10 @@ func (r Recipe) EnsureIsClean() error {
// EnsureLatest makes sure the latest commit is checked out for the local recipe repository // EnsureLatest makes sure the latest commit is checked out for the local recipe repository
func (r Recipe) EnsureLatest() error { func (r Recipe) EnsureLatest() error {
if r.Local {
return nil
}
if err := gitPkg.EnsureGitRepo(r.Dir); err != nil { if err := gitPkg.EnsureGitRepo(r.Dir); err != nil {
return err return err
} }
@ -231,6 +255,10 @@ func (r Recipe) EnsureLatest() error {
// EnsureUpToDate ensures that the local repo is synced to the remote // EnsureUpToDate ensures that the local repo is synced to the remote
func (r Recipe) EnsureUpToDate() error { func (r Recipe) EnsureUpToDate() error {
if r.Local {
return nil
}
repo, err := git.PlainOpen(r.Dir) repo, err := git.PlainOpen(r.Dir)
if err != nil { if err != nil {
return errors.New(i18n.G("unable to open %s: %s", r.Dir, err)) return errors.New(i18n.G("unable to open %s: %s", r.Dir, err))
@ -282,6 +310,10 @@ func (r Recipe) EnsureUpToDate() error {
// IsDirty checks whether a recipe is dirty or not. // IsDirty checks whether a recipe is dirty or not.
func (r *Recipe) IsDirty() (bool, error) { func (r *Recipe) IsDirty() (bool, error) {
if r.Local {
return false, nil
}
isClean, err := gitPkg.IsClean(r.Dir) isClean, err := gitPkg.IsClean(r.Dir)
if err != nil { if err != nil {
return false, err return false, err
@ -292,6 +324,10 @@ func (r *Recipe) IsDirty() (bool, error) {
// ChaosVersion constructs a chaos mode recipe version. // ChaosVersion constructs a chaos mode recipe version.
func (r *Recipe) ChaosVersion() (string, error) { func (r *Recipe) ChaosVersion() (string, error) {
if r.Local {
return "", nil
}
var version string var version string
head, err := r.Head() head, err := r.Head()
@ -315,6 +351,10 @@ func (r *Recipe) ChaosVersion() (string, error) {
// Push pushes the latest changes to a SSH URL remote. You need to have your // Push pushes the latest changes to a SSH URL remote. You need to have your
// local SSH configuration for git.coopcloud.tech working for this to work // local SSH configuration for git.coopcloud.tech working for this to work
func (r Recipe) Push(dryRun bool) error { func (r Recipe) Push(dryRun bool) error {
if r.Local {
return nil
}
repo, err := git.PlainOpen(r.Dir) repo, err := git.PlainOpen(r.Dir)
if err != nil { if err != nil {
return err return err
@ -333,6 +373,10 @@ func (r Recipe) Push(dryRun bool) error {
// Tags list the recipe tags // Tags list the recipe tags
func (r Recipe) Tags() ([]string, error) { func (r Recipe) Tags() ([]string, error) {
if r.Local {
return nil, nil
}
var tags []string var tags []string
repo, err := git.PlainOpen(r.Dir) repo, err := git.PlainOpen(r.Dir)
@ -371,6 +415,10 @@ func (r Recipe) Tags() ([]string, error) {
// GetRecipeVersions retrieves all recipe versions. // GetRecipeVersions retrieves all recipe versions.
func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) { func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
if r.Local {
return nil, nil, nil
}
var warnMsg []string var warnMsg []string
versions := RecipeVersions{} versions := RecipeVersions{}

View File

@ -124,6 +124,14 @@ type Features struct {
func Get(name string) Recipe { func Get(name string) Recipe {
version := "" version := ""
versionRaw := "" versionRaw := ""
gitURL := ""
sshURL := ""
dir := ""
local := false
if strings.HasPrefix(name, "./") {
dir = path.Join(config.ABRA_DIR, name)
local = true
} else {
if strings.Contains(name, ":") { if strings.Contains(name, ":") {
split := strings.Split(name, ":") split := strings.Split(name, ":")
if len(split) > 2 { if len(split) > 2 {
@ -139,8 +147,8 @@ func Get(name string) Recipe {
} }
} }
gitURL := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, name) gitURL = fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, name)
sshURL := fmt.Sprintf(config.RECIPES_SSH_URL_TEMPLATE, name) sshURL = fmt.Sprintf(config.RECIPES_SSH_URL_TEMPLATE, name)
if strings.Contains(name, "/") { if strings.Contains(name, "/") {
u, err := url.Parse(name) u, err := url.Parse(name)
if err != nil { if err != nil {
@ -154,7 +162,8 @@ func Get(name string) Recipe {
sshURL = u.String() + ".git" sshURL = u.String() + ".git"
} }
dir := path.Join(config.RECIPES_DIR, escapeRecipeName(name)) dir = path.Join(config.RECIPES_DIR, escapeRecipeName(name))
}
r := Recipe{ r := Recipe{
Name: name, Name: name,
@ -163,6 +172,7 @@ func Get(name string) Recipe {
Dir: dir, Dir: dir,
GitURL: gitURL, GitURL: gitURL,
SSHURL: sshURL, SSHURL: sshURL,
Local: local,
ComposePath: path.Join(dir, "compose.yml"), ComposePath: path.Join(dir, "compose.yml"),
ReadmePath: path.Join(dir, "README.md"), ReadmePath: path.Join(dir, "README.md"),
@ -187,6 +197,7 @@ type Recipe struct {
Dir string Dir string
GitURL string GitURL string
SSHURL string SSHURL string
Local bool
ComposePath string ComposePath string
ReadmePath string ReadmePath string