refactor(recipe): rename Recipe2 -> Recipe

This commit is contained in:
2024-07-08 13:19:40 +02:00
parent f638b6a16b
commit f14d49cc64
21 changed files with 85 additions and 85 deletions

View File

@ -18,7 +18,7 @@ import (
// GetComposeFiles gets the list of compose files for an app (or recipe if you
// don't already have an app) which should be merged into a composetypes.Config
// while respecting the COMPOSE_FILE env var.
func (r Recipe2) GetComposeFiles(appEnv map[string]string) ([]string, error) {
func (r Recipe) GetComposeFiles(appEnv map[string]string) ([]string, error) {
composeFileEnvVar, ok := appEnv["COMPOSE_FILE"]
if !ok {
if err := ensurePathExists(r.ComposePath); err != nil {
@ -59,7 +59,7 @@ func (r Recipe2) GetComposeFiles(appEnv map[string]string) ([]string, error) {
return composeFiles, nil
}
func (r Recipe2) GetComposeConfig(env map[string]string) (*composetypes.Config, error) {
func (r Recipe) GetComposeConfig(env map[string]string) (*composetypes.Config, error) {
pattern := fmt.Sprintf("%s/compose**yml", r.Dir)
composeFiles, err := filepath.Glob(pattern)
if err != nil {
@ -86,7 +86,7 @@ func (r Recipe2) GetComposeConfig(env map[string]string) (*composetypes.Config,
}
// GetVersionLabelLocal retrieves the version label on the local recipe config
func (r Recipe2) GetVersionLabelLocal() (string, error) {
func (r Recipe) GetVersionLabelLocal() (string, error) {
var label string
config, err := r.GetComposeConfig(nil)
if err != nil {
@ -109,7 +109,7 @@ func (r Recipe2) GetVersionLabelLocal() (string, error) {
}
// UpdateTag updates an image tag in-place on file system local compose files.
func (r Recipe2) UpdateTag(image, tag string) (bool, error) {
func (r Recipe) UpdateTag(image, tag string) (bool, error) {
fullPattern := fmt.Sprintf("%s/compose**yml", r.Dir)
image = formatter.StripTagMeta(image)
@ -179,7 +179,7 @@ func (r Recipe2) UpdateTag(image, tag string) (bool, error) {
}
// UpdateLabel updates a label in-place on file system local compose files.
func (r Recipe2) UpdateLabel(pattern, serviceName, label string) error {
func (r Recipe) UpdateLabel(pattern, serviceName, label string) error {
fullPattern := fmt.Sprintf("%s/%s", r.Dir, pattern)
composeFiles, err := filepath.Glob(fullPattern)
if err != nil {

View File

@ -6,7 +6,7 @@ import (
"coopcloud.tech/abra/pkg/envfile"
)
func (r Recipe2) SampleEnv() (map[string]string, error) {
func (r Recipe) SampleEnv() (map[string]string, error) {
sampleEnv, err := envfile.ReadEnv(r.SampleEnvPath)
if err != nil {
return sampleEnv, fmt.Errorf("unable to discover .env.sample for %s", r.Name)

View File

@ -16,7 +16,7 @@ import (
)
// Ensure makes sure the recipe exists, is up to date and has the latest version checked out.
func (r Recipe2) Ensure(chaos bool, offline bool) error {
func (r Recipe) Ensure(chaos bool, offline bool) error {
if err := r.EnsureExists(); err != nil {
return err
}
@ -38,7 +38,7 @@ func (r Recipe2) Ensure(chaos bool, offline bool) error {
}
// EnsureExists ensures that the recipe is locally cloned
func (r Recipe2) EnsureExists() error {
func (r Recipe) EnsureExists() error {
recipeDir := path.Join(config.RECIPES_DIR, r.Name)
if _, err := os.Stat(recipeDir); os.IsNotExist(err) {
@ -57,7 +57,7 @@ func (r Recipe2) EnsureExists() error {
}
// EnsureVersion checks whether a specific version exists for a recipe.
func (r Recipe2) EnsureVersion(version string) error {
func (r Recipe) EnsureVersion(version string) error {
recipeDir := path.Join(config.RECIPES_DIR, r.Name)
if err := gitPkg.EnsureGitRepo(recipeDir); err != nil {
@ -115,7 +115,7 @@ func (r Recipe2) EnsureVersion(version string) error {
}
// EnsureIsClean makes sure that the recipe repository has no unstaged changes.
func (r Recipe2) EnsureIsClean() error {
func (r Recipe) EnsureIsClean() error {
recipeDir := path.Join(config.RECIPES_DIR, r.Name)
isClean, err := gitPkg.IsClean(recipeDir)
@ -132,7 +132,7 @@ func (r Recipe2) EnsureIsClean() error {
}
// EnsureLatest makes sure the latest commit is checked out for the local recipe repository
func (r Recipe2) EnsureLatest() error {
func (r Recipe) EnsureLatest() error {
recipeDir := path.Join(config.RECIPES_DIR, r.Name)
if err := gitPkg.EnsureGitRepo(recipeDir); err != nil {
@ -169,7 +169,7 @@ func (r Recipe2) EnsureLatest() error {
}
// EnsureUpToDate ensures that the local repo is synced to the remote
func (r Recipe2) EnsureUpToDate() error {
func (r Recipe) EnsureUpToDate() error {
recipeDir := path.Join(config.RECIPES_DIR, r.Name)
repo, err := git.PlainOpen(recipeDir)
@ -222,7 +222,7 @@ func (r Recipe2) EnsureUpToDate() error {
}
// ChaosVersion constructs a chaos mode recipe version.
func (r Recipe2) ChaosVersion() (string, error) {
func (r Recipe) ChaosVersion() (string, error) {
var version string
head, err := gitPkg.GetRecipeHead(r.Name)
@ -247,7 +247,7 @@ func (r Recipe2) ChaosVersion() (string, error) {
// 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
func (r Recipe2) Push(dryRun bool) error {
func (r Recipe) Push(dryRun bool) error {
repo, err := git.PlainOpen(r.Dir)
if err != nil {
return err
@ -265,7 +265,7 @@ func (r Recipe2) Push(dryRun bool) error {
}
// Tags list the recipe tags
func (r Recipe2) Tags() ([]string, error) {
func (r Recipe) Tags() ([]string, error) {
var tags []string
repo, err := git.PlainOpen(r.Dir)
@ -291,7 +291,7 @@ func (r Recipe2) Tags() ([]string, error) {
}
// GetRecipeVersions retrieves all recipe versions.
func (r Recipe2) GetRecipeVersions(offline bool) (RecipeVersions, error) {
func (r Recipe) GetRecipeVersions(offline bool) (RecipeVersions, error) {
versions := RecipeVersions{}
log.Debugf("attempting to open git repository in %s", r.Dir)

View File

@ -122,9 +122,9 @@ type Features struct {
SSO string `json:"sso"`
}
func Get2(name string) Recipe2 {
func Get(name string) Recipe {
dir := path.Join(config.RECIPES_DIR, name)
return Recipe2{
return Recipe{
Name: name,
Dir: dir,
SSHURL: fmt.Sprintf(config.SSH_URL_TEMPLATE, name),
@ -135,7 +135,7 @@ func Get2(name string) Recipe2 {
}
}
type Recipe2 struct {
type Recipe struct {
Name string
Dir string
SSHURL string
@ -157,7 +157,7 @@ func GetRecipesLocal() ([]string, error) {
return recipes, nil
}
func GetRecipeFeaturesAndCategory(r Recipe2) (Features, string, error) {
func GetRecipeFeaturesAndCategory(r Recipe) (Features, string, error) {
feat := Features{}
var category string

View File

@ -14,7 +14,7 @@ func TestGetVersionLabelLocalDoesNotUseTimeoutLabel(t *testing.T) {
t.Fatal(err)
}
r := Get2("traefik")
r := Get("traefik")
for i := 1; i < 1000; i++ {
label, err := r.GetVersionLabelLocal()