forked from toolshed/abra
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a81dedf3b |
@@ -7,4 +7,3 @@
|
||||
/bin
|
||||
dist/
|
||||
tests/integration/.bats
|
||||
.devbox
|
||||
|
||||
+1
-7
@@ -222,13 +222,7 @@ synchronize your local app environment values with what is deployed live.`),
|
||||
mergedEnv[k] = v
|
||||
}
|
||||
|
||||
// The recipe version is always carried by TYPE (RECIPE, when present,
|
||||
// is a bare source pointer). Stamp the deployed version onto TYPE and
|
||||
// leave RECIPE untouched so the two never drift apart.
|
||||
if t, ok := mergedEnv["TYPE"]; ok {
|
||||
name, _, _ := strings.Cut(t, ":")
|
||||
mergedEnv["TYPE"] = fmt.Sprintf("%s:%s", name, version)
|
||||
} else {
|
||||
if !strings.Contains(recipeEnvVar, ":") {
|
||||
mergedEnv[recipeKey] = fmt.Sprintf("%s:%s", mergedEnv[recipeKey], version)
|
||||
}
|
||||
|
||||
|
||||
+1
-17
@@ -32,18 +32,6 @@ deploy <domain>" to do so.
|
||||
You can see what recipes are available (i.e. values for the [recipe] argument)
|
||||
by running "abra recipe ls".
|
||||
|
||||
In addition to short catalogue names, [recipe] also accepts arbitrary git
|
||||
URLs to use a recipe from outside the catalogue (e.g. a fork or work in
|
||||
progress). Any of these forms is accepted:
|
||||
|
||||
abra app new git.example.com/user/recipe
|
||||
abra app new https://git.example.com/user/recipe
|
||||
abra app new git@git.example.com:user/recipe
|
||||
|
||||
In that case a RECIPE=<canonical name> line is written to the app's .env
|
||||
file so a subsequent "abra app deploy" (on this or another machine) will
|
||||
re-fetch the recipe from the same git source.
|
||||
|
||||
Recipe commit hashes are supported values for "[version]".
|
||||
|
||||
Passing the "--secrets/-S" flag will automatically generate secrets for your
|
||||
@@ -307,7 +295,7 @@ func ensureDomainFlag(recipe recipePkg.Recipe, server string) error {
|
||||
if appDomain == "" && !internal.NoInput {
|
||||
prompt := &survey.Input{
|
||||
Message: i18n.G("Specify app domain"),
|
||||
Default: fmt.Sprintf("%s.%s", recipe.ShortName(), server),
|
||||
Default: fmt.Sprintf("%s.%s", recipe.Name, server),
|
||||
}
|
||||
if err := survey.AskOne(prompt, &appDomain); err != nil {
|
||||
return err
|
||||
@@ -318,10 +306,6 @@ func ensureDomainFlag(recipe recipePkg.Recipe, server string) error {
|
||||
return errors.New(i18n.G("no domain provided"))
|
||||
}
|
||||
|
||||
if strings.ContainsAny(appDomain, "/\\") {
|
||||
return errors.New(i18n.G("invalid domain '%s': must not contain '/' or '\\'", appDomain))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -188,12 +188,6 @@ beforehand. See "abra app backup" for more.`),
|
||||
appPkg.SetChaosVersionLabel(compose, stackName, chosenDowngrade)
|
||||
}
|
||||
|
||||
// NOTE: stamp the deployed version label ourselves rather than relying
|
||||
// on the value baked into the recipe's compose.yml. Git-URL/WIP recipes
|
||||
// often carry a stale or missing label, which would otherwise leave the
|
||||
// live deployment reporting the wrong version after a rollback.
|
||||
appPkg.SetVersionLabel(compose, stackName, chosenDowngrade)
|
||||
|
||||
// Gather secrets
|
||||
secretInfo, err := deploy.GatherSecretsForDeploy(cl, app, internal.ShowUnchanged)
|
||||
if err != nil {
|
||||
|
||||
+4
-24
@@ -200,12 +200,6 @@ beforehand. See "abra app backup" for more.`),
|
||||
appPkg.SetChaosVersionLabel(compose, stackName, chosenUpgrade)
|
||||
}
|
||||
|
||||
// NOTE: stamp the deployed version label ourselves rather than relying
|
||||
// on the value baked into the recipe's compose.yml. Git-URL/WIP recipes
|
||||
// often carry a stale or missing label, which would otherwise leave the
|
||||
// live deployment reporting the wrong version after an upgrade.
|
||||
appPkg.SetVersionLabel(compose, stackName, chosenUpgrade)
|
||||
|
||||
envVars, err := appPkg.CheckEnv(app)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -352,17 +346,9 @@ func getReleaseNotes(
|
||||
return errors.New(i18n.G("parsing chosen upgrade version failed: %s", err))
|
||||
}
|
||||
|
||||
// The deployed version can be "unknown" (e.g. deployed without a version
|
||||
// label, as is common for git-URL/work-in-progress recipes). In that case
|
||||
// there is no lower bound to filter by, so we gather notes for every
|
||||
// version below the chosen one instead of failing.
|
||||
var parsedDeployedVersion tagcmp.Tag
|
||||
haveDeployedVersion := deployMeta.Version != config.UNKNOWN_DEFAULT
|
||||
if haveDeployedVersion {
|
||||
parsedDeployedVersion, err = tagcmp.Parse(deployMeta.Version)
|
||||
if err != nil {
|
||||
return errors.New(i18n.G("parsing deployment version failed: %s", err))
|
||||
}
|
||||
parsedDeployedVersion, err := tagcmp.Parse(deployMeta.Version)
|
||||
if err != nil {
|
||||
return errors.New(i18n.G("parsing deployment version failed: %s", err))
|
||||
}
|
||||
|
||||
for _, version := range internal.SortVersionsDesc(versions) {
|
||||
@@ -371,7 +357,7 @@ func getReleaseNotes(
|
||||
return errors.New(i18n.G("parsing recipe version failed: %s", err))
|
||||
}
|
||||
|
||||
if (!haveDeployedVersion || parsedVersion.IsGreaterThan(parsedDeployedVersion)) &&
|
||||
if parsedVersion.IsGreaterThan(parsedDeployedVersion) &&
|
||||
parsedVersion.IsLessThan(parsedChosenUpgrade) {
|
||||
note, err := app.Recipe.GetReleaseNotes(version, app.Domain)
|
||||
if err != nil {
|
||||
@@ -434,12 +420,6 @@ func validateUpgradeVersionArg(
|
||||
return errors.New(i18n.G("'%s' is not a known version for %s", specificVersion, app.Recipe.Name))
|
||||
}
|
||||
|
||||
// Without a known deployed version we cannot tell whether the requested
|
||||
// version is an upgrade; trust the explicit choice rather than failing.
|
||||
if deployMeta.Version == config.UNKNOWN_DEFAULT {
|
||||
return nil
|
||||
}
|
||||
|
||||
parsedDeployedVersion, err := tagcmp.Parse(deployMeta.Version)
|
||||
if err != nil {
|
||||
return errors.New(i18n.G("'%s' is not a known version", deployMeta.Version))
|
||||
|
||||
@@ -59,15 +59,9 @@ func ValidateRecipe(args []string, cmdName string) recipe.Recipe {
|
||||
log.Fatal(i18n.G("no recipe name provided"))
|
||||
}
|
||||
|
||||
recipeName = recipe.NormalizeRecipeName(recipeName)
|
||||
|
||||
lookupName := recipeName
|
||||
if i := strings.LastIndex(lookupName, ":"); i >= 0 {
|
||||
lookupName = lookupName[:i]
|
||||
}
|
||||
if _, ok := knownRecipes[lookupName]; !ok {
|
||||
if !strings.Contains(lookupName, "/") {
|
||||
log.Fatal(i18n.G("no recipe '%s' exists? pass a git URL (e.g. https://git.example.com/user/recipe) to use a recipe outside the catalogue", lookupName))
|
||||
if _, ok := knownRecipes[recipeName]; !ok {
|
||||
if !strings.Contains(recipeName, "/") {
|
||||
log.Fatal(i18n.G("no recipe '%s' exists?", recipeName))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,11 @@ package recipe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
@@ -43,7 +41,6 @@ var RecipeListCommand = &cobra.Command{
|
||||
|
||||
headers := []string{
|
||||
i18n.G("name"),
|
||||
i18n.G("source"),
|
||||
i18n.G("category"),
|
||||
i18n.G("status"),
|
||||
i18n.G("healthcheck"),
|
||||
@@ -59,7 +56,6 @@ var RecipeListCommand = &cobra.Command{
|
||||
for _, recipe := range recipes {
|
||||
row := []string{
|
||||
recipe.Name,
|
||||
i18n.G("catalogue"),
|
||||
recipe.Category,
|
||||
strconv.Itoa(recipe.Features.Status),
|
||||
recipe.Features.Healthcheck,
|
||||
@@ -80,23 +76,6 @@ var RecipeListCommand = &cobra.Command{
|
||||
}
|
||||
}
|
||||
|
||||
externals := externalRecipes(catl)
|
||||
sort.Strings(externals)
|
||||
for _, name := range externals {
|
||||
row := []string{
|
||||
name,
|
||||
i18n.G("external"),
|
||||
"-", "-", "-", "-", "-", "-", "-",
|
||||
}
|
||||
if pattern != "" {
|
||||
if !strings.Contains(name, pattern) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
table.Row(row...)
|
||||
rows = append(rows, row)
|
||||
}
|
||||
|
||||
if len(rows) > 0 {
|
||||
if internal.MachineReadable {
|
||||
out, err := formatter.ToJSON(headers, rows)
|
||||
@@ -114,30 +93,6 @@ var RecipeListCommand = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
// externalRecipes returns canonical names of locally-cloned recipes that
|
||||
// were sourced from an arbitrary git URL (i.e. they carry a .abra-source
|
||||
// sidecar) and are not already listed in the catalogue.
|
||||
func externalRecipes(catl recipe.RecipeCatalogue) []string {
|
||||
dirs, err := recipe.GetRecipesLocal()
|
||||
if err != nil {
|
||||
log.Debug(i18n.G("can't read local recipes: %s", err))
|
||||
return nil
|
||||
}
|
||||
|
||||
var names []string
|
||||
for _, dir := range dirs {
|
||||
canonical := recipe.ReadRecipeSource(path.Join(config.RECIPES_DIR, dir))
|
||||
if canonical == "" {
|
||||
continue
|
||||
}
|
||||
if _, inCatalogue := catl[canonical]; inCatalogue {
|
||||
continue
|
||||
}
|
||||
names = append(names, canonical)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
var (
|
||||
pattern string
|
||||
)
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ func main() {
|
||||
Version = "dev"
|
||||
}
|
||||
if Commit == "" {
|
||||
Commit = "unknown-commit"
|
||||
Commit = " "
|
||||
}
|
||||
|
||||
cli.Run(Version, Commit)
|
||||
|
||||
+50
-110
@@ -260,30 +260,12 @@ func ReadAppEnvFile(appFile AppFile, name AppName) (App, error) {
|
||||
func NewApp(env envfile.AppEnv, name string, appFile AppFile) (App, error) {
|
||||
domain := env["DOMAIN"]
|
||||
|
||||
typeVar, hasType := env["TYPE"]
|
||||
recipeVar, hasRecipe := env["RECIPE"]
|
||||
if !hasType && !hasRecipe {
|
||||
return App{}, errors.New(i18n.G("%s is missing the TYPE env var?", name))
|
||||
}
|
||||
|
||||
// The recipe identity is taken from RECIPE when present (it records the
|
||||
// canonical git source for externally-sourced recipes), otherwise from
|
||||
// TYPE. The deployed version is always carried by TYPE when a TYPE line
|
||||
// exists; only legacy apps that set RECIPE alone carry it there. RECIPE
|
||||
// itself must stay a bare source pointer, never a versioned value.
|
||||
identity := typeVar
|
||||
if hasRecipe {
|
||||
identity = recipeVar
|
||||
}
|
||||
|
||||
versionSource := identity
|
||||
if hasType {
|
||||
versionSource = typeVar
|
||||
}
|
||||
|
||||
recipeName, _, _ := strings.Cut(identity, ":")
|
||||
if _, version, found := strings.Cut(versionSource, ":"); found && version != "" {
|
||||
recipeName = fmt.Sprintf("%s:%s", recipeName, version)
|
||||
recipeName, exists := env["RECIPE"]
|
||||
if !exists {
|
||||
recipeName, exists = env["TYPE"]
|
||||
if !exists {
|
||||
return App{}, errors.New(i18n.G("%s is missing the TYPE env var?", name))
|
||||
}
|
||||
}
|
||||
|
||||
return App{
|
||||
@@ -410,15 +392,11 @@ func TemplateAppEnvSample(r recipe.Recipe, appName, server, domain string) error
|
||||
|
||||
newContents := strings.Replace(
|
||||
string(read),
|
||||
fmt.Sprintf("%s.example.com", r.ShortName()),
|
||||
fmt.Sprintf("%s.example.com", r.Name),
|
||||
domain,
|
||||
-1,
|
||||
)
|
||||
|
||||
if strings.Contains(r.Name, "/") {
|
||||
newContents = injectRecipeLine(newContents, r.Name)
|
||||
}
|
||||
|
||||
err = os.WriteFile(appEnvPath, []byte(newContents), 0)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -429,37 +407,6 @@ func TemplateAppEnvSample(r recipe.Recipe, appName, server, domain string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
// injectRecipeLine ensures the env file carries a RECIPE=<canonical name>
|
||||
// line so a downstream `abra app deploy` (potentially on another machine)
|
||||
// can re-fetch the recipe from its original git source. If a RECIPE= line
|
||||
// already exists in the copied .env.sample it is replaced; otherwise a new
|
||||
// line is inserted immediately after the TYPE= line, or appended at the
|
||||
// end if no TYPE= line is present.
|
||||
func injectRecipeLine(contents, canonicalName string) string {
|
||||
lines := strings.Split(contents, "\n")
|
||||
for i, line := range lines {
|
||||
trimmed := strings.TrimLeft(line, " \t")
|
||||
if strings.HasPrefix(trimmed, "RECIPE=") {
|
||||
lines[i] = "RECIPE=" + canonicalName
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
}
|
||||
for i, line := range lines {
|
||||
trimmed := strings.TrimLeft(line, " \t")
|
||||
if strings.HasPrefix(trimmed, "TYPE=") {
|
||||
out := make([]string, 0, len(lines)+1)
|
||||
out = append(out, lines[:i+1]...)
|
||||
out = append(out, "RECIPE="+canonicalName)
|
||||
out = append(out, lines[i+1:]...)
|
||||
return strings.Join(out, "\n")
|
||||
}
|
||||
}
|
||||
if contents != "" && !strings.HasSuffix(contents, "\n") {
|
||||
contents += "\n"
|
||||
}
|
||||
return contents + "RECIPE=" + canonicalName + "\n"
|
||||
}
|
||||
|
||||
// SanitiseAppName makes a app name usable with Docker by replacing illegal
|
||||
// characters.
|
||||
func SanitiseAppName(name string) string {
|
||||
@@ -567,22 +514,10 @@ func ExposeAllEnv(
|
||||
_, exists := service.Environment[k]
|
||||
if !exists {
|
||||
value := v
|
||||
switch k {
|
||||
case "TYPE":
|
||||
if k == "TYPE" || k == "RECIPE" {
|
||||
// NOTE(d1): don't use the wrong version from the app env
|
||||
// since we are deploying a new version. Keep the
|
||||
// recipe name already recorded in TYPE and only
|
||||
// swap in the version being deployed.
|
||||
name, _, _ := strings.Cut(v, ":")
|
||||
if _, version, found := strings.Cut(toDeployVersion, ":"); found {
|
||||
value = fmt.Sprintf("%s:%s", name, version)
|
||||
} else {
|
||||
value = name
|
||||
}
|
||||
case "RECIPE":
|
||||
// RECIPE records the canonical git source only; the
|
||||
// version is carried by TYPE, so keep it bare here.
|
||||
value, _, _ = strings.Cut(toDeployVersion, ":")
|
||||
// since we are deploying a new version
|
||||
value = toDeployVersion
|
||||
}
|
||||
service.Environment[k] = &value
|
||||
log.Debug(i18n.G("%s: %s: %s", stackName, k, value))
|
||||
@@ -707,55 +642,60 @@ func (a App) WriteRecipeVersion(version string, dryRun bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var (
|
||||
lines []string
|
||||
hasType bool
|
||||
scanner = bufio.NewScanner(file)
|
||||
dirtyVersion string
|
||||
skipped bool
|
||||
lines []string
|
||||
scanner = bufio.NewScanner(file)
|
||||
)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
lines = append(lines, line)
|
||||
if strings.HasPrefix(line, "TYPE=") {
|
||||
hasType = true
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
file.Close()
|
||||
log.Fatal(err)
|
||||
}
|
||||
file.Close()
|
||||
|
||||
// The recipe version is carried by a single field: TYPE when present (the
|
||||
// standard recipe key), otherwise the legacy RECIPE key. When both exist
|
||||
// (git-URL recipes) RECIPE stays a bare source pointer and only TYPE is
|
||||
// versioned, so the two can never drift apart.
|
||||
targetPrefix := "RECIPE="
|
||||
if hasType {
|
||||
targetPrefix = "TYPE="
|
||||
}
|
||||
|
||||
for i, line := range lines {
|
||||
if !strings.HasPrefix(line, targetPrefix) || strings.HasPrefix(line, "#") {
|
||||
if !strings.HasPrefix(line, "RECIPE=") && !strings.HasPrefix(line, "TYPE=") {
|
||||
lines = append(lines, line)
|
||||
continue
|
||||
}
|
||||
|
||||
name, _, _ := strings.Cut(line, ":")
|
||||
lines[i] = fmt.Sprintf("%s:%s", name, version)
|
||||
if strings.HasPrefix(line, "#") {
|
||||
lines = append(lines, line)
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.Contains(line, version) && !a.Recipe.Dirty && !strings.HasSuffix(line, config.DIRTY_DEFAULT) {
|
||||
skipped = true
|
||||
lines = append(lines, line)
|
||||
continue
|
||||
}
|
||||
|
||||
splitted := strings.Split(line, ":")
|
||||
|
||||
line = fmt.Sprintf("%s:%s", splitted[0], version)
|
||||
lines = append(lines, line)
|
||||
}
|
||||
|
||||
if dryRun {
|
||||
log.Debug(i18n.G("skipping writing version %s because dry run", version))
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm); err != nil {
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Debug(i18n.G("version %s saved to %s.env", version, a.Domain))
|
||||
if a.Recipe.Dirty && dirtyVersion != "" {
|
||||
version = dirtyVersion
|
||||
}
|
||||
|
||||
if !dryRun {
|
||||
if err := os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
log.Debug(i18n.G("skipping writing version %s because dry run", version))
|
||||
}
|
||||
|
||||
if !skipped {
|
||||
log.Debug(i18n.G("version %s saved to %s.env", version, a.Domain))
|
||||
} else {
|
||||
log.Debug(i18n.G("skipping version %s write as already exists in %s.env", version, a.Domain))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package app_test
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -273,60 +271,6 @@ func TestWriteRecipeVersionOverwrite(t *testing.T) {
|
||||
assert.Equal(t, "foo", app.Recipe.EnvVersion)
|
||||
}
|
||||
|
||||
// TestWriteRecipeVersionSingleField ensures the version is written to exactly
|
||||
// one field: TYPE when present (even alongside a RECIPE source pointer, as with
|
||||
// git-URL recipes), otherwise the legacy RECIPE field. RECIPE must stay bare
|
||||
// when a TYPE line exists so the two can never drift apart.
|
||||
func TestWriteRecipeVersionSingleField(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "git recipe: TYPE and RECIPE both present",
|
||||
input: "TYPE=myrecipe\nRECIPE=git.example.com/user/myrecipe\nDOMAIN=x\n",
|
||||
want: "TYPE=myrecipe:1.2.3+4.5.6\nRECIPE=git.example.com/user/myrecipe\nDOMAIN=x",
|
||||
},
|
||||
{
|
||||
name: "git recipe: re-versioning replaces only TYPE",
|
||||
input: "TYPE=myrecipe:0.1.0+1.0.0\nRECIPE=git.example.com/user/myrecipe\nDOMAIN=x\n",
|
||||
want: "TYPE=myrecipe:1.2.3+4.5.6\nRECIPE=git.example.com/user/myrecipe\nDOMAIN=x",
|
||||
},
|
||||
{
|
||||
name: "legacy recipe: only RECIPE present",
|
||||
input: "RECIPE=test_recipe\nDOMAIN=x\n",
|
||||
want: "RECIPE=test_recipe:1.2.3+4.5.6\nDOMAIN=x",
|
||||
},
|
||||
{
|
||||
name: "catalogue recipe: only TYPE present",
|
||||
input: "TYPE=nextcloud\nDOMAIN=x\n",
|
||||
want: "TYPE=nextcloud:1.2.3+4.5.6\nDOMAIN=x",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
p := filepath.Join(t.TempDir(), "app.env")
|
||||
if err := os.WriteFile(p, []byte(tc.input), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
app := appPkg.App{Path: p, Domain: "x"}
|
||||
if err := app.WriteRecipeVersion("1.2.3+4.5.6", false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got, err := os.ReadFile(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.want, string(got))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteRecipeVersionUnknown(t *testing.T) {
|
||||
test.Setup()
|
||||
t.Cleanup(func() { test.Teardown() })
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package app
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestInjectRecipeLineAfterType(t *testing.T) {
|
||||
in := "DOMAIN=example.com\nTYPE=foo\nVERSION=1.0\n"
|
||||
want := "DOMAIN=example.com\nTYPE=foo\nRECIPE=org/foo\nVERSION=1.0\n"
|
||||
got := injectRecipeLine(in, "org/foo")
|
||||
if got != want {
|
||||
t.Errorf("injectRecipeLine inserted RECIPE in wrong position\nwant:\n%q\ngot:\n%q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInjectRecipeLineReplacesExisting(t *testing.T) {
|
||||
in := "TYPE=foo\nRECIPE=old\nDOMAIN=example.com\n"
|
||||
want := "TYPE=foo\nRECIPE=org/foo\nDOMAIN=example.com\n"
|
||||
got := injectRecipeLine(in, "org/foo")
|
||||
if got != want {
|
||||
t.Errorf("injectRecipeLine should replace existing RECIPE line\nwant:\n%q\ngot:\n%q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInjectRecipeLineNoTypeAppends(t *testing.T) {
|
||||
in := "DOMAIN=example.com\n"
|
||||
want := "DOMAIN=example.com\nRECIPE=org/foo\n"
|
||||
got := injectRecipeLine(in, "org/foo")
|
||||
if got != want {
|
||||
t.Errorf("injectRecipeLine should append when TYPE is missing\nwant:\n%q\ngot:\n%q", want, got)
|
||||
}
|
||||
}
|
||||
@@ -27,16 +27,10 @@ var BoldUnderlineStyle = lipgloss.NewStyle().
|
||||
Underline(true)
|
||||
|
||||
func ShortenID(str string) string {
|
||||
if len(str) < 12 {
|
||||
return str
|
||||
}
|
||||
return str[:12]
|
||||
}
|
||||
|
||||
func SmallSHA(hash string) string {
|
||||
if len(hash) < 8 {
|
||||
return hash
|
||||
}
|
||||
return hash[:8]
|
||||
}
|
||||
|
||||
|
||||
@@ -36,11 +36,6 @@ func IsClean(repoPath string) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Ignore the abra-managed sidecar file that records the canonical
|
||||
// source URL for externally-cloned recipes; it lives alongside the
|
||||
// recipe but is not part of the upstream tree.
|
||||
patterns = append(patterns, gitignore.ParsePattern(".abra-source", nil))
|
||||
|
||||
if len(patterns) > 0 {
|
||||
worktree.Excludes = append(patterns, worktree.Excludes...)
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package git
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
@@ -15,37 +13,3 @@ func TestIsClean(t *testing.T) {
|
||||
assert.Equal(t, isClean, false)
|
||||
assert.True(t, errors.Is(err, git.ErrRepositoryNotExists))
|
||||
}
|
||||
|
||||
// TestIsCleanIgnoresAbraSource confirms that the .abra-source sidecar
|
||||
// file written by abra next to externally-cloned recipes does not cause
|
||||
// IsClean to report the worktree as dirty.
|
||||
func TestIsCleanIgnoresAbraSource(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
if _, err := git.PlainInit(dir, false); err != nil {
|
||||
t.Fatalf("git init failed: %s", err)
|
||||
}
|
||||
|
||||
sidecar := filepath.Join(dir, ".abra-source")
|
||||
if err := os.WriteFile(sidecar, []byte("git.example.com/u/recipe\n"), 0o644); err != nil {
|
||||
t.Fatalf("writing sidecar failed: %s", err)
|
||||
}
|
||||
|
||||
isClean, err := IsClean(dir)
|
||||
if err != nil {
|
||||
t.Fatalf("IsClean returned error: %s", err)
|
||||
}
|
||||
assert.True(t, isClean, "expected worktree with only .abra-source to be reported clean")
|
||||
|
||||
// Sanity check: an unrelated untracked file should still mark it dirty.
|
||||
other := filepath.Join(dir, "random.txt")
|
||||
if err := os.WriteFile(other, []byte("hello"), 0o644); err != nil {
|
||||
t.Fatalf("writing extra file failed: %s", err)
|
||||
}
|
||||
|
||||
isClean, err = IsClean(dir)
|
||||
if err != nil {
|
||||
t.Fatalf("IsClean returned error: %s", err)
|
||||
}
|
||||
assert.False(t, isClean, "expected worktree with unrelated untracked file to be reported dirty")
|
||||
}
|
||||
|
||||
+87
-62
@@ -7,13 +7,13 @@
|
||||
msgid ""
|
||||
msgstr "Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: EMAIL\n"
|
||||
"POT-Creation-Date: 2026-10-14 10:32-0400\n"
|
||||
"POT-Creation-Date: 2026-10-22 21:25+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Type: text/plain; charset=CHARSET\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: ./cli/app/cp.go:38
|
||||
@@ -219,7 +219,7 @@ msgstr ""
|
||||
msgid "%s created (version: %s)"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:335
|
||||
#: ./cli/recipe/upgrade.go:345
|
||||
#, c-format
|
||||
msgid "%s currently has these unstaged changes 👇"
|
||||
msgstr ""
|
||||
@@ -304,7 +304,7 @@ msgstr ""
|
||||
msgid "%s has no secrets to generate, skipping..."
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:107
|
||||
#: ./pkg/recipe/compose.go:109
|
||||
#, c-format
|
||||
msgid "%s has no version label? try running \"abra recipe sync %s\" first?"
|
||||
msgstr ""
|
||||
@@ -324,12 +324,12 @@ msgstr ""
|
||||
msgid "%s is already fetched"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:233
|
||||
#: ./pkg/recipe/compose.go:277
|
||||
#, c-format
|
||||
msgid "%s is already set, nothing to do?"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:72
|
||||
#: ./pkg/recipe/compose.go:74
|
||||
#, c-format
|
||||
msgid "%s is missing a compose.yml or compose.*.yml file?"
|
||||
msgstr ""
|
||||
@@ -379,7 +379,7 @@ msgstr ""
|
||||
msgid "%s must first be deployed on %s before moving"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:150
|
||||
#: ./cli/recipe/upgrade.go:153
|
||||
#, c-format
|
||||
msgid "%s not considered semver-like"
|
||||
msgstr ""
|
||||
@@ -549,6 +549,11 @@ msgstr ""
|
||||
msgid "%s: waiting %d seconds before next retry"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:392
|
||||
#, c-format
|
||||
msgid "%s:%s was re-published upstream (digest %s → %s)"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/app/upgrade.go:425
|
||||
#, c-format
|
||||
msgid "'%s' is not a known version"
|
||||
@@ -638,17 +643,17 @@ msgstr ""
|
||||
msgid "CHAOS DEPLOY"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:47
|
||||
#: ./pkg/recipe/compose.go:49
|
||||
#, c-format
|
||||
msgid "COMPOSE_FILE (=\"%s\") parsing failed?"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:58
|
||||
#: ./pkg/recipe/compose.go:60
|
||||
#, c-format
|
||||
msgid "COMPOSE_FILE detected (%s), loading %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:38
|
||||
#: ./pkg/recipe/compose.go:40
|
||||
#, c-format
|
||||
msgid "COMPOSE_FILE detected, loading %s"
|
||||
msgstr ""
|
||||
@@ -1687,7 +1692,7 @@ msgctxt "recipe fetch"
|
||||
msgid "a"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:408
|
||||
#: ./cli/recipe/upgrade.go:459
|
||||
msgctxt "recipe upgrade"
|
||||
msgid "a"
|
||||
msgstr ""
|
||||
@@ -1737,7 +1742,7 @@ msgstr ""
|
||||
msgid "accepts at most 2 args with --local/-l"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:249
|
||||
#: ./pkg/recipe/compose.go:293
|
||||
#, c-format
|
||||
msgid "add '- \"%s\"' manually to the 'app' service in %s"
|
||||
msgstr ""
|
||||
@@ -1780,7 +1785,7 @@ msgstr ""
|
||||
msgid "all-services"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:407
|
||||
#: ./cli/recipe/upgrade.go:458
|
||||
msgid "all-tags"
|
||||
msgstr ""
|
||||
|
||||
@@ -1919,7 +1924,7 @@ msgstr ""
|
||||
msgid "c"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:416
|
||||
#: ./cli/recipe/upgrade.go:467
|
||||
msgctxt "recipe upgrade"
|
||||
msgid "c"
|
||||
msgstr ""
|
||||
@@ -1928,7 +1933,7 @@ msgstr ""
|
||||
msgid "can not insert from file and read from stdin"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:323
|
||||
#: ./cli/recipe/upgrade.go:333
|
||||
#, c-format
|
||||
msgid "can upgrade service: %s, image: %s, tag: %s ::"
|
||||
msgstr ""
|
||||
@@ -2108,7 +2113,7 @@ msgstr ""
|
||||
msgid "chore: publish new catalogue release changes"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:352
|
||||
#: ./cli/recipe/upgrade.go:362
|
||||
msgid "chore: update image tags"
|
||||
msgstr ""
|
||||
|
||||
@@ -2170,19 +2175,19 @@ msgstr ""
|
||||
msgid "commandconn: starting %s with %v"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:415
|
||||
#: ./cli/recipe/upgrade.go:466
|
||||
msgid "commit"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:418
|
||||
#: ./cli/recipe/upgrade.go:469
|
||||
msgid "commit changes"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:342
|
||||
#: ./cli/recipe/upgrade.go:352
|
||||
msgid "commit changes?"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:356
|
||||
#: ./cli/recipe/upgrade.go:366
|
||||
#, c-format
|
||||
msgid "committed changes as '%s'"
|
||||
msgstr ""
|
||||
@@ -2230,12 +2235,12 @@ msgstr ""
|
||||
msgid "connection timed out for %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:191
|
||||
#: ./pkg/recipe/compose.go:235
|
||||
#, c-format
|
||||
msgid "considering %s config(s) for label update"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:123
|
||||
#: ./pkg/recipe/compose.go:132
|
||||
#, c-format
|
||||
msgid "considering %s config(s) for tag update"
|
||||
msgstr ""
|
||||
@@ -2258,7 +2263,7 @@ msgstr ""
|
||||
msgid "context lacks Docker endpoint"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:229
|
||||
#: ./pkg/recipe/compose.go:273
|
||||
#, c-format
|
||||
msgid "coop-cloud.${STACK_NAME}.version=%s"
|
||||
msgstr ""
|
||||
@@ -2465,12 +2470,12 @@ msgstr ""
|
||||
msgid "detected ABRA_CI=1"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:204
|
||||
#: ./cli/recipe/upgrade.go:214
|
||||
#, c-format
|
||||
msgid "detected compatible upgradable tags %s for %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:177
|
||||
#: ./cli/recipe/upgrade.go:180
|
||||
#, c-format
|
||||
msgid "detected potential upgradable tags %s for %s"
|
||||
msgstr ""
|
||||
@@ -2509,6 +2514,16 @@ msgstr ""
|
||||
msgid "different versions for secret '%s', '%s' and %s'"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:388
|
||||
#, c-format
|
||||
msgid "digest of %s:%s is up to date"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:413
|
||||
#, c-format
|
||||
msgid "digest updated for %s:%s"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/recipe.go:202
|
||||
#, c-format
|
||||
msgid "dir: %s, "
|
||||
@@ -2658,7 +2673,7 @@ msgstr ""
|
||||
msgid "ensuring env version %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:285
|
||||
#: ./cli/recipe/upgrade.go:295
|
||||
msgid "enter / return to confirm, choose 'skip' to not upgrade this tag, vim mode is enabled"
|
||||
msgstr ""
|
||||
|
||||
@@ -2839,7 +2854,7 @@ msgstr ""
|
||||
msgid "failed to migrate app config: %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/client/registry.go:20
|
||||
#: ./pkg/client/registry.go:37 ./pkg/client/registry.go:55 ./pkg/client/registry.go:60
|
||||
#, c-format
|
||||
msgid "failed to parse image %s, saw: %s"
|
||||
msgstr ""
|
||||
@@ -3291,15 +3306,15 @@ msgstr ""
|
||||
msgid "including VOLUMES=%v in backupbot exec invocation"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/release.go:634 ./cli/recipe/upgrade.go:378
|
||||
#: ./cli/recipe/release.go:634 ./cli/recipe/upgrade.go:429
|
||||
msgid "increase the major part of the version"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/release.go:642 ./cli/recipe/upgrade.go:386
|
||||
#: ./cli/recipe/release.go:642 ./cli/recipe/upgrade.go:437
|
||||
msgid "increase the minor part of the version"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/release.go:650 ./cli/recipe/upgrade.go:394
|
||||
#: ./cli/recipe/release.go:650 ./cli/recipe/upgrade.go:445
|
||||
msgid "increase the patch part of the version"
|
||||
msgstr ""
|
||||
|
||||
@@ -3464,7 +3479,7 @@ msgstr ""
|
||||
msgid "list [flags]"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:410
|
||||
#: ./cli/recipe/upgrade.go:461
|
||||
msgid "list all tags, not just upgrades"
|
||||
msgstr ""
|
||||
|
||||
@@ -3534,11 +3549,11 @@ msgstr ""
|
||||
#. with no spaces in between
|
||||
#. translators: `abra man` aliases. use a comma separated list of aliases
|
||||
#. with no spaces in between
|
||||
#: ./cli/app/list.go:319 ./cli/app/move.go:34 ./cli/app/ps.go:205 ./cli/app/secret.go:553 ./cli/app/secret.go:649 ./cli/recipe/list.go:104 ./cli/recipe/upgrade.go:400 ./cli/recipe/version.go:139 ./cli/run.go:152 ./cli/server/list.go:106
|
||||
#: ./cli/app/list.go:319 ./cli/app/move.go:34 ./cli/app/ps.go:205 ./cli/app/secret.go:553 ./cli/app/secret.go:649 ./cli/recipe/list.go:104 ./cli/recipe/upgrade.go:451 ./cli/recipe/version.go:139 ./cli/run.go:152 ./cli/server/list.go:106
|
||||
msgid "m"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/app/list.go:318 ./cli/app/ps.go:204 ./cli/app/secret.go:552 ./cli/app/secret.go:648 ./cli/recipe/list.go:103 ./cli/recipe/upgrade.go:399 ./cli/recipe/version.go:138 ./cli/server/list.go:105
|
||||
#: ./cli/app/list.go:318 ./cli/app/ps.go:204 ./cli/app/secret.go:552 ./cli/app/secret.go:648 ./cli/recipe/list.go:103 ./cli/recipe/upgrade.go:450 ./cli/recipe/version.go:138 ./cli/server/list.go:105
|
||||
msgid "machine"
|
||||
msgstr ""
|
||||
|
||||
@@ -3547,7 +3562,7 @@ msgstr ""
|
||||
msgid "main app service version for %s is empty?"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/internal/recipe.go:48 ./cli/internal/recipe.go:66 ./cli/internal/recipe.go:80 ./cli/recipe/release.go:631 ./cli/recipe/upgrade.go:375
|
||||
#: ./cli/internal/recipe.go:48 ./cli/internal/recipe.go:66 ./cli/internal/recipe.go:80 ./cli/recipe/release.go:631 ./cli/recipe/upgrade.go:426
|
||||
msgid "major"
|
||||
msgstr ""
|
||||
|
||||
@@ -3576,7 +3591,7 @@ msgstr ""
|
||||
msgid "migrating app config from %s to %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/internal/recipe.go:48 ./cli/internal/recipe.go:68 ./cli/internal/recipe.go:82 ./cli/recipe/release.go:639 ./cli/recipe/upgrade.go:383
|
||||
#: ./cli/internal/recipe.go:48 ./cli/internal/recipe.go:68 ./cli/internal/recipe.go:82 ./cli/recipe/release.go:639 ./cli/recipe/upgrade.go:434
|
||||
msgid "minor"
|
||||
msgstr ""
|
||||
|
||||
@@ -3705,7 +3720,7 @@ msgstr ""
|
||||
msgid "no .git directory in %s?"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:29
|
||||
#: ./pkg/recipe/compose.go:31
|
||||
#, c-format
|
||||
msgid "no COMPOSE_FILE detected, loading default: %s"
|
||||
msgstr ""
|
||||
@@ -3731,7 +3746,7 @@ msgstr ""
|
||||
msgid "no changes discovered in %s, nothing to publish?"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:361
|
||||
#: ./cli/recipe/upgrade.go:371
|
||||
msgid "no changes, skip creating commit"
|
||||
msgstr ""
|
||||
|
||||
@@ -3756,7 +3771,7 @@ msgstr ""
|
||||
msgid "no domain provided"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:248
|
||||
#: ./pkg/recipe/compose.go:292
|
||||
msgid "no existing label found, automagic insertion not supported yet"
|
||||
msgstr ""
|
||||
|
||||
@@ -3765,7 +3780,7 @@ msgstr ""
|
||||
msgid "no git tags found for %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:182
|
||||
#: ./cli/recipe/upgrade.go:192
|
||||
#, c-format
|
||||
msgid "no new versions available for %s, assuming %s is the latest (use -a/--all-tags to see all anyway)"
|
||||
msgstr ""
|
||||
@@ -3897,12 +3912,12 @@ msgstr ""
|
||||
msgid "not requesting a remote TTY"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:305
|
||||
#: ./cli/recipe/upgrade.go:315
|
||||
#, c-format
|
||||
msgid "not upgrading %s, skipping as requested"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:244
|
||||
#: ./cli/recipe/upgrade.go:254
|
||||
#, c-format
|
||||
msgid "not upgrading from %s to %s for %s, because the upgrade type is more serious than what user wants"
|
||||
msgstr ""
|
||||
@@ -3956,12 +3971,12 @@ msgstr ""
|
||||
msgid "p"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:163
|
||||
#: ./cli/recipe/upgrade.go:166
|
||||
#, c-format
|
||||
msgid "parsed %s for %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:159
|
||||
#: ./pkg/recipe/compose.go:178
|
||||
#, c-format
|
||||
msgid "parsed %s from %s"
|
||||
msgstr ""
|
||||
@@ -3999,7 +4014,7 @@ msgstr ""
|
||||
msgid "pass command not found on $PATH, is it installed?"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/internal/recipe.go:48 ./cli/internal/recipe.go:70 ./cli/internal/recipe.go:84 ./cli/recipe/release.go:647 ./cli/recipe/upgrade.go:391
|
||||
#: ./cli/internal/recipe.go:48 ./cli/internal/recipe.go:70 ./cli/internal/recipe.go:84 ./cli/recipe/release.go:647 ./cli/recipe/upgrade.go:442
|
||||
msgid "patch"
|
||||
msgstr ""
|
||||
|
||||
@@ -4053,7 +4068,7 @@ msgstr ""
|
||||
msgid "prefer offline & filesystem access"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/app/list.go:321 ./cli/app/ps.go:207 ./cli/app/secret.go:555 ./cli/app/secret.go:651 ./cli/recipe/list.go:106 ./cli/recipe/upgrade.go:402 ./cli/recipe/version.go:141 ./cli/server/list.go:108
|
||||
#: ./cli/app/list.go:321 ./cli/app/ps.go:207 ./cli/app/secret.go:555 ./cli/app/secret.go:651 ./cli/recipe/list.go:106 ./cli/recipe/upgrade.go:453 ./cli/recipe/version.go:141 ./cli/server/list.go:108
|
||||
msgid "print machine-readable output"
|
||||
msgstr ""
|
||||
|
||||
@@ -4436,7 +4451,7 @@ msgstr ""
|
||||
msgid "retrieved %s as target container on %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:59
|
||||
#: ./pkg/recipe/compose.go:61
|
||||
#, c-format
|
||||
msgid "retrieved %s configs for %s"
|
||||
msgstr ""
|
||||
@@ -4446,7 +4461,7 @@ msgstr ""
|
||||
msgid "retrieved %s for %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:144
|
||||
#: ./cli/recipe/upgrade.go:147
|
||||
#, c-format
|
||||
msgid "retrieved %s from remote registry for %s"
|
||||
msgstr ""
|
||||
@@ -4723,12 +4738,12 @@ msgstr ""
|
||||
msgid "serverAdd: cleanUp: unable to list files in %s: %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:227
|
||||
#: ./cli/recipe/upgrade.go:237
|
||||
#, c-format
|
||||
msgid "service %s is at version %s, but pinned to %s, please correct your compose.yml file manually!"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:223
|
||||
#: ./cli/recipe/upgrade.go:233
|
||||
#, c-format
|
||||
msgid "service %s, image %s pinned to %s, no compatible upgrade found"
|
||||
msgstr ""
|
||||
@@ -5007,7 +5022,7 @@ msgstr ""
|
||||
msgid "sync [flags]"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:243
|
||||
#: ./pkg/recipe/compose.go:287
|
||||
#, c-format
|
||||
msgid "synced label %s to service %s"
|
||||
msgstr ""
|
||||
@@ -5025,7 +5040,7 @@ msgstr ""
|
||||
msgid "tag at commit %s is unannotated or otherwise broken"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:301
|
||||
#: ./cli/recipe/upgrade.go:311
|
||||
#, c-format
|
||||
msgid "tag upgraded from %s to %s for %s"
|
||||
msgstr ""
|
||||
@@ -5212,7 +5227,7 @@ msgstr ""
|
||||
msgid "unable to determine server of app %s, please pass --server/-s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:252
|
||||
#: ./cli/recipe/upgrade.go:262
|
||||
#, c-format
|
||||
msgid "unable to determine versioning semantics of %s, listing all tags"
|
||||
msgstr ""
|
||||
@@ -5286,12 +5301,12 @@ msgstr ""
|
||||
msgid "unable to open worktree of %s: %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:159
|
||||
#: ./cli/recipe/upgrade.go:162
|
||||
#, c-format
|
||||
msgid "unable to parse %s, error was: %s, skipping upgrade for %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:153
|
||||
#: ./pkg/recipe/compose.go:167
|
||||
#, c-format
|
||||
msgid "unable to parse %s, skipping"
|
||||
msgstr ""
|
||||
@@ -5331,7 +5346,7 @@ msgstr ""
|
||||
msgid "unable to read remotes in %s: %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:153
|
||||
#: ./cli/recipe/upgrade.go:156
|
||||
#, c-format
|
||||
msgid "unable to read tag for image %s, is it missing? skipping upgrade for %s"
|
||||
msgstr ""
|
||||
@@ -5381,6 +5396,11 @@ msgstr ""
|
||||
msgid "unable to retrieve container for %s: %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:193
|
||||
#, c-format
|
||||
msgid "unable to retrieve digest for %s: %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/app/list.go:157
|
||||
#, c-format
|
||||
msgid "unable to retrieve tags for %s: %s"
|
||||
@@ -5513,12 +5533,17 @@ msgstr ""
|
||||
msgid "up"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:397
|
||||
#, c-format
|
||||
msgid "update digest of %s:%s?"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/upstream/stack/stack.go:477
|
||||
#, c-format
|
||||
msgid "updating %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./pkg/recipe/compose.go:171 ./pkg/recipe/compose.go:237
|
||||
#: ./pkg/recipe/compose.go:213 ./pkg/recipe/compose.go:281
|
||||
#, c-format
|
||||
msgid "updating %s to %s in %s"
|
||||
msgstr ""
|
||||
@@ -5543,17 +5568,17 @@ msgstr ""
|
||||
msgid "upgrade [flags]"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:248
|
||||
#: ./cli/recipe/upgrade.go:258
|
||||
#, c-format
|
||||
msgid "upgrade to which tag? (service: %s, image: %s, tag: %s)"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:254
|
||||
#: ./cli/recipe/upgrade.go:264
|
||||
#, c-format
|
||||
msgid "upgrade to which tag? (service: %s, tag: %s)"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/upgrade.go:221
|
||||
#: ./cli/recipe/upgrade.go:231
|
||||
#, c-format
|
||||
msgid "upgrading service %s from %s to %s (pinned tag: %s)"
|
||||
msgstr ""
|
||||
@@ -5806,11 +5831,11 @@ msgstr ""
|
||||
msgid "writing recipe version failed: %s"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/release.go:632 ./cli/recipe/upgrade.go:376
|
||||
#: ./cli/recipe/release.go:632 ./cli/recipe/upgrade.go:427
|
||||
msgid "x"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/release.go:640 ./cli/recipe/upgrade.go:384
|
||||
#: ./cli/recipe/release.go:640 ./cli/recipe/upgrade.go:435
|
||||
msgid "y"
|
||||
msgstr ""
|
||||
|
||||
@@ -5822,7 +5847,7 @@ msgstr ""
|
||||
msgid "you can only use one version flag: --major, --minor or --patch"
|
||||
msgstr ""
|
||||
|
||||
#: ./cli/recipe/release.go:648 ./cli/recipe/upgrade.go:392
|
||||
#: ./cli/recipe/release.go:648 ./cli/recipe/upgrade.go:443
|
||||
msgid "z"
|
||||
msgstr ""
|
||||
|
||||
|
||||
+10
-102
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -21,11 +20,6 @@ import (
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
)
|
||||
|
||||
// SourceFile is the sidecar file written next to an externally-cloned
|
||||
// recipe so the canonical "host/path" name can be recovered later (the
|
||||
// on-disk directory name escapes "/" and "." to "_", which is lossy).
|
||||
const SourceFile = ".abra-source"
|
||||
|
||||
type EnsureContext struct {
|
||||
Chaos bool
|
||||
Offline bool
|
||||
@@ -65,7 +59,7 @@ func (r Recipe) Ensure(ctx EnsureContext) error {
|
||||
return errors.New(i18n.G(`cannot redeploy previous chaos version (%s), did you mean to use "--chaos"?`))
|
||||
}
|
||||
|
||||
if _, err := r.EnsureVersionCtx(ctx, r.EnvVersion); err != nil {
|
||||
if _, err := r.EnsureVersion(r.EnvVersion); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -85,12 +79,6 @@ func (r Recipe) EnsureExists() error {
|
||||
if err := gitPkg.Clone(r.Dir, r.GitURL); err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.Contains(r.Name, "/") {
|
||||
sidecar := path.Join(r.Dir, SourceFile)
|
||||
if err := os.WriteFile(sidecar, []byte(r.Name+"\n"), 0o644); err != nil {
|
||||
log.Debug(i18n.G("failed to write recipe source sidecar %s: %s", sidecar, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := gitPkg.EnsureGitRepo(r.Dir); err != nil {
|
||||
@@ -100,18 +88,6 @@ func (r Recipe) EnsureExists() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReadRecipeSource returns the canonical name recorded in the .abra-source
|
||||
// sidecar inside the given recipe directory, or the empty string if no
|
||||
// sidecar exists. This lets callers recover the unescaped "host/path"
|
||||
// form for externally-cloned recipes.
|
||||
func ReadRecipeSource(recipeDir string) string {
|
||||
data, err := os.ReadFile(path.Join(recipeDir, SourceFile))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(data))
|
||||
}
|
||||
|
||||
// IsChaosCommit determines if a version sttring is a chaos commit or not.
|
||||
func (r Recipe) IsChaosCommit(version string) (bool, error) {
|
||||
isChaosCommit := false
|
||||
@@ -149,13 +125,6 @@ func (r Recipe) IsChaosCommit(version string) (bool, error) {
|
||||
|
||||
// EnsureVersion checks whether a specific version exists for a recipe.
|
||||
func (r Recipe) EnsureVersion(version string) (bool, error) {
|
||||
return r.EnsureVersionCtx(EnsureContext{}, version)
|
||||
}
|
||||
|
||||
// EnsureVersionCtx is like EnsureVersion but is aware of the surrounding
|
||||
// EnsureContext, so that e.g. offline mode can skip network fetches when
|
||||
// resolving a branch name that isn't already available locally.
|
||||
func (r Recipe) EnsureVersionCtx(ctx EnsureContext, version string) (bool, error) {
|
||||
isChaosCommit := false
|
||||
|
||||
if err := gitPkg.EnsureGitRepo(r.Dir); err != nil {
|
||||
@@ -190,46 +159,30 @@ func (r Recipe) EnsureVersionCtx(ctx EnsureContext, version string) (bool, error
|
||||
}
|
||||
|
||||
var opts *git.CheckoutOptions
|
||||
var checkedOutRef string
|
||||
if tagRef.String() == "" {
|
||||
log.Debug(i18n.G("attempting to checkout '%s' as chaos commit", version))
|
||||
|
||||
hash, hashErr := repo.ResolveRevision(plumbing.Revision(version))
|
||||
if hashErr != nil {
|
||||
branchHash, found, branchErr := resolveBranch(repo, version, ctx.Offline)
|
||||
if errors.Is(branchErr, errOfflineBranchUnresolved) {
|
||||
return isChaosCommit, errors.New(i18n.G("'%s' is not available locally and cannot be fetched in offline mode; retry without --offline", version))
|
||||
}
|
||||
if branchErr != nil {
|
||||
return isChaosCommit, branchErr
|
||||
}
|
||||
if !found {
|
||||
return isChaosCommit, errors.New(i18n.G("unable to resolve '%s': %s", version, hashErr))
|
||||
}
|
||||
|
||||
opts = &git.CheckoutOptions{Hash: branchHash, Create: false, Force: true}
|
||||
isChaosCommit = true
|
||||
checkedOutRef = version
|
||||
} else {
|
||||
opts = &git.CheckoutOptions{Hash: *hash, Create: false, Force: true}
|
||||
isChaosCommit = true
|
||||
checkedOutRef = hash.String()
|
||||
hash, err := repo.ResolveRevision(plumbing.Revision(version))
|
||||
if err != nil {
|
||||
log.Fatal(i18n.G("unable to resolve '%s': %s", version, err))
|
||||
}
|
||||
|
||||
opts = &git.CheckoutOptions{Hash: *hash, Create: false, Force: true}
|
||||
isChaosCommit = true
|
||||
} else {
|
||||
opts = &git.CheckoutOptions{Branch: tagRef, Create: false, Force: true}
|
||||
checkedOutRef = tagRef.Short()
|
||||
}
|
||||
|
||||
worktree, err := repo.Worktree()
|
||||
if err != nil {
|
||||
return isChaosCommit, err
|
||||
return isChaosCommit, nil
|
||||
}
|
||||
|
||||
if err := worktree.Checkout(opts); err != nil {
|
||||
return isChaosCommit, err
|
||||
return isChaosCommit, nil
|
||||
}
|
||||
|
||||
log.Debug(i18n.G("successfully checked %s out to %s in %s", r.Name, checkedOutRef, r.Dir))
|
||||
log.Debug(i18n.G("successfully checked %s out to %s in %s", r.Name, tagRef.Short(), r.Dir))
|
||||
|
||||
return isChaosCommit, nil
|
||||
}
|
||||
@@ -532,51 +485,6 @@ func (r Recipe) GetRecipeVersions() (RecipeVersions, []string, error) {
|
||||
return versions, uniqueWarnings, nil
|
||||
}
|
||||
|
||||
// resolveBranch resolves name as a branch on the "origin" remote, fetching
|
||||
// it on demand into a remote-tracking ref (never into refs/heads/*, which
|
||||
// would corrupt GetDefaultBranch's local-branch-name heuristic). It returns
|
||||
// (hash, true, nil) if name is a branch, (_, false, nil) if name is
|
||||
// confirmed not to be a branch, and a non-nil error for any other failure
|
||||
// (e.g. network/auth issues) that should not be silently treated as "not a
|
||||
// branch". When offline is true, no fetch is attempted and only an
|
||||
// already-fetched remote-tracking ref is consulted.
|
||||
func resolveBranch(repo *git.Repository, name string, offline bool) (plumbing.Hash, bool, error) {
|
||||
remoteTrackingRef := plumbing.NewRemoteReferenceName("origin", name)
|
||||
|
||||
if !offline {
|
||||
refSpec := gitCfg.RefSpec(fmt.Sprintf("+refs/heads/%s:%s", name, remoteTrackingRef))
|
||||
err := repo.Fetch(&git.FetchOptions{
|
||||
RemoteName: "origin",
|
||||
RefSpecs: []gitCfg.RefSpec{refSpec},
|
||||
Force: true,
|
||||
})
|
||||
if err != nil {
|
||||
var noMatch git.NoMatchingRefSpecError
|
||||
switch {
|
||||
case errors.Is(err, git.NoErrAlreadyUpToDate):
|
||||
case errors.As(err, &noMatch):
|
||||
return plumbing.ZeroHash, false, nil
|
||||
default:
|
||||
return plumbing.ZeroHash, false, errors.New(i18n.G("unable to fetch branch '%s': %s", name, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ref, err := repo.Reference(remoteTrackingRef, true)
|
||||
if err != nil {
|
||||
if offline {
|
||||
return plumbing.ZeroHash, false, errOfflineBranchUnresolved
|
||||
}
|
||||
return plumbing.ZeroHash, false, errors.New(i18n.G("unable to resolve fetched branch '%s': %s", name, err))
|
||||
}
|
||||
|
||||
return ref.Hash(), true, nil
|
||||
}
|
||||
|
||||
// errOfflineBranchUnresolved is returned by resolveBranch when offline mode
|
||||
// prevents fetching a branch that isn't already available locally.
|
||||
var errOfflineBranchUnresolved = errors.New(i18n.G("not fetched and cannot resolve offline"))
|
||||
|
||||
// Head retrieves latest HEAD metadata.
|
||||
func (r Recipe) Head() (*plumbing.Reference, error) {
|
||||
repo, err := git.PlainOpen(r.Dir)
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"coopcloud.tech/abra/pkg/test"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -38,122 +36,3 @@ func TestIsDirty(t *testing.T) {
|
||||
|
||||
assert.True(t, dirty)
|
||||
}
|
||||
|
||||
func TestEnsureVersionBranch(t *testing.T) {
|
||||
test.SetupWithUpstream()
|
||||
t.Cleanup(func() { test.Teardown() })
|
||||
|
||||
upstream, err := git.PlainOpen(test.UpstreamRecipeDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
featureRef, err := upstream.Reference(plumbing.NewBranchReferenceName(test.FeatureBranch), true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := Get(test.RecipeName)
|
||||
|
||||
isChaosCommit, err := r.EnsureVersion(test.FeatureBranch)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.True(t, isChaosCommit)
|
||||
|
||||
head, err := r.Head()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, featureRef.Hash(), head.Hash())
|
||||
}
|
||||
|
||||
func TestEnsureVersionBranchRefetchesOnRedeploy(t *testing.T) {
|
||||
test.SetupWithUpstream()
|
||||
t.Cleanup(func() { test.Teardown() })
|
||||
|
||||
r := Get(test.RecipeName)
|
||||
|
||||
if _, err := r.EnsureVersion(test.FeatureBranch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := test.CreateBranchWithCommit(test.UpstreamRecipeDir, test.FeatureBranch, "feature2.txt", "more feature work"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
upstream, err := git.PlainOpen(test.UpstreamRecipeDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
featureRef, err := upstream.Reference(plumbing.NewBranchReferenceName(test.FeatureBranch), true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := r.EnsureVersion(test.FeatureBranch); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
head, err := r.Head()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, featureRef.Hash(), head.Hash())
|
||||
}
|
||||
|
||||
func TestEnsureVersionOfflineUnfetchedBranch(t *testing.T) {
|
||||
test.SetupWithUpstream()
|
||||
t.Cleanup(func() { test.Teardown() })
|
||||
|
||||
r := Get(test.RecipeName)
|
||||
|
||||
headBefore, err := r.Head()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = r.EnsureVersionCtx(EnsureContext{Offline: true}, test.FeatureBranch)
|
||||
assert.ErrorContains(t, err, "offline")
|
||||
|
||||
headAfter, err := r.Head()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, headBefore.Hash(), headAfter.Hash())
|
||||
}
|
||||
|
||||
func TestEnsureVersionUnknownNameErrors(t *testing.T) {
|
||||
test.SetupWithUpstream()
|
||||
t.Cleanup(func() { test.Teardown() })
|
||||
|
||||
r := Get(test.RecipeName)
|
||||
|
||||
_, err := r.EnsureVersion("does-not-exist-anywhere")
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestEnsureBranchPinnedRecipe(t *testing.T) {
|
||||
test.SetupWithUpstream()
|
||||
t.Cleanup(func() { test.Teardown() })
|
||||
|
||||
upstream, err := git.PlainOpen(test.UpstreamRecipeDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
featureRef, err := upstream.Reference(plumbing.NewBranchReferenceName(test.FeatureBranch), true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := Get(test.RecipeName + ":" + test.FeatureBranch)
|
||||
|
||||
if err := r.Ensure(EnsureContext{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
head, err := r.Head()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, featureRef.Hash(), head.Hash())
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -122,84 +121,7 @@ type Features struct {
|
||||
SSO string `json:"sso"`
|
||||
}
|
||||
|
||||
// scpURLPattern matches SCP-style git URLs like git@host:path or git@host:port/path.
|
||||
// Captures: 1=host(:port)?, 2=path.
|
||||
var scpURLPattern = regexp.MustCompile(`^[\w.-]+@([\w.-]+(?::\d+)?):(.+)$`)
|
||||
|
||||
// NormalizeRecipeName canonicalizes a recipe identifier to a stable
|
||||
// "host/path" form (or returns short catalog names unchanged). Accepts:
|
||||
//
|
||||
// - https://host/path[.git][:version]
|
||||
// - http://host/path[.git][:version]
|
||||
// - ssh://git@host[:port]/path[.git][:version]
|
||||
// - git@host:path[.git][:version] (SCP-style)
|
||||
// - host/path[.git][:version] (already canonical)
|
||||
// - short-name[:version] (catalog recipe, pass through)
|
||||
//
|
||||
// The optional trailing :version suffix is preserved verbatim. The .git
|
||||
// suffix and trailing slashes on the path are stripped so the four URL
|
||||
// forms of the same repository collapse to one canonical value.
|
||||
func NormalizeRecipeName(input string) string {
|
||||
input = strings.TrimSpace(input)
|
||||
|
||||
// Split off the version suffix first, but only if it's not part of a
|
||||
// scheme (https://) or SCP-style git@host: prefix. The simplest way is
|
||||
// to detect those prefixes and treat the rest as the path-with-version.
|
||||
var (
|
||||
body = input
|
||||
version string
|
||||
)
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(input, "https://") || strings.HasPrefix(input, "http://") || strings.HasPrefix(input, "ssh://"):
|
||||
u, err := url.Parse(input)
|
||||
if err != nil {
|
||||
return input
|
||||
}
|
||||
host := u.Hostname() // strip port to keep canonical form colon-free
|
||||
p := strings.TrimPrefix(u.Path, "/")
|
||||
p, version = splitVersion(p)
|
||||
body = host + "/" + p
|
||||
case scpURLPattern.MatchString(input):
|
||||
m := scpURLPattern.FindStringSubmatch(input)
|
||||
host := m[1]
|
||||
if i := strings.Index(host, ":"); i >= 0 {
|
||||
host = host[:i] // strip port
|
||||
}
|
||||
p, v := splitVersion(m[2])
|
||||
body = host + "/" + p
|
||||
version = v
|
||||
default:
|
||||
body, version = splitVersion(input)
|
||||
}
|
||||
|
||||
body = strings.TrimSuffix(body, "/")
|
||||
body = strings.TrimSuffix(body, ".git")
|
||||
|
||||
if version != "" {
|
||||
return body + ":" + version
|
||||
}
|
||||
return body
|
||||
}
|
||||
|
||||
// splitVersion separates a trailing ":version" suffix from a recipe path.
|
||||
// It only treats the final colon-separated segment as a version when it is
|
||||
// non-empty and contains no slash (a slash means the colon belonged to the
|
||||
// path, e.g. a host:port or scheme separator).
|
||||
func splitVersion(s string) (string, string) {
|
||||
idx := strings.LastIndex(s, ":")
|
||||
if idx < 0 {
|
||||
return s, ""
|
||||
}
|
||||
candidate := s[idx+1:]
|
||||
if candidate == "" || strings.Contains(candidate, "/") {
|
||||
return s, ""
|
||||
}
|
||||
return s[:idx], candidate
|
||||
}
|
||||
|
||||
func Get(name string) Recipe {
|
||||
name = NormalizeRecipeName(name)
|
||||
version := ""
|
||||
versionRaw := ""
|
||||
if strings.Contains(name, ":") {
|
||||
@@ -287,16 +209,6 @@ func (r Recipe) String() string {
|
||||
return out
|
||||
}
|
||||
|
||||
// ShortName returns the final path segment of the recipe name, i.e. the
|
||||
// bare recipe name without any "host/org/" prefix carried by externally
|
||||
// sourced (git URL) recipes. For catalogue recipes it returns Name unchanged.
|
||||
func (r Recipe) ShortName() string {
|
||||
if i := strings.LastIndex(r.Name, "/"); i >= 0 {
|
||||
return r.Name[i+1:]
|
||||
}
|
||||
return r.Name
|
||||
}
|
||||
|
||||
func escapeRecipeName(recipeName string) string {
|
||||
recipeName = strings.ReplaceAll(recipeName, "/", "_")
|
||||
recipeName = strings.ReplaceAll(recipeName, ".", "_")
|
||||
|
||||
@@ -88,88 +88,6 @@ func TestGet(t *testing.T) {
|
||||
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/abra.sh"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "https://mygit.org/myorg/cool-recipe",
|
||||
recipe: Recipe{
|
||||
Name: "mygit.org/myorg/cool-recipe",
|
||||
Dir: path.Join(cfg.GetAbraDir(), "/recipes/mygit_org_myorg_cool-recipe"),
|
||||
GitURL: "https://mygit.org/myorg/cool-recipe.git",
|
||||
SSHURL: "ssh://git@mygit.org/myorg/cool-recipe.git",
|
||||
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/compose.yml"),
|
||||
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/README.md"),
|
||||
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/.env.sample"),
|
||||
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/abra.sh"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "https://mygit.org/myorg/cool-recipe.git",
|
||||
recipe: Recipe{
|
||||
Name: "mygit.org/myorg/cool-recipe",
|
||||
Dir: path.Join(cfg.GetAbraDir(), "/recipes/mygit_org_myorg_cool-recipe"),
|
||||
GitURL: "https://mygit.org/myorg/cool-recipe.git",
|
||||
SSHURL: "ssh://git@mygit.org/myorg/cool-recipe.git",
|
||||
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/compose.yml"),
|
||||
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/README.md"),
|
||||
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/.env.sample"),
|
||||
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/abra.sh"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "https://mygit.org/myorg/cool-recipe.git:1.2.4",
|
||||
recipe: Recipe{
|
||||
Name: "mygit.org/myorg/cool-recipe",
|
||||
EnvVersion: "1.2.4",
|
||||
EnvVersionRaw: "1.2.4",
|
||||
Dir: path.Join(cfg.GetAbraDir(), "/recipes/mygit_org_myorg_cool-recipe"),
|
||||
GitURL: "https://mygit.org/myorg/cool-recipe.git",
|
||||
SSHURL: "ssh://git@mygit.org/myorg/cool-recipe.git",
|
||||
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/compose.yml"),
|
||||
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/README.md"),
|
||||
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/.env.sample"),
|
||||
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/abra.sh"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ssh://git@mygit.org/myorg/cool-recipe.git",
|
||||
recipe: Recipe{
|
||||
Name: "mygit.org/myorg/cool-recipe",
|
||||
Dir: path.Join(cfg.GetAbraDir(), "/recipes/mygit_org_myorg_cool-recipe"),
|
||||
GitURL: "https://mygit.org/myorg/cool-recipe.git",
|
||||
SSHURL: "ssh://git@mygit.org/myorg/cool-recipe.git",
|
||||
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/compose.yml"),
|
||||
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/README.md"),
|
||||
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/.env.sample"),
|
||||
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/abra.sh"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "git@mygit.org:myorg/cool-recipe.git",
|
||||
recipe: Recipe{
|
||||
Name: "mygit.org/myorg/cool-recipe",
|
||||
Dir: path.Join(cfg.GetAbraDir(), "/recipes/mygit_org_myorg_cool-recipe"),
|
||||
GitURL: "https://mygit.org/myorg/cool-recipe.git",
|
||||
SSHURL: "ssh://git@mygit.org/myorg/cool-recipe.git",
|
||||
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/compose.yml"),
|
||||
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/README.md"),
|
||||
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/.env.sample"),
|
||||
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/abra.sh"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "git@mygit.org:myorg/cool-recipe:1.2.4",
|
||||
recipe: Recipe{
|
||||
Name: "mygit.org/myorg/cool-recipe",
|
||||
EnvVersion: "1.2.4",
|
||||
EnvVersionRaw: "1.2.4",
|
||||
Dir: path.Join(cfg.GetAbraDir(), "/recipes/mygit_org_myorg_cool-recipe"),
|
||||
GitURL: "https://mygit.org/myorg/cool-recipe.git",
|
||||
SSHURL: "ssh://git@mygit.org/myorg/cool-recipe.git",
|
||||
ComposePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/compose.yml"),
|
||||
ReadmePath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/README.md"),
|
||||
SampleEnvPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/.env.sample"),
|
||||
AbraShPath: path.Join(cfg.GetAbraDir(), "recipes/mygit_org_myorg_cool-recipe/abra.sh"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
@@ -183,49 +101,6 @@ func TestGet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRecipeName(t *testing.T) {
|
||||
cases := []struct {
|
||||
in, want string
|
||||
}{
|
||||
// catalog short names pass through
|
||||
{"foo", "foo"},
|
||||
{"foo:1.2.3", "foo:1.2.3"},
|
||||
|
||||
// bare host/path form
|
||||
{"mygit.org/myorg/cool-recipe", "mygit.org/myorg/cool-recipe"},
|
||||
{"mygit.org/myorg/cool-recipe.git", "mygit.org/myorg/cool-recipe"},
|
||||
{"mygit.org/myorg/cool-recipe.git:1.2.3", "mygit.org/myorg/cool-recipe:1.2.3"},
|
||||
{"mygit.org/myorg/cool-recipe/", "mygit.org/myorg/cool-recipe"},
|
||||
|
||||
// https://
|
||||
{"https://mygit.org/myorg/cool-recipe", "mygit.org/myorg/cool-recipe"},
|
||||
{"https://mygit.org/myorg/cool-recipe.git", "mygit.org/myorg/cool-recipe"},
|
||||
{"https://mygit.org/myorg/cool-recipe.git:1.2.3", "mygit.org/myorg/cool-recipe:1.2.3"},
|
||||
{"http://mygit.org/myorg/cool-recipe", "mygit.org/myorg/cool-recipe"},
|
||||
|
||||
// ssh://, with and without port
|
||||
{"ssh://git@mygit.org/myorg/cool-recipe.git", "mygit.org/myorg/cool-recipe"},
|
||||
{"ssh://git@mygit.org:2222/myorg/cool-recipe.git", "mygit.org/myorg/cool-recipe"},
|
||||
|
||||
// SCP-style git@host:path
|
||||
{"git@mygit.org:myorg/cool-recipe", "mygit.org/myorg/cool-recipe"},
|
||||
{"git@mygit.org:myorg/cool-recipe.git", "mygit.org/myorg/cool-recipe"},
|
||||
{"git@mygit.org:myorg/cool-recipe:1.2.3", "mygit.org/myorg/cool-recipe:1.2.3"},
|
||||
|
||||
// whitespace
|
||||
{" https://mygit.org/myorg/cool-recipe ", "mygit.org/myorg/cool-recipe"},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.in, func(t *testing.T) {
|
||||
got := NormalizeRecipeName(tc.in)
|
||||
if got != tc.want {
|
||||
t.Errorf("NormalizeRecipeName(%q) = %q, want %q", tc.in, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetVersionLabelLocalDoesNotUseTimeoutLabel(t *testing.T) {
|
||||
test.Setup()
|
||||
t.Cleanup(func() { test.Teardown() })
|
||||
|
||||
@@ -8,9 +8,6 @@ import (
|
||||
|
||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||
"git.coopcloud.tech/toolshed/godotenv"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -79,126 +76,6 @@ func Setup() {
|
||||
}
|
||||
}
|
||||
|
||||
// UpstreamRecipeDir is the "remote" repo used by SetupWithUpstream, kept
|
||||
// outside recipes/ so Teardown's blanket removal of $ABRA_DIR still cleans
|
||||
// it up.
|
||||
var UpstreamRecipeDir = os.ExpandEnv("$ABRA_DIR/_upstream/test_recipe")
|
||||
|
||||
// FeatureBranch is the non-default branch created by SetupWithUpstream.
|
||||
const FeatureBranch = "feature"
|
||||
|
||||
// SetupWithUpstream is like Setup, but the recipe under $ABRA_DIR/recipes
|
||||
// is a real clone of a separate "upstream" repo (UpstreamRecipeDir) rather
|
||||
// than a git-inited copy of the fixture. The upstream repo additionally has
|
||||
// a FeatureBranch with one extra commit not present on main, so tests can
|
||||
// exercise resolving/fetching a non-default branch as a recipe :version.
|
||||
func SetupWithUpstream() {
|
||||
Teardown()
|
||||
|
||||
if err := os.Mkdir(os.ExpandEnv("$ABRA_DIR"), 0764); err != nil {
|
||||
if !os.IsExist(err) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Mkdir(os.ExpandEnv("$ABRA_DIR/servers"), 0700); err != nil {
|
||||
if !os.IsExist(err) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Mkdir(os.ExpandEnv("$ABRA_DIR/recipes"), 0764); err != nil {
|
||||
if !os.IsExist(err) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
serverSrcDir := os.ExpandEnv("$PWD/../../tests/resources/test_server")
|
||||
serverDestDir := os.ExpandEnv("$ABRA_DIR/servers/test_server")
|
||||
if err := os.CopyFS(serverDestDir, os.DirFS(serverSrcDir)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(path.Dir(UpstreamRecipeDir), 0764); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
recipeSrcDir := os.ExpandEnv("$PWD/../../tests/resources/test_recipe")
|
||||
if err := os.CopyFS(UpstreamRecipeDir, os.DirFS(recipeSrcDir)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(path.Join(UpstreamRecipeDir, ".env.sample"), []byte("TYPE=test_recipe\n"), 0o644); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := gitPkg.Init(UpstreamRecipeDir, true, "tester", "helo@coopcloud.tech"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := CreateBranchWithCommit(UpstreamRecipeDir, FeatureBranch, "feature.txt", "feature work"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
recipeDestDir := os.ExpandEnv("$ABRA_DIR/recipes/test_recipe")
|
||||
if err := gitPkg.Clone(recipeDestDir, UpstreamRecipeDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateBranchWithCommit checks out branchName in repoPath (creating it off
|
||||
// the current HEAD if it doesn't exist yet, or extending it if it does),
|
||||
// writes fileName with contents, commits it, then returns to the repo's
|
||||
// default branch (leaving the new commit reachable only via the branch's
|
||||
// ref, matching how a contributor would push a feature branch upstream
|
||||
// without switching the repo's HEAD away from main).
|
||||
func CreateBranchWithCommit(repoPath, branchName, fileName, contents string) error {
|
||||
repo, err := git.PlainOpen(repoPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
head, err := repo.Head()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
worktree, err := repo.Worktree()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
branchRef := plumbing.NewBranchReferenceName(branchName)
|
||||
create := true
|
||||
if _, err := repo.Reference(branchRef, true); err == nil {
|
||||
create = false
|
||||
}
|
||||
|
||||
checkoutOpts := &git.CheckoutOptions{Branch: branchRef, Create: create}
|
||||
if create {
|
||||
checkoutOpts.Hash = head.Hash()
|
||||
}
|
||||
if err := worktree.Checkout(checkoutOpts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.WriteFile(path.Join(repoPath, fileName), []byte(contents), 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := worktree.Add(fileName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := worktree.Commit(fileName, &git.CommitOptions{
|
||||
Author: &object.Signature{Name: "tester", Email: "helo@coopcloud.tech"},
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return worktree.Checkout(&git.CheckoutOptions{Branch: head.Name()})
|
||||
}
|
||||
|
||||
func AddEnv(envKey, envValue string) error {
|
||||
filePath := os.ExpandEnv(fmt.Sprintf("$ABRA_DIR/servers/%s/%s.env", ServerName, AppName))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user