refactor: PR feedback

This commit is contained in:
3wc
2025-09-09 13:18:26 -04:00
parent 34934cf62d
commit 076d522b1a
3 changed files with 18 additions and 20 deletions

View File

@ -208,7 +208,6 @@ checkout as-is. Recipe commit hashes are also supported as values for
}
// Show deploy overview
if err := internal.DeployOverview(
app,
deployedVersion,

View File

@ -39,11 +39,11 @@ func RemoveConfigs(cl *client.Client, ctx context.Context, configNames []string,
return nil
}
// GetConfigNameAndVersion parses a full config name like `app_example_com_someconf_v1` to extract name and version, ("someconf", "v1")
func GetConfigNameAndVersion(fullName string, stackName string) (string, string, error) {
name := strings.TrimPrefix(fullName, stackName+"_")
if lastUnderscore := strings.LastIndex(name, "_"); lastUnderscore != -1 {
return name[0:lastUnderscore], name[lastUnderscore+1:], nil
} else {
return "", "", errors.New(i18n.G("can't parse version from config '%s'", fullName))
}
return "", "", errors.New(i18n.G("can't parse version from config '%s'", fullName))
}

View File

@ -10,6 +10,7 @@ import (
"coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/envfile"
"coopcloud.tech/abra/pkg/formatter"
"coopcloud.tech/abra/pkg/i18n"
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/recipe"
"coopcloud.tech/abra/pkg/secret"
@ -72,7 +73,7 @@ func GetConfigsForStack(cl *dockerClient.Client, app appPkg.App) (map[string]str
} else {
// Just make sure the versions are the same..
if existingConfigVersion != configVersion {
log.Warnf("different versions for config '%s', '%s' and %s'", configBaseName, existingConfigVersion, configVersion)
log.Warnf(i18n.G( "different versions for config '%s', '%s' and %s'", configBaseName, existingConfigVersion, configVersion))
}
}
}
@ -119,7 +120,7 @@ func GetImagesForStack(cl *dockerClient.Client, app appPkg.App) (map[string]stri
} else {
// Just make sure the versions are the same..
if existingImageVersion != imageTag {
log.Warnf("different versions for image '%s', '%s' and %s'", imageBaseName, existingImageVersion, imageTag)
log.Warnf(i18n.G("different versions for image '%s', '%s' and %s'", imageBaseName, existingImageVersion, imageTag))
}
}
}
@ -129,7 +130,6 @@ func GetImagesForStack(cl *dockerClient.Client, app appPkg.App) (map[string]stri
}
func GatherSecretsForDeploy(cl *dockerClient.Client, app appPkg.App) ([]string, error) {
secStats, err := secret.PollSecretsStatus(cl, app)
if err != nil {
return nil, err
@ -154,32 +154,32 @@ func GatherConfigsForDeploy(cl *dockerClient.Client, app appPkg.App, compose *co
return nil, err
}
log.Debugf("Deployed config names: %v", currentConfigs)
log.Debugf(i18n.G("deployed config names: %v", currentConfigs))
// Get new configs from the compose specification
newConfigs := compose.Configs
var configInfo []string
for configName := range newConfigs {
log.Debugf("Searching abra.sh for version for %s", configName)
log.Debugf(i18n.G("searching abra.sh for version for %s", configName))
versionKey := strings.ToUpper(configName) + "_VERSION"
newVersion, exists := abraShEnv[versionKey]
if !exists {
log.Warnf("No version found for config %s", configName)
configInfo = append(configInfo, fmt.Sprintf("%s: ? (missing version)", configName))
log.Warnf(i18n.G("no version found for config %s", configName))
configInfo = append(configInfo, i18n.G("%s: ? (missing version)", configName))
continue
}
if currentVersion, exists := currentConfigs[configName]; exists {
if currentVersion == newVersion {
if showUnchanged {
configInfo = append(configInfo, fmt.Sprintf("%s: %s (unchanged)", configName, newVersion))
configInfo = append(configInfo, i18n.G("%s: %s (unchanged)", configName, newVersion))
}
} else {
configInfo = append(configInfo, fmt.Sprintf("%s: %s → %s", configName, currentVersion, newVersion))
configInfo = append(configInfo, i18n.G("%s: %s → %s", configName, currentVersion, newVersion))
}
} else {
configInfo = append(configInfo, fmt.Sprintf("%s: %s (new)", configName, newVersion))
configInfo = append(configInfo, i18n.G("%s: %s (new)", configName, newVersion))
}
}
@ -187,14 +187,13 @@ func GatherConfigsForDeploy(cl *dockerClient.Client, app appPkg.App, compose *co
}
func GatherImagesForDeploy(cl *dockerClient.Client, app appPkg.App, compose *composetypes.Config, showUnchanged bool) ([]string, error) {
// Get current images from existing deployment
currentImages, err := GetImagesForStack(cl, app)
if err != nil {
return nil, err
}
log.Debugf("Deployed images: %v", currentImages)
log.Debugf(i18n.G("deployed images: %v", currentImages))
// Proposed new images from the compose files
newImages := make(map[string]string)
@ -215,24 +214,24 @@ func GatherImagesForDeploy(cl *dockerClient.Client, app appPkg.App, compose *com
} else {
// Just make sure the versions are the same..
if existingImageVersion != imageTag {
log.Warnf("different versions for image '%s', '%s' and %s'", imageBaseName, existingImageVersion, imageTag)
log.Warnf(i18n.G("different versions for image '%s', '%s' and %s'", imageBaseName, existingImageVersion, imageTag))
}
}
}
log.Debugf("Proposed images: %v", newImages)
log.Debugf(i18n.G("proposed images: %v", newImages))
var imageInfo []string
for newImageName, newImageVersion := range newImages {
if currentVersion, exists := currentImages[newImageName]; exists {
if currentVersion == newImageVersion {
if showUnchanged {
imageInfo = append(imageInfo, fmt.Sprintf("%s: %s (unchanged)", formatter.StripTagMeta(newImageName), newImageVersion))
imageInfo = append(imageInfo, i18n.G("%s: %s (unchanged)", formatter.StripTagMeta(newImageName), newImageVersion))
}
} else {
imageInfo = append(imageInfo, fmt.Sprintf("%s: %s → %s", formatter.StripTagMeta(newImageName), currentVersion, newImageVersion))
imageInfo = append(imageInfo, i18n.G("%s: %s → %s", formatter.StripTagMeta(newImageName), currentVersion, newImageVersion))
}
} else {
imageInfo = append(imageInfo, fmt.Sprintf("%s: %s (new)", formatter.StripTagMeta(newImageName), newImageVersion))
imageInfo = append(imageInfo, i18n.G("%s: %s (new)", formatter.StripTagMeta(newImageName), newImageVersion))
}
}