refactor: use central logger

This commit is contained in:
2024-07-07 23:45:37 +02:00
parent cf8ff410cc
commit ef108d63e1
86 changed files with 903 additions and 889 deletions

View File

@ -17,11 +17,11 @@ import (
"coopcloud.tech/abra/pkg/upstream/convert"
"coopcloud.tech/abra/pkg/upstream/stack"
"coopcloud.tech/abra/pkg/log"
loader "coopcloud.tech/abra/pkg/upstream/stack"
composetypes "github.com/docker/cli/cli/compose/types"
"github.com/docker/docker/api/types/filters"
"github.com/schollz/progressbar/v3"
"github.com/sirupsen/logrus"
)
// Get retrieves an app
@ -36,7 +36,7 @@ func Get(appName string) (App, error) {
return App{}, err
}
logrus.Debugf("retrieved %s for %s", app, appName)
log.Debugf("retrieved %s for %s", app, appName)
return app, nil
}
@ -125,7 +125,7 @@ func StackName(appName string) string {
stackName := SanitiseAppName(appName)
if len(stackName) > config.MAX_SANITISED_APP_NAME_LENGTH {
logrus.Debugf("trimming %s to %s to avoid runtime limits", stackName, stackName[:config.MAX_SANITISED_APP_NAME_LENGTH])
log.Debugf("trimming %s to %s to avoid runtime limits", stackName, stackName[:config.MAX_SANITISED_APP_NAME_LENGTH])
stackName = stackName[:config.MAX_SANITISED_APP_NAME_LENGTH]
}
@ -235,7 +235,7 @@ func ReadAppEnvFile(appFile AppFile, name AppName) (App, error) {
return App{}, fmt.Errorf("env file for %s couldn't be read: %s", name, err.Error())
}
logrus.Debugf("read env %s from %s", env, appFile.Path)
log.Debugf("read env %s from %s", env, appFile.Path)
app, err := NewApp(env, name, appFile)
if err != nil {
@ -281,7 +281,7 @@ func LoadAppFiles(servers ...string) (AppFiles, error) {
}
}
logrus.Debugf("collecting metadata from %v servers: %s", len(servers), strings.Join(servers, ", "))
log.Debugf("collecting metadata from %v servers: %s", len(servers), strings.Join(servers, ", "))
for _, server := range servers {
serverDir := path.Join(config.SERVERS_DIR, server)
@ -387,7 +387,7 @@ func TemplateAppEnvSample(recipeName, appName, server, domain string) error {
return err
}
logrus.Debugf("copied & templated %s to %s", envSamplePath, appEnvPath)
log.Debugf("copied & templated %s to %s", envSamplePath, appEnvPath)
return nil
}
@ -472,7 +472,7 @@ func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]str
}
}
logrus.Debugf("retrieved app statuses: %s", statuses)
log.Debugf("retrieved app statuses: %s", statuses)
return statuses, nil
}
@ -486,7 +486,7 @@ func GetAppComposeConfig(recipe string, opts stack.Deploy, appEnv envfile.AppEnv
return &composetypes.Config{}, err
}
logrus.Debugf("retrieved %s for %s", compose.Filename, recipe)
log.Debugf("retrieved %s for %s", compose.Filename, recipe)
return compose, nil
}
@ -495,13 +495,13 @@ func GetAppComposeConfig(recipe string, opts stack.Deploy, appEnv envfile.AppEnv
func ExposeAllEnv(stackName string, compose *composetypes.Config, appEnv envfile.AppEnv) {
for _, service := range compose.Services {
if service.Name == "app" {
logrus.Debugf("Add the following environment to the app service config of %s:", stackName)
log.Debugf("Add the following environment to the app service config of %s:", stackName)
for k, v := range appEnv {
_, exists := service.Environment[k]
if !exists {
value := v
service.Environment[k] = &value
logrus.Debugf("Add Key: %s Value: %s to %s", k, value, stackName)
log.Debugf("Add Key: %s Value: %s to %s", k, value, stackName)
}
}
}
@ -570,9 +570,9 @@ func ReadAbraShCmdNames(abraSh string) ([]string, error) {
}
if len(cmdNames) > 0 {
logrus.Debugf("read %s from %s", strings.Join(cmdNames, " "), abraSh)
log.Debugf("read %s from %s", strings.Join(cmdNames, " "), abraSh)
} else {
logrus.Debugf("read 0 command names from %s", abraSh)
log.Debugf("read 0 command names from %s", abraSh)
}
return cmdNames, nil

View File

@ -5,8 +5,8 @@ import (
"strconv"
"coopcloud.tech/abra/pkg/envfile"
"coopcloud.tech/abra/pkg/log"
composetypes "github.com/docker/cli/cli/compose/types"
"github.com/sirupsen/logrus"
)
// SetRecipeLabel adds the label 'coop-cloud.${STACK_NAME}.recipe=${RECIPE}' to the app container
@ -14,7 +14,7 @@ import (
func SetRecipeLabel(compose *composetypes.Config, stackName string, recipe string) {
for _, service := range compose.Services {
if service.Name == "app" {
logrus.Debugf("set recipe label 'coop-cloud.%s.recipe' to %s for %s", stackName, recipe, stackName)
log.Debugf("set recipe label 'coop-cloud.%s.recipe' to %s for %s", stackName, recipe, stackName)
labelKey := fmt.Sprintf("coop-cloud.%s.recipe", stackName)
service.Deploy.Labels[labelKey] = recipe
}
@ -26,7 +26,7 @@ func SetRecipeLabel(compose *composetypes.Config, stackName string, recipe strin
func SetChaosLabel(compose *composetypes.Config, stackName string, chaos bool) {
for _, service := range compose.Services {
if service.Name == "app" {
logrus.Debugf("set label 'coop-cloud.%s.chaos' to %v for %s", stackName, chaos, stackName)
log.Debugf("set label 'coop-cloud.%s.chaos' to %v for %s", stackName, chaos, stackName)
labelKey := fmt.Sprintf("coop-cloud.%s.chaos", stackName)
service.Deploy.Labels[labelKey] = strconv.FormatBool(chaos)
}
@ -37,7 +37,7 @@ func SetChaosLabel(compose *composetypes.Config, stackName string, chaos bool) {
func SetChaosVersionLabel(compose *composetypes.Config, stackName string, chaosVersion string) {
for _, service := range compose.Services {
if service.Name == "app" {
logrus.Debugf("set label 'coop-cloud.%s.chaos-version' to %v for %s", stackName, chaosVersion, stackName)
log.Debugf("set label 'coop-cloud.%s.chaos-version' to %v for %s", stackName, chaosVersion, stackName)
labelKey := fmt.Sprintf("coop-cloud.%s.chaos-version", stackName)
service.Deploy.Labels[labelKey] = chaosVersion
}
@ -54,7 +54,7 @@ func SetUpdateLabel(compose *composetypes.Config, stackName string, appEnv envfi
if !exists {
enable_auto_update = "false"
}
logrus.Debugf("set label 'coop-cloud.%s.autoupdate' to %s for %s", stackName, enable_auto_update, stackName)
log.Debugf("set label 'coop-cloud.%s.autoupdate' to %s for %s", stackName, enable_auto_update, stackName)
labelKey := fmt.Sprintf("coop-cloud.%s.autoupdate", stackName)
service.Deploy.Labels[labelKey] = enable_auto_update
}
@ -66,13 +66,13 @@ func GetLabel(compose *composetypes.Config, stackName string, label string) stri
for _, service := range compose.Services {
if service.Name == "app" {
labelKey := fmt.Sprintf("coop-cloud.%s.%s", stackName, label)
logrus.Debugf("get label '%s'", labelKey)
log.Debugf("get label '%s'", labelKey)
if labelValue, ok := service.Deploy.Labels[labelKey]; ok {
return labelValue
}
}
}
logrus.Debugf("no %s label found for %s", label, stackName)
log.Debugf("no %s label found for %s", label, stackName)
return ""
}
@ -81,7 +81,7 @@ func GetTimeoutFromLabel(compose *composetypes.Config, stackName string) (int, e
timeout := 50 // Default Timeout
var err error = nil
if timeoutLabel := GetLabel(compose, stackName, "timeout"); timeoutLabel != "" {
logrus.Debugf("timeout label: %s", timeoutLabel)
log.Debugf("timeout label: %s", timeoutLabel)
timeout, err = strconv.Atoi(timeoutLabel)
}
return timeout, err

View File

@ -4,8 +4,8 @@ import (
"fmt"
"coopcloud.tech/abra/pkg/app"
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/recipe"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@ -13,7 +13,7 @@ import (
func AppNameComplete(c *cli.Context) {
appNames, err := app.GetAppNames()
if err != nil {
logrus.Warn(err)
log.Warn(err)
}
if c.NArg() > 0 {
@ -39,7 +39,7 @@ func ServiceNameComplete(appName string) {
func RecipeNameComplete(c *cli.Context) {
catl, err := recipe.ReadRecipeCatalogue(false)
if err != nil {
logrus.Warn(err)
log.Warn(err)
}
if c.NArg() > 0 {
@ -55,7 +55,7 @@ func RecipeNameComplete(c *cli.Context) {
func RecipeVersionComplete(recipeName string) {
catl, err := recipe.ReadRecipeCatalogue(false)
if err != nil {
logrus.Warn(err)
log.Warn(err)
}
for _, v := range catl[recipeName].Versions {
@ -69,7 +69,7 @@ func RecipeVersionComplete(recipeName string) {
func ServerNameComplete(c *cli.Context) {
files, err := app.LoadAppFiles("")
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
if c.NArg() > 0 {

View File

@ -8,21 +8,21 @@ import (
"coopcloud.tech/abra/pkg/config"
gitPkg "coopcloud.tech/abra/pkg/git"
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
"github.com/sirupsen/logrus"
)
// EnsureCatalogue ensures that the catalogue is cloned locally & present.
func EnsureCatalogue() error {
catalogueDir := path.Join(config.ABRA_DIR, "catalogue")
if _, err := os.Stat(catalogueDir); err != nil && os.IsNotExist(err) {
logrus.Warnf("local recipe catalogue is missing, retrieving now")
log.Warnf("local recipe catalogue is missing, retrieving now")
url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, config.CATALOGUE_JSON_REPO_NAME)
if err := gitPkg.Clone(catalogueDir, url); err != nil {
return err
}
logrus.Debugf("cloned catalogue repository to %s", catalogueDir)
log.Debugf("cloned catalogue repository to %s", catalogueDir)
}
return nil
@ -57,7 +57,7 @@ func EnsureUpToDate() error {
if len(remotes) == 0 {
msg := "cannot ensure %s is up-to-date, no git remotes configured"
logrus.Debugf(msg, config.CATALOGUE_DIR)
log.Debugf(msg, config.CATALOGUE_DIR)
return nil
}
@ -82,7 +82,7 @@ func EnsureUpToDate() error {
}
}
logrus.Debugf("fetched latest git changes for %s", config.CATALOGUE_DIR)
log.Debugf("fetched latest git changes for %s", config.CATALOGUE_DIR)
return nil
}

View File

@ -10,10 +10,10 @@ import (
"time"
contextPkg "coopcloud.tech/abra/pkg/context"
"coopcloud.tech/abra/pkg/log"
sshPkg "coopcloud.tech/abra/pkg/ssh"
commandconnPkg "coopcloud.tech/abra/pkg/upstream/commandconn"
"github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)
// Conf is a Docker client configuration.
@ -85,7 +85,7 @@ func New(serverName string, opts ...Opt) (*client.Client, error) {
return nil, err
}
logrus.Debugf("created client for %s", serverName)
log.Debugf("created client for %s", serverName)
info, err := cl.Info(context.Background())
if err != nil {

View File

@ -5,11 +5,11 @@ import (
"fmt"
"coopcloud.tech/abra/pkg/context"
"coopcloud.tech/abra/pkg/log"
commandconnPkg "coopcloud.tech/abra/pkg/upstream/commandconn"
dConfig "github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/context/docker"
contextStore "github.com/docker/cli/cli/context/store"
"github.com/sirupsen/logrus"
)
type Context = contextStore.Metadata
@ -22,7 +22,7 @@ func CreateContext(contextName string) error {
return err
}
logrus.Debugf("created the %s context", contextName)
log.Debugf("created the %s context", contextName)
return nil
}

View File

@ -5,10 +5,10 @@ import (
"fmt"
"time"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)
func GetVolumes(cl *client.Client, ctx context.Context, server string, fs filters.Args) ([]*volume.Volume, error) {
@ -54,7 +54,7 @@ func retryFunc(retries int, fn func() error) error {
}
if i+1 < retries {
sleep := time.Duration(i+1) * time.Duration(i+1)
logrus.Infof("%s: waiting %d seconds before next retry", err, sleep)
log.Infof("%s: waiting %d seconds before next retry", err, sleep)
time.Sleep(sleep * time.Second)
}
}

View File

@ -10,11 +10,11 @@ import (
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/envfile"
"coopcloud.tech/abra/pkg/formatter"
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/upstream/stack"
loader "coopcloud.tech/abra/pkg/upstream/stack"
"github.com/distribution/reference"
composetypes "github.com/docker/cli/cli/compose/types"
"github.com/sirupsen/logrus"
)
// UpdateTag updates an image tag in-place on file system local compose files.
@ -24,7 +24,7 @@ func UpdateTag(pattern, image, tag, recipeName string) (bool, error) {
return false, err
}
logrus.Debugf("considering %s config(s) for tag update", strings.Join(composeFiles, ", "))
log.Debugf("considering %s config(s) for tag update", strings.Join(composeFiles, ", "))
for _, composeFile := range composeFiles {
opts := stack.Deploy{Composefiles: []string{composeFile}}
@ -55,13 +55,13 @@ func UpdateTag(pattern, image, tag, recipeName string) (bool, error) {
case reference.NamedTagged:
composeTag = img.(reference.NamedTagged).Tag()
default:
logrus.Debugf("unable to parse %s, skipping", img)
log.Debugf("unable to parse %s, skipping", img)
continue
}
composeImage := formatter.StripTagMeta(reference.Path(img))
logrus.Debugf("parsed %s from %s", composeTag, service.Image)
log.Debugf("parsed %s from %s", composeTag, service.Image)
if image == composeImage {
bytes, err := ioutil.ReadFile(composeFile)
@ -73,7 +73,7 @@ func UpdateTag(pattern, image, tag, recipeName string) (bool, error) {
new := fmt.Sprintf("%s:%s", composeImage, tag)
replacedBytes := strings.Replace(string(bytes), old, new, -1)
logrus.Debugf("updating %s to %s in %s", old, new, compose.Filename)
log.Debugf("updating %s to %s in %s", old, new, compose.Filename)
if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0764); err != nil {
return false, err
@ -92,7 +92,7 @@ func UpdateLabel(pattern, serviceName, label, recipeName string) error {
return err
}
logrus.Debugf("considering %s config(s) for label update", strings.Join(composeFiles, ", "))
log.Debugf("considering %s config(s) for label update", strings.Join(composeFiles, ", "))
for _, composeFile := range composeFiles {
opts := stack.Deploy{Composefiles: []string{composeFile}}
@ -135,23 +135,23 @@ func UpdateLabel(pattern, serviceName, label, recipeName string) error {
replacedBytes := strings.Replace(string(bytes), old, label, -1)
if old == label {
logrus.Warnf("%s is already set, nothing to do?", label)
log.Warnf("%s is already set, nothing to do?", label)
return nil
}
logrus.Debugf("updating %s to %s in %s", old, label, compose.Filename)
log.Debugf("updating %s to %s in %s", old, label, compose.Filename)
if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0764); err != nil {
return err
}
logrus.Infof("synced label %s to service %s", label, serviceName)
log.Infof("synced label %s to service %s", label, serviceName)
}
}
if !discovered {
logrus.Warn("no existing label found, automagic insertion not supported yet")
logrus.Fatalf("add '- \"%s\"' manually to the 'app' service in %s", label, composeFile)
log.Warn("no existing label found, automagic insertion not supported yet")
log.Fatalf("add '- \"%s\"' manually to the 'app' service in %s", label, composeFile)
}
}

View File

@ -5,7 +5,7 @@ import (
"path"
"path/filepath"
"github.com/sirupsen/logrus"
"coopcloud.tech/abra/pkg/log"
"gopkg.in/yaml.v3"
)
@ -16,13 +16,13 @@ func LoadAbraConfig() Abra {
wd, _ := os.Getwd()
configFile := findAbraConfig(wd)
if configFile == "" {
logrus.Debugf("no config file found")
log.Debugf("no config file found")
return Abra{}
}
data, err := os.ReadFile(configFile)
if err != nil {
// Do nothing, when an error occurs
logrus.Debugf("error reading config file: %s", err)
log.Debugf("error reading config file: %s", err)
return Abra{}
}
@ -30,10 +30,10 @@ func LoadAbraConfig() Abra {
err = yaml.Unmarshal(data, &config)
if err != nil {
// Do nothing, when an error occurs
logrus.Debugf("error loading config file: %s", err)
log.Debugf("error loading config file: %s", err)
return Abra{}
}
logrus.Debugf("config file loaded from: %s", configFile)
log.Debugf("config file loaded from: %s", configFile)
config.configPath = configFile
return config
}
@ -73,18 +73,18 @@ type Abra struct {
// 3. use $HOME/.abra when above two options failed
func (a Abra) GetAbraDir() string {
if dir, exists := os.LookupEnv("ABRA_DIR"); exists && dir != "" {
logrus.Debug("read abra dir from $ABRA_DIR")
log.Debug("read abra dir from $ABRA_DIR")
return dir
}
if a.AbraDir != "" {
logrus.Debug("read abra dir from config file")
log.Debug("read abra dir from config file")
if path.IsAbs(a.AbraDir) {
return a.AbraDir
}
// Make the path absolute
return path.Join(a.configPath, a.AbraDir)
}
logrus.Debug("using default abra dir")
log.Debug("using default abra dir")
return os.ExpandEnv("$HOME/.abra")
}

View File

@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"
"github.com/sirupsen/logrus"
"coopcloud.tech/abra/pkg/log"
)
const MAX_SANITISED_APP_NAME_LENGTH = 45
@ -26,7 +26,7 @@ func GetServers() ([]string, error) {
return servers, err
}
logrus.Debugf("retrieved %v servers: %s", len(servers), servers)
log.Debugf("retrieved %v servers: %s", len(servers), servers)
return servers, nil
}
@ -39,7 +39,7 @@ func ReadServerNames() ([]string, error) {
return nil, err
}
logrus.Debugf("read %s from %s", strings.Join(serverNames, ","), SERVERS_DIR)
log.Debugf("read %s from %s", strings.Join(serverNames, ","), SERVERS_DIR)
return serverNames, nil
}
@ -63,7 +63,7 @@ func GetAllFilesInDirectory(directory string) ([]fs.FileInfo, error) {
realPath, err := filepath.EvalSymlinks(filePath)
if err != nil {
logrus.Warningf("broken symlink in your abra config folders: %s", filePath)
log.Warnf("broken symlink in your abra config folders: %s", filePath)
} else {
realFile, err := os.Stat(realPath)
if err != nil {
@ -96,7 +96,7 @@ func GetAllFoldersInDirectory(directory string) ([]string, error) {
filePath := path.Join(directory, file.Name())
realDir, err := filepath.EvalSymlinks(filePath)
if err != nil {
logrus.Warningf("broken symlink in your abra config folders: %s", filePath)
log.Warnf("broken symlink in your abra config folders: %s", filePath)
} else if stat, err := os.Stat(realDir); err == nil && stat.IsDir() {
// path is a directory
folders = append(folders, file.Name())

View File

@ -6,12 +6,12 @@ import (
"strings"
"coopcloud.tech/abra/pkg/formatter"
"coopcloud.tech/abra/pkg/log"
"github.com/AlecAivazis/survey/v2"
"github.com/docker/docker/api/types"
containerTypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)
// GetContainer retrieves a container. If noInput is false and the retrievd
@ -43,7 +43,7 @@ func GetContainer(c context.Context, cl *client.Client, filters filters.Args, no
return types.Container{}, err
}
logrus.Warnf("ambiguous container list received, prompting for input")
log.Warnf("ambiguous container list received, prompting for input")
var response string
prompt := &survey.Select{
@ -64,7 +64,7 @@ func GetContainer(c context.Context, cl *client.Client, filters filters.Args, no
}
}
logrus.Panic("failed to match chosen container")
log.Fatal("failed to match chosen container")
}
return containers[0], nil

View File

@ -7,8 +7,8 @@ import (
"regexp"
"strings"
"coopcloud.tech/abra/pkg/log"
"git.coopcloud.tech/coop-cloud/godotenv"
"github.com/sirupsen/logrus"
)
// envVarModifiers is a list of env var modifier strings. These are added to
@ -31,7 +31,7 @@ func ReadEnv(filePath string) (AppEnv, error) {
return nil, err
}
logrus.Debugf("read %s from %s", envVars, filePath)
log.Debugf("read %s from %s", envVars, filePath)
return envVars, nil
}
@ -45,7 +45,7 @@ func ReadEnvWithModifiers(filePath string) (AppEnv, AppModifiers, error) {
return nil, mods, err
}
logrus.Debugf("read %s from %s", envVars, filePath)
log.Debugf("read %s from %s", envVars, filePath)
return envVars, mods, nil
}
@ -83,9 +83,9 @@ func ReadAbraShEnvVars(abraSh string) (map[string]string, error) {
}
if len(envVars) > 0 {
logrus.Debugf("read %s from %s", envVars, abraSh)
log.Debugf("read %s from %s", envVars, abraSh)
} else {
logrus.Debugf("read 0 env var exports from %s", abraSh)
log.Debugf("read 0 env var exports from %s", abraSh)
}
return envVars, nil

View File

@ -9,8 +9,8 @@ import (
"github.com/docker/go-units"
// "github.com/olekukonko/tablewriter"
"coopcloud.tech/abra/pkg/jsontable"
"coopcloud.tech/abra/pkg/log"
"github.com/schollz/progressbar/v3"
"github.com/sirupsen/logrus"
)
func ShortenID(str string) string {
@ -66,7 +66,7 @@ func StripTagMeta(image string) string {
}
if originalImage != image {
logrus.Debugf("stripped %s to %s for parsing", originalImage, image)
log.Debugf("stripped %s to %s for parsing", originalImage, image)
}
return image

View File

@ -1,8 +1,8 @@
package git
import (
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
"github.com/sirupsen/logrus"
)
// Add adds a file to the git index.
@ -18,7 +18,7 @@ func Add(repoPath, path string, dryRun bool) error {
}
if dryRun {
logrus.Debugf("dry run: adding %s", path)
log.Debugf("dry run: adding %s", path)
} else {
worktree.Add(path)
}

View File

@ -3,9 +3,9 @@ package git
import (
"fmt"
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/sirupsen/logrus"
)
// Check if a branch exists in a repo. Use this and not repository.Branch(),
@ -90,11 +90,11 @@ func CheckoutDefaultBranch(repo *git.Repository, repoPath string) (plumbing.Refe
}
if err := worktree.Checkout(checkOutOpts); err != nil {
logrus.Debugf("failed to check out %s in %s", branch, repoPath)
log.Debugf("failed to check out %s in %s", branch, repoPath)
return branch, err
}
logrus.Debugf("successfully checked out %v in %s", branch, repoPath)
log.Debugf("successfully checked out %v in %s", branch, repoPath)
return branch, nil
}

View File

@ -6,15 +6,15 @@ import (
"path/filepath"
"strings"
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/sirupsen/logrus"
)
// Clone runs a git clone which accounts for different default branches.
func Clone(dir, url string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) {
logrus.Debugf("%s does not exist, attempting to git clone from %s", dir, url)
log.Debugf("%s does not exist, attempting to git clone from %s", dir, url)
_, err := git.PlainClone(dir, false, &git.CloneOptions{
URL: url,
@ -23,7 +23,7 @@ func Clone(dir, url string) error {
SingleBranch: true,
})
if err != nil {
logrus.Debugf("cloning %s default branch failed, attempting from main branch", url)
log.Debugf("cloning %s default branch failed, attempting from main branch", url)
_, err := git.PlainClone(dir, false, &git.CloneOptions{
URL: url,
@ -41,9 +41,9 @@ func Clone(dir, url string) error {
}
}
logrus.Debugf("%s has been git cloned successfully", dir)
log.Debugf("%s has been git cloned successfully", dir)
} else {
logrus.Debugf("%s already exists", dir)
log.Debugf("%s already exists", dir)
}
return nil

View File

@ -3,8 +3,8 @@ package git
import (
"fmt"
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
"github.com/sirupsen/logrus"
)
// Commit runs a git commit
@ -38,9 +38,9 @@ func Commit(repoPath, commitMessage string, dryRun bool) error {
if err != nil {
return err
}
logrus.Debug("git changes commited")
log.Debug("git changes commited")
} else {
logrus.Debug("dry run: no changes commited")
log.Debug("dry run: no changes commited")
}
return nil

View File

@ -4,7 +4,7 @@ import (
"fmt"
"os/exec"
"github.com/sirupsen/logrus"
"coopcloud.tech/abra/pkg/log"
)
// getGitDiffArgs builds the `git diff` invocation args. It removes the usage
@ -26,7 +26,7 @@ func getGitDiffArgs(repoPath string) []string {
// skips if it cannot find the command on the system.
func DiffUnstaged(path string) error {
if _, err := exec.LookPath("git"); err != nil {
logrus.Warnf("unable to locate git command, cannot output diff")
log.Warnf("unable to locate git command, cannot output diff")
return nil
}

View File

@ -3,9 +3,9 @@ package git
import (
"fmt"
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/sirupsen/logrus"
)
// Init inits a new repo and commits all the stuff if you want
@ -13,7 +13,7 @@ func Init(repoPath string, commit bool, gitName, gitEmail string) error {
if _, err := git.PlainInit(repoPath, false); err != nil {
return fmt.Errorf("git init: %s", err)
}
logrus.Debugf("initialised new git repo in %s", repoPath)
log.Debugf("initialised new git repo in %s", repoPath)
if commit {
commitRepo, err := git.PlainOpen(repoPath)
@ -37,7 +37,7 @@ func Init(repoPath string, commit bool, gitName, gitEmail string) error {
if _, err = commitWorktree.Commit("init", &git.CommitOptions{Author: author}); err != nil {
return fmt.Errorf("git commit: %s", err)
}
logrus.Debugf("init committed all files for new git repo in %s", repoPath)
log.Debugf("init committed all files for new git repo in %s", repoPath)
}
return nil

View File

@ -1,15 +1,15 @@
package git
import (
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/sirupsen/logrus"
)
// Push pushes the latest changes & optionally tags to the default remote
func Push(repoDir string, remote string, tags bool, dryRun bool) error {
if dryRun {
logrus.Debugf("dry run: no git changes pushed in %s", repoDir)
log.Debugf("dry run: no git changes pushed in %s", repoDir)
return nil
}
@ -27,7 +27,7 @@ func Push(repoDir string, remote string, tags bool, dryRun bool) error {
return err
}
logrus.Debugf("git changes pushed")
log.Debugf("git changes pushed")
if tags {
opts.RefSpecs = append(opts.RefSpecs, config.RefSpec("+refs/tags/*:refs/tags/*"))
@ -36,7 +36,7 @@ func Push(repoDir string, remote string, tags bool, dryRun bool) error {
return err
}
logrus.Debugf("git tags pushed")
log.Debugf("git tags pushed")
}
return nil

View File

@ -9,11 +9,11 @@ import (
"strings"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
gitConfigPkg "github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/gitignore"
"github.com/sirupsen/logrus"
)
// GetRecipeHead retrieves latest HEAD metadata.
@ -60,9 +60,9 @@ func IsClean(repoPath string) (bool, error) {
}
if status.String() != "" {
logrus.Debugf("discovered git status in %s: %s", repoPath, status.String())
log.Debugf("discovered git status in %s: %s", repoPath, status.String())
} else {
logrus.Debugf("discovered clean git status in %s", repoPath)
log.Debugf("discovered clean git status in %s", repoPath)
}
return status.IsClean(), nil
@ -98,7 +98,7 @@ func parseGitConfig() (*gitConfigPkg.Config, error) {
globalGitConfig := filepath.Join(usr.HomeDir, ".gitconfig")
if _, err := os.Stat(globalGitConfig); err != nil {
if os.IsNotExist(err) {
logrus.Debugf("no %s exists, not reading any global gitignore config", globalGitConfig)
log.Debugf("no %s exists, not reading any global gitignore config", globalGitConfig)
return cfg, nil
}
return cfg, err
@ -140,7 +140,7 @@ func parseExcludesFile(excludesfile string) ([]gitignore.Pattern, error) {
if _, err := os.Stat(excludesfile); err != nil {
if os.IsNotExist(err) {
logrus.Debugf("no %s exists, skipping reading gitignore paths", excludesfile)
log.Debugf("no %s exists, skipping reading gitignore paths", excludesfile)
return ps, nil
}
return ps, err
@ -159,7 +159,7 @@ func parseExcludesFile(excludesfile string) ([]gitignore.Pattern, error) {
}
}
logrus.Debugf("read global ignore paths: %s", strings.Join(pathsRaw, " "))
log.Debugf("read global ignore paths: %s", strings.Join(pathsRaw, " "))
return ps, nil
}

View File

@ -3,15 +3,15 @@ package git
import (
"strings"
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/sirupsen/logrus"
)
// CreateRemote creates a new git remote in a repository
func CreateRemote(repo *git.Repository, name, url string, dryRun bool) error {
if dryRun {
logrus.Debugf("dry run: remote %s (%s) not created", name, url)
log.Debugf("dry run: remote %s (%s) not created", name, url)
return nil
}

View File

@ -8,13 +8,13 @@ import (
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/envfile"
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/recipe"
recipePkg "coopcloud.tech/abra/pkg/recipe"
"coopcloud.tech/tagcmp"
"github.com/distribution/reference"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/sirupsen/logrus"
)
var Warn = "warn"
@ -47,10 +47,10 @@ func (l LintRule) Skip(recipe recipe.Recipe) bool {
if l.SkipCondition != nil {
ok, err := l.SkipCondition(recipe)
if err != nil {
logrus.Debugf("%s: skip condition: %s", l.Ref, err)
log.Debugf("%s: skip condition: %s", l.Ref, err)
}
if ok {
logrus.Debugf("skipping %s based on skip condition", l.Ref)
log.Debugf("skipping %s based on skip condition", l.Ref)
return true
}
}
@ -175,7 +175,7 @@ var LintRules = map[string][]LintRule{
// used in code paths such as "app deploy" to avoid nasty surprises but not for
// the typical linting commands, which do handle other levels.
func LintForErrors(recipe recipe.Recipe) error {
logrus.Debugf("linting for critical errors in %s configs", recipe.Name)
log.Debugf("linting for critical errors in %s configs", recipe.Name)
for level := range LintRules {
if level != "error" {
@ -197,7 +197,7 @@ func LintForErrors(recipe recipe.Recipe) error {
}
}
logrus.Debugf("linting successful, %s is well configured", recipe.Name)
log.Debugf("linting successful, %s is well configured", recipe.Name)
return nil
}
@ -343,12 +343,12 @@ func LintImagePresent(recipe recipe.Recipe) (bool, error) {
func LintHasPublishedVersion(recipe recipe.Recipe) (bool, error) {
catl, err := recipePkg.ReadRecipeCatalogue(false)
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
versions, err := recipePkg.GetRecipeCatalogueVersions(recipe.Name, catl)
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
if len(versions) == 0 {
@ -429,7 +429,7 @@ func LintValidTags(recipe recipe.Recipe) (bool, error) {
iter, err := repo.Tags()
if err != nil {
logrus.Fatalf("unable to list local tags for %s", recipe.Name)
log.Fatalf("unable to list local tags for %s", recipe.Name)
}
if err := iter.ForEach(func(ref *plumbing.Reference) error {

View File

@ -19,6 +19,7 @@ import (
"coopcloud.tech/abra/pkg/formatter"
gitPkg "coopcloud.tech/abra/pkg/git"
"coopcloud.tech/abra/pkg/limit"
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/upstream/stack"
loader "coopcloud.tech/abra/pkg/upstream/stack"
"coopcloud.tech/abra/pkg/web"
@ -27,7 +28,6 @@ import (
composetypes "github.com/docker/cli/cli/compose/types"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/sirupsen/logrus"
)
// RecipeCatalogueURL is the only current recipe catalogue available.
@ -81,7 +81,7 @@ func (r RecipeMeta) LatestVersion() string {
version = tag
}
logrus.Debugf("choosing %s as latest version of %s", version, r.Name)
log.Debugf("choosing %s as latest version of %s", version, r.Name)
return version
}
@ -206,7 +206,7 @@ func (r Recipe) Tags() ([]string, error) {
return tags, err
}
logrus.Debugf("detected %s as tags for recipe %s", strings.Join(tags, ", "), r.Name)
log.Debugf("detected %s as tags for recipe %s", strings.Join(tags, ", "), r.Name)
return tags, nil
}
@ -284,7 +284,7 @@ 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)
log.Debugf("%s does not exist, attemmpting to clone", recipeDir)
url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipeName)
if err := gitPkg.Clone(recipeDir, url); err != nil {
return err
@ -330,7 +330,7 @@ func EnsureVersion(recipeName, version string) error {
joinedTags := strings.Join(parsedTags, ", ")
if joinedTags != "" {
logrus.Debugf("read %s as tags for recipe %s", joinedTags, recipeName)
log.Debugf("read %s as tags for recipe %s", joinedTags, recipeName)
}
if tagRef.String() == "" {
@ -351,7 +351,7 @@ func EnsureVersion(recipeName, version string) error {
return err
}
logrus.Debugf("successfully checked %s out to %s in %s", recipeName, tagRef.Short(), recipeDir)
log.Debugf("successfully checked %s out to %s in %s", recipeName, tagRef.Short(), recipeDir)
return nil
}
@ -403,7 +403,7 @@ func EnsureLatest(recipeName string) error {
}
if err := worktree.Checkout(checkOutOpts); err != nil {
logrus.Debugf("failed to check out %s in %s", branch, recipeDir)
log.Debugf("failed to check out %s in %s", branch, recipeDir)
return err
}
@ -472,7 +472,7 @@ func GetRecipeFeaturesAndCategory(recipeName string) (Features, string, error) {
readmePath := path.Join(config.RECIPES_DIR, recipeName, "README.md")
logrus.Debugf("attempting to open %s for recipe metadata parsing", readmePath)
log.Debugf("attempting to open %s for recipe metadata parsing", readmePath)
readmeFS, err := ioutil.ReadFile(readmePath)
if err != nil {
@ -553,9 +553,9 @@ func GetImageMetadata(imageRowString, recipeName string) (Image, error) {
if len(imgFields) < 3 {
if imageRowString != "" {
logrus.Warnf("%s image meta has incorrect format: %s", recipeName, imageRowString)
log.Warnf("%s image meta has incorrect format: %s", recipeName, imageRowString)
} else {
logrus.Warnf("%s image meta is empty?", recipeName)
log.Warnf("%s image meta is empty?", recipeName)
}
return img, nil
}
@ -567,13 +567,13 @@ func GetImageMetadata(imageRowString, recipeName string) (Image, error) {
imageName, err := GetStringInBetween(recipeName, imgString, "[", "]")
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
img.Image = strings.ReplaceAll(imageName, "`", "")
imageURL, err := GetStringInBetween(recipeName, imgString, "(", ")")
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
img.URL = imageURL
@ -612,7 +612,7 @@ func EnsureUpToDate(recipeName string) error {
}
if len(remotes) == 0 {
logrus.Debugf("cannot ensure %s is up-to-date, no git remotes configured", recipeName)
log.Debugf("cannot ensure %s is up-to-date, no git remotes configured", recipeName)
return nil
}
@ -645,7 +645,7 @@ func EnsureUpToDate(recipeName string) error {
}
}
logrus.Debugf("fetched latest git changes for %s", recipeName)
log.Debugf("fetched latest git changes for %s", recipeName)
return nil
}
@ -682,7 +682,7 @@ func readRecipeCatalogueFS(target interface{}) error {
return err
}
logrus.Debugf("read recipe catalogue from file system cache in %s", config.RECIPES_JSON)
log.Debugf("read recipe catalogue from file system cache in %s", config.RECIPES_JSON)
return nil
}
@ -711,7 +711,7 @@ func VersionsOfService(recipe, serviceName string, offline bool) ([]string, erro
}
}
logrus.Debugf("detected versions %s for %s", strings.Join(versions, ", "), recipe)
log.Debugf("detected versions %s for %s", strings.Join(versions, ", "), recipe)
return versions, nil
}
@ -738,7 +738,7 @@ func GetRecipeMeta(recipeName string, offline bool) (RecipeMeta, error) {
}
}
logrus.Debugf("recipe metadata retrieved for %s", recipeName)
log.Debugf("recipe metadata retrieved for %s", recipeName)
return recipeMeta, nil
}
@ -831,7 +831,7 @@ func ReadReposMetadata() (RepoCatalogue, error) {
pagedURL := fmt.Sprintf("%s?page=%v", ReposMetadataURL, pageIdx)
logrus.Debugf("fetching repo metadata from %s", pagedURL)
log.Debugf("fetching repo metadata from %s", pagedURL)
if err := web.ReadJSON(pagedURL, &reposList); err != nil {
return reposMeta, err
@ -869,7 +869,7 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
versions := RecipeVersions{}
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
logrus.Debugf("attempting to open git repository in %s", recipeDir)
log.Debugf("attempting to open git repository in %s", recipeDir)
repo, err := git.PlainOpen(recipeDir)
if err != nil {
@ -889,7 +889,7 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
if err := gitTags.ForEach(func(ref *plumbing.Reference) (err error) {
tag := strings.TrimPrefix(string(ref.Name()), "refs/tags/")
logrus.Debugf("processing %s for %s", tag, recipeName)
log.Debugf("processing %s for %s", tag, recipeName)
checkOutOpts := &git.CheckoutOptions{
Create: false,
@ -897,11 +897,11 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
Branch: plumbing.ReferenceName(ref.Name()),
}
if err := worktree.Checkout(checkOutOpts); err != nil {
logrus.Debugf("failed to check out %s in %s", tag, recipeDir)
log.Debugf("failed to check out %s in %s", tag, recipeDir)
return err
}
logrus.Debugf("successfully checked out %s in %s", ref.Name(), recipeDir)
log.Debugf("successfully checked out %s in %s", ref.Name(), recipeDir)
recipe, err := Get(recipeName, offline)
if err != nil {
@ -925,7 +925,7 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
case reference.NamedTagged:
tag = img.(reference.NamedTagged).Tag()
case reference.Named:
logrus.Warnf("%s service is missing image tag?", path)
log.Warnf("%s service is missing image tag?", path)
continue
}
@ -949,7 +949,7 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
sortRecipeVersions(versions)
logrus.Debugf("collected %s for %s", versions, recipeName)
log.Debugf("collected %s for %s", versions, recipeName)
return versions, nil
}
@ -1036,7 +1036,7 @@ func UpdateRepositories(repos RepoCatalogue, recipeName string) error {
recipeDir := path.Join(config.RECIPES_DIR, rm.Name)
if err := gitPkg.Clone(recipeDir, rm.CloneURL); err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
ch <- rm.Name
@ -1076,7 +1076,7 @@ func GetComposeFiles(recipe string, appEnv map[string]string) ([]string, error)
if err := ensurePathExists(path); err != nil {
return composeFiles, err
}
logrus.Debugf("no COMPOSE_FILE detected, loading default: %s", path)
log.Debugf("no COMPOSE_FILE detected, loading default: %s", path)
composeFiles = append(composeFiles, path)
return composeFiles, nil
}
@ -1086,7 +1086,7 @@ func GetComposeFiles(recipe string, appEnv map[string]string) ([]string, error)
if err := ensurePathExists(path); err != nil {
return composeFiles, err
}
logrus.Debugf("COMPOSE_FILE detected, loading %s", path)
log.Debugf("COMPOSE_FILE detected, loading %s", path)
composeFiles = append(composeFiles, path)
return composeFiles, nil
}
@ -1105,8 +1105,8 @@ func GetComposeFiles(recipe string, appEnv map[string]string) ([]string, error)
composeFiles = append(composeFiles, path)
}
logrus.Debugf("COMPOSE_FILE detected (%s), loading %s", composeFileEnvVar, strings.Join(envVars, ", "))
logrus.Debugf("retrieved %s configs for %s", strings.Join(composeFiles, ", "), recipe)
log.Debugf("COMPOSE_FILE detected (%s), loading %s", composeFileEnvVar, strings.Join(envVars, ", "))
log.Debugf("retrieved %s configs for %s", strings.Join(composeFiles, ", "), recipe)
return composeFiles, nil
}

View File

@ -5,7 +5,7 @@ import (
"fmt"
"os/exec"
"github.com/sirupsen/logrus"
"coopcloud.tech/abra/pkg/log"
)
// PassInsertSecret inserts a secret into a pass store.
@ -19,13 +19,13 @@ func PassInsertSecret(secretValue, secretName, appName, server string) error {
secretValue, server, appName, secretName,
)
logrus.Debugf("attempting to run %s", cmd)
log.Debugf("attempting to run %s", cmd)
if err := exec.Command("bash", "-c", cmd).Run(); err != nil {
return err
}
logrus.Infof("%s inserted into pass store", secretName)
log.Infof("%s inserted into pass store", secretName)
return nil
}
@ -41,13 +41,13 @@ func PassRmSecret(secretName, appName, server string) error {
server, appName, secretName,
)
logrus.Debugf("attempting to run %s", cmd)
log.Debugf("attempting to run %s", cmd)
if err := exec.Command("bash", "-c", cmd).Run(); err != nil {
return err
}
logrus.Infof("%s removed from pass store", secretName)
log.Infof("%s removed from pass store", secretName)
return nil
}

View File

@ -15,13 +15,13 @@ import (
"coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/envfile"
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/recipe"
"coopcloud.tech/abra/pkg/upstream/stack"
loader "coopcloud.tech/abra/pkg/upstream/stack"
"github.com/decentral1se/passgen"
"github.com/docker/docker/api/types"
dockerClient "github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)
// Secret represents a secret.
@ -55,7 +55,7 @@ func GeneratePasswords(count, length uint) ([]string, error) {
return nil, err
}
logrus.Debugf("generated %s", strings.Join(passwords, ", "))
log.Debugf("generated %s", strings.Join(passwords, ", "))
return passwords, nil
}
@ -73,7 +73,7 @@ func GeneratePassphrases(count uint) ([]string, error) {
return nil, err
}
logrus.Debugf("generated %s", strings.Join(passphrases, ", "))
log.Debugf("generated %s", strings.Join(passphrases, ", "))
return passphrases, nil
}
@ -110,7 +110,7 @@ func ReadSecretsConfig(appEnvPath string, composeFiles []string, stackName strin
}
if len(enabledSecrets) == 0 {
logrus.Debugf("not generating app secrets, none enabled in recipe config")
log.Debugf("not generating app secrets, none enabled in recipe config")
return nil, nil
}
@ -121,7 +121,7 @@ func ReadSecretsConfig(appEnvPath string, composeFiles []string, stackName strin
}
if !(slices.Contains(enabledSecrets, secretId)) {
logrus.Warnf("%s not enabled in recipe config, skipping", secretId)
log.Warnf("%s not enabled in recipe config, skipping", secretId)
continue
}
@ -171,7 +171,7 @@ func GenerateSecrets(cl *dockerClient.Client, secrets map[string]Secret, server
go func(secretName string, secret Secret) {
defer wg.Done()
logrus.Debugf("attempting to generate and store %s on %s", secret.RemoteName, server)
log.Debugf("attempting to generate and store %s on %s", secret.RemoteName, server)
if secret.Length > 0 {
passwords, err := GeneratePasswords(1, uint(secret.Length))
@ -182,7 +182,7 @@ func GenerateSecrets(cl *dockerClient.Client, secrets map[string]Secret, server
if err := client.StoreSecret(cl, secret.RemoteName, passwords[0], server); err != nil {
if strings.Contains(err.Error(), "AlreadyExists") {
logrus.Warnf("%s already exists, moving on...", secret.RemoteName)
log.Warnf("%s already exists, moving on...", secret.RemoteName)
ch <- nil
} else {
ch <- err
@ -202,7 +202,7 @@ func GenerateSecrets(cl *dockerClient.Client, secrets map[string]Secret, server
if err := client.StoreSecret(cl, secret.RemoteName, passphrases[0], server); err != nil {
if strings.Contains(err.Error(), "AlreadyExists") {
logrus.Warnf("%s already exists, moving on...", secret.RemoteName)
log.Warnf("%s already exists, moving on...", secret.RemoteName)
ch <- nil
} else {
ch <- err
@ -227,7 +227,7 @@ func GenerateSecrets(cl *dockerClient.Client, secrets map[string]Secret, server
}
}
logrus.Debugf("generated and stored %v on %s", secrets, server)
log.Debugf("generated and stored %v on %s", secrets, server)
return secretsGenerated, nil
}

View File

@ -5,7 +5,7 @@ import (
"path"
"coopcloud.tech/abra/pkg/config"
"github.com/sirupsen/logrus"
"coopcloud.tech/abra/pkg/log"
)
// CreateServerDir creates a server directory under ~/.abra.
@ -17,11 +17,11 @@ func CreateServerDir(serverName string) error {
return err
}
logrus.Debugf("%s already exists", serverPath)
log.Debugf("%s already exists", serverPath)
return nil
}
logrus.Debugf("successfully created %s", serverPath)
log.Debugf("successfully created %s", serverPath)
return nil
}

View File

@ -6,12 +6,12 @@ import (
"strings"
"coopcloud.tech/abra/pkg/formatter"
"coopcloud.tech/abra/pkg/log"
"github.com/AlecAivazis/survey/v2"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)
// GetService retrieves a service container based on a label. If prompt is true
@ -52,7 +52,7 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
return swarm.Service{}, err
}
logrus.Warnf("ambiguous service list received, prompting for input")
log.Warnf("ambiguous service list received, prompting for input")
var response string
prompt := &survey.Select{
@ -72,7 +72,7 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
}
}
logrus.Panic("failed to match chosen service")
log.Fatal("failed to match chosen service")
}
return matchingServices[0], nil
@ -106,7 +106,7 @@ func GetService(c context.Context, cl *client.Client, filters filters.Args, prom
return swarm.Service{}, err
}
logrus.Warnf("ambiguous service list received, prompting for input")
log.Warnf("ambiguous service list received, prompting for input")
var response string
prompt := &survey.Select{
@ -126,7 +126,7 @@ func GetService(c context.Context, cl *client.Client, filters filters.Args, prom
}
}
logrus.Panic("failed to match chosen service")
log.Fatal("failed to match chosen service")
}
return services[0], nil

View File

@ -1,13 +1,12 @@
package test
import (
"log"
"os"
"path"
appPkg "coopcloud.tech/abra/pkg/app"
"coopcloud.tech/abra/pkg/envfile"
"github.com/sirupsen/logrus"
"coopcloud.tech/abra/pkg/log"
)
var (
@ -53,12 +52,12 @@ var ExpectedAppFiles = map[string]appPkg.AppFile{
func RmServerAppRecipe() {
testAppLink := os.ExpandEnv("$HOME/.abra/servers/foo.com")
if err := os.Remove(testAppLink); err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
testRecipeLink := os.ExpandEnv("$HOME/.abra/recipes/test")
if err := os.Remove(testRecipeLink); err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
}

View File

@ -27,8 +27,8 @@ import (
"syscall"
"time"
"coopcloud.tech/abra/pkg/log"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
exec "golang.org/x/sys/execabs"
)
@ -46,7 +46,7 @@ func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) {
)
c.cmd = exec.CommandContext(ctx, cmd, args...)
// we assume that args never contains sensitive information
logrus.Debugf("commandconn: starting %s with %v", cmd, args)
log.Debugf("commandconn: starting %s with %v", cmd, args)
c.cmd.Env = os.Environ()
c.cmd.SysProcAttr = &syscall.SysProcAttr{}
setPdeathsig(c.cmd)
@ -189,14 +189,14 @@ func (c *commandConn) CloseRead() error {
// NOTE: maybe already closed here
if err := c.stdout.Close(); err != nil && !ignorableCloseError(err) {
// muted because https://github.com/docker/compose/issues/8544
// logrus.Warnf("commandConn.CloseRead: %v", err)
// log.Warnf("commandConn.CloseRead: %v", err)
}
c.stdioClosedMu.Lock()
c.stdoutClosed = true
c.stdioClosedMu.Unlock()
if err := c.killIfStdioClosed(); err != nil {
// muted because https://github.com/docker/compose/issues/8544
// logrus.Warnf("commandConn.CloseRead: %v", err)
// log.Warnf("commandConn.CloseRead: %v", err)
}
return nil
}
@ -213,14 +213,14 @@ func (c *commandConn) CloseWrite() error {
// NOTE: maybe already closed here
if err := c.stdin.Close(); err != nil && !ignorableCloseError(err) {
// muted because https://github.com/docker/compose/issues/8544
// logrus.Warnf("commandConn.CloseWrite: %v", err)
// log.Warnf("commandConn.CloseWrite: %v", err)
}
c.stdioClosedMu.Lock()
c.stdinClosed = true
c.stdioClosedMu.Unlock()
if err := c.killIfStdioClosed(); err != nil {
// muted because https://github.com/docker/compose/issues/8544
// logrus.Warnf("commandConn.CloseWrite: %v", err)
// log.Warnf("commandConn.CloseWrite: %v", err)
}
return nil
}
@ -236,11 +236,11 @@ func (c *commandConn) Write(p []byte) (int, error) {
func (c *commandConn) Close() error {
var err error
if err = c.CloseRead(); err != nil {
logrus.Warnf("commandConn.Close: CloseRead: %v", err)
log.Warnf("commandConn.Close: CloseRead: %v", err)
}
if err = c.CloseWrite(); err != nil {
// muted because https://github.com/docker/compose/issues/8544
// logrus.Warnf("commandConn.Close: CloseWrite: %v", err)
// log.Warnf("commandConn.Close: CloseWrite: %v", err)
}
return err
}
@ -252,15 +252,15 @@ func (c *commandConn) RemoteAddr() net.Addr {
return c.remoteAddr
}
func (c *commandConn) SetDeadline(t time.Time) error {
logrus.Debugf("unimplemented call: SetDeadline(%v)", t)
log.Debugf("unimplemented call: SetDeadline(%v)", t)
return nil
}
func (c *commandConn) SetReadDeadline(t time.Time) error {
logrus.Debugf("unimplemented call: SetReadDeadline(%v)", t)
log.Debugf("unimplemented call: SetReadDeadline(%v)", t)
return nil
}
func (c *commandConn) SetWriteDeadline(t time.Time) error {
logrus.Debugf("unimplemented call: SetWriteDeadline(%v)", t)
log.Debugf("unimplemented call: SetWriteDeadline(%v)", t)
return nil
}
@ -284,7 +284,7 @@ type stderrWriter struct {
}
func (w *stderrWriter) Write(p []byte) (int, error) {
logrus.Debugf("%s%s", w.debugPrefix, string(p))
log.Debugf("%s%s", w.debugPrefix, string(p))
w.stderrMu.Lock()
if w.stderr.Len() > 4096 {
w.stderr.Reset()

View File

@ -6,11 +6,11 @@ import (
"fmt"
"io"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types"
apiclient "github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)
// RunExec runs a command on a remote container. io.Writer corresponds to the
@ -109,7 +109,7 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, client *apiclie
}
if err := <-errCh; err != nil {
logrus.Debugf("Error hijack: %s", err)
log.Debugf("Error hijack: %s", err)
return out, err
}

View File

@ -7,12 +7,12 @@ import (
"runtime"
"sync"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/stdcopy"
"github.com/moby/term"
"github.com/sirupsen/logrus"
)
// The default escape key sequence: ctrl-p, ctrl-q
@ -96,7 +96,7 @@ func (h *hijackedIOStreamer) setupInput() (restore func(), err error) {
if h.detachKeys != "" {
customEscapeKeys, err := term.ToBytes(h.detachKeys)
if err != nil {
logrus.Warnf("invalid detach escape keys, using default: %s", err)
log.Warnf("invalid detach escape keys, using default: %s", err)
} else {
escapeKeys = customEscapeKeys
}
@ -128,10 +128,10 @@ func (h *hijackedIOStreamer) beginOutputStream(restoreInput func()) <-chan error
_, err = stdcopy.StdCopy(h.outputStream, h.errorStream, h.resp.Reader)
}
logrus.Debug("[hijack] End of stdout")
log.Debug("[hijack] End of stdout")
if err != nil {
logrus.Debugf("Error receiveStdout: %s", err)
log.Debugf("Error receiveStdout: %s", err)
}
outputDone <- err
@ -152,7 +152,7 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
// messages will be in normal type.
restoreInput()
logrus.Debug("[hijack] End of stdin")
log.Debug("[hijack] End of stdin")
if _, ok := err.(term.EscapeError); ok {
detached <- err
@ -163,12 +163,12 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
// This error will also occur on the receive
// side (from stdout) where it will be
// propagated back to the caller.
logrus.Debugf("Error sendStdin: %s", err)
log.Debugf("Error sendStdin: %s", err)
}
}
if err := h.resp.CloseWrite(); err != nil {
logrus.Debugf("Couldn't send EOF: %s", err)
log.Debugf("Couldn't send EOF: %s", err)
}
close(inputDone)

View File

@ -8,12 +8,12 @@ import (
"runtime"
"time"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
apiclient "github.com/docker/docker/client"
"github.com/moby/sys/signal"
"github.com/sirupsen/logrus"
)
// resizeTtyTo resizes tty to specific height and width
@ -35,7 +35,7 @@ func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id strin
}
if err != nil {
logrus.Debugf("Error resize: %s\r", err)
log.Debugf("Error resize: %s\r", err)
}
return err
}

View File

@ -4,9 +4,9 @@ import (
"context"
"fmt"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/sirupsen/logrus"
)
// RunServiceScale scales a service (useful for restart action)
@ -37,7 +37,7 @@ func RunServiceScale(ctx context.Context, cl *client.Client, serviceID string, s
}
for _, warning := range response.Warnings {
logrus.Warn(warning)
log.Warn(warning)
}
return nil

View File

@ -7,10 +7,10 @@ import (
"sort"
"strings"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/cli/cli/compose/loader"
"github.com/docker/cli/cli/compose/schema"
composetypes "github.com/docker/cli/cli/compose/types"
"github.com/sirupsen/logrus"
)
// DontSkipValidation ensures validation is done for compose file loading
@ -51,13 +51,13 @@ func LoadComposefile(opts Deploy, appEnv map[string]string, options ...func(*loa
unsupportedProperties := loader.GetUnsupportedProperties(dicts...)
if len(unsupportedProperties) > 0 {
logrus.Warnf("%s: ignoring unsupported options: %s",
log.Warnf("%s: ignoring unsupported options: %s",
recipeName, strings.Join(unsupportedProperties, ", "))
}
deprecatedProperties := loader.GetDeprecatedProperties(dicts...)
if len(deprecatedProperties) > 0 {
logrus.Warnf("%s: ignoring deprecated options: %s",
log.Warnf("%s: ignoring deprecated options: %s",
recipeName, propertyWarnings(deprecatedProperties))
}
return config, nil

View File

@ -6,13 +6,13 @@ import (
"sort"
"strings"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
apiclient "github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// RunRemove is the swarm implementation of docker stack remove
@ -46,7 +46,7 @@ func RunRemove(ctx context.Context, client *apiclient.Client, opts Remove) error
}
if len(services)+len(networks)+len(secrets)+len(configs) == 0 {
logrus.Warning(fmt.Errorf("nothing found in stack: %s", namespace))
log.Warnf("nothing found in stack: %s", namespace)
continue
}
@ -87,10 +87,10 @@ func removeServices(
var hasError bool
sort.Slice(services, sortServiceByName(services))
for _, service := range services {
logrus.Infof("removing service %s\n", service.Spec.Name)
log.Infof("removing service %s\n", service.Spec.Name)
if err := client.ServiceRemove(ctx, service.ID); err != nil {
hasError = true
logrus.Fatalf("failed to remove service %s: %s", service.ID, err)
log.Fatalf("failed to remove service %s: %s", service.ID, err)
}
}
return hasError
@ -103,10 +103,10 @@ func removeNetworks(
) bool {
var hasError bool
for _, network := range networks {
logrus.Infof("removing network %s\n", network.Name)
log.Infof("removing network %s\n", network.Name)
if err := client.NetworkRemove(ctx, network.ID); err != nil {
hasError = true
logrus.Fatalf("failed to remove network %s: %s", network.ID, err)
log.Fatalf("failed to remove network %s: %s", network.ID, err)
}
}
return hasError
@ -119,10 +119,10 @@ func removeSecrets(
) bool {
var hasError bool
for _, secret := range secrets {
logrus.Infof("Removing secret %s\n", secret.Spec.Name)
log.Infof("Removing secret %s\n", secret.Spec.Name)
if err := client.SecretRemove(ctx, secret.ID); err != nil {
hasError = true
logrus.Fatalf("Failed to remove secret %s: %s", secret.ID, err)
log.Fatalf("Failed to remove secret %s: %s", secret.ID, err)
}
}
return hasError
@ -135,10 +135,10 @@ func removeConfigs(
) bool {
var hasError bool
for _, config := range configs {
logrus.Infof("removing config %s\n", config.Spec.Name)
log.Infof("removing config %s\n", config.Spec.Name)
if err := client.ConfigRemove(ctx, config.ID); err != nil {
hasError = true
logrus.Fatalf("failed to remove config %s: %s", config.ID, err)
log.Fatalf("failed to remove config %s: %s", config.ID, err)
}
}
return hasError

View File

@ -11,6 +11,7 @@ import (
stdlibErr "errors"
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/upstream/convert"
"github.com/docker/cli/cli/command/service/progress"
"github.com/docker/cli/cli/command/stack/formatter"
@ -23,7 +24,6 @@ import (
"github.com/docker/docker/client"
dockerClient "github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// Resolve image constants
@ -118,12 +118,12 @@ func IsDeployed(ctx context.Context, cl *dockerClient.Client, stackName string)
}
}
logrus.Debugf("%s has been detected as deployed with version %s", stackName, version)
log.Debugf("%s has been detected as deployed with version %s", stackName, version)
return true, version, nil
}
logrus.Debugf("%s has been detected as not deployed", stackName)
log.Debugf("%s has been detected as not deployed", stackName)
return isDeployed, version, nil
}
@ -131,7 +131,7 @@ func IsDeployed(ctx context.Context, cl *dockerClient.Client, stackName string)
func pruneServices(ctx context.Context, cl *dockerClient.Client, namespace convert.Namespace, services map[string]struct{}) {
oldServices, err := GetStackServices(ctx, cl, namespace.Name())
if err != nil {
logrus.Infof("failed to list services: %s\n", err)
log.Infof("failed to list services: %s\n", err)
}
pruneServices := []swarm.Service{}
@ -213,9 +213,9 @@ func deployCompose(ctx context.Context, cl *dockerClient.Client, opts Deploy, co
return err
}
logrus.Infof("waiting for %s to deploy... please hold 🤚", appName)
log.Infof("waiting for %s to deploy... please hold 🤚", appName)
if err := waitOnServices(ctx, cl, serviceIDs, appName); err == nil {
logrus.Infof("Successfully deployed %s", appName)
log.Infof("Successfully deployed %s", appName)
}
return err
}
@ -265,7 +265,7 @@ func createSecrets(ctx context.Context, cl *dockerClient.Client, secrets []swarm
}
case dockerClient.IsErrNotFound(err):
// secret does not exist, then we create a new one.
logrus.Infof("Creating secret %s\n", secretSpec.Name)
log.Infof("Creating secret %s\n", secretSpec.Name)
if _, err := cl.SecretCreate(ctx, secretSpec); err != nil {
return errors.Wrapf(err, "failed to create secret %s", secretSpec.Name)
}
@ -287,7 +287,7 @@ func createConfigs(ctx context.Context, cl *dockerClient.Client, configs []swarm
}
case dockerClient.IsErrNotFound(err):
// config does not exist, then we create a new one.
logrus.Infof("creating config %s\n", configSpec.Name)
log.Infof("creating config %s\n", configSpec.Name)
if _, err := cl.ConfigCreate(ctx, configSpec); err != nil {
return errors.Wrapf(err, "failed to create config %s", configSpec.Name)
}
@ -318,7 +318,7 @@ func createNetworks(ctx context.Context, cl *dockerClient.Client, namespace conv
createOpts.Driver = defaultNetworkDriver
}
logrus.Infof("creating network %s\n", name)
log.Infof("creating network %s\n", name)
if _, err := cl.NetworkCreate(ctx, name, createOpts); err != nil {
return errors.Wrapf(err, "failed to create network %s", name)
}
@ -355,7 +355,7 @@ func deployServices(
)
if service, exists := existingServiceMap[name]; exists {
logrus.Infof("Updating service %s (id: %s)\n", name, service.ID)
log.Infof("Updating service %s (id: %s)\n", name, service.ID)
updateOpts := types.ServiceUpdateOptions{EncodedRegistryAuth: encodedAuth}
@ -394,12 +394,12 @@ func deployServices(
}
for _, warning := range response.Warnings {
logrus.Warn(warning)
log.Warn(warning)
}
serviceIDs = append(serviceIDs, service.ID)
} else {
logrus.Infof("creating service %s\n", name)
log.Infof("creating service %s\n", name)
createOpts := types.ServiceCreateOptions{EncodedRegistryAuth: encodedAuth}
@ -418,7 +418,7 @@ func deployServices(
}
if dontWait {
logrus.Warn("skipping converge logic checks")
log.Warn("skipping converge logic checks")
return nil, nil
}

View File

@ -3,18 +3,18 @@ package web
import (
"fmt"
"coopcloud.tech/abra/pkg/log"
"github.com/hashicorp/go-retryablehttp"
"github.com/sirupsen/logrus"
)
// customLeveledLogger is custom logger with logrus baked in
// customLeveledLogger is custom logger with custom logger baked in
type customLeveledLogger struct {
retryablehttp.Logger
}
// Printf wires up logrus into the custom retryablehttp logger
// Printf wires up our existing custom logger into the custom retryablehttp logger
func (l customLeveledLogger) Printf(msg string, args ...interface{}) {
logrus.Debugf(fmt.Sprintf(msg, args...))
log.Debugf(fmt.Sprintf(msg, args...))
}
// NewHTTPRetryClient instantiates a new http client with retries baked in