diff --git a/internal/deployment/domain/backend.go b/internal/deployment/domain/backend.go index c68fedf7..2749998a 100644 --- a/internal/deployment/domain/backend.go +++ b/internal/deployment/domain/backend.go @@ -2,8 +2,18 @@ package domain import "context" -// Backend service used to run an application services. -type Backend interface { - Run(context.Context, Deployment) (Services, error) // Launch a deployment through the backend and return services that has been deployed - Cleanup(context.Context, App) error // Cleanup an application, which means removing every possible stuff related to it -} +type ( + // Backend service used to run an application services. + Backend interface { + Run(context.Context, Deployment) (Services, error) // Launch a deployment through the backend and return services that has been deployed + Cleanup(context.Context, App) error // Cleanup an application, which means removing every possible stuff related to it + } + + // Specific logger interface use by deployment jobs to document the deployment process. + StepLogger interface { + Stepf(string, ...any) + Warnf(string, ...any) + Infof(string, ...any) + Error(error) + } +) diff --git a/internal/deployment/domain/deployment_id.go b/internal/deployment/domain/deployment_id.go index bea890e7..a61aab63 100644 --- a/internal/deployment/domain/deployment_id.go +++ b/internal/deployment/domain/deployment_id.go @@ -1,8 +1,8 @@ package domain -// The deployment unique identifier is a composite key -// based on the app id and the deployment number. type ( + // The deployment unique identifier is a composite key + // based on the app id and the deployment number. DeploymentNumber int DeploymentID struct { diff --git a/internal/deployment/domain/meta.go b/internal/deployment/domain/meta.go index b22cf47e..643af2d8 100644 --- a/internal/deployment/domain/meta.go +++ b/internal/deployment/domain/meta.go @@ -9,7 +9,7 @@ type Meta struct { } // Builds a new deployment meta from a kind and any additional data. -// You should never call it outside a Trigger implementation since +// You should never call it outside a Source implementation since // it will be picked by a job to actually initiate the deployment. func NewMeta(kind Kind, data string) Meta { return Meta{kind, data} diff --git a/internal/deployment/infra/backend/docker/docker.go b/internal/deployment/infra/backend/docker/docker.go index 81d173cd..060d5ced 100644 --- a/internal/deployment/infra/backend/docker/docker.go +++ b/internal/deployment/infra/backend/docker/docker.go @@ -12,6 +12,7 @@ import ( "strings" "github.com/YuukanOO/seelf/internal/deployment/domain" + "github.com/YuukanOO/seelf/internal/deployment/infra" "github.com/YuukanOO/seelf/pkg/log" "github.com/YuukanOO/seelf/pkg/ostools" "github.com/compose-spec/compose-go/cli" @@ -169,7 +170,7 @@ func (d *docker) Run(ctx context.Context, depl domain.Deployment) (domain.Servic defer logfile.Close() - logger := log.NewStepLogger(logfile) + logger := infra.NewStepLogger(logfile) logger.Stepf("configuring seelf docker project for environment: %s", depl.Config().Environment()) project, services, err := d.generateProject(depl, logger) @@ -185,7 +186,7 @@ func (d *docker) Run(ctx context.Context, depl domain.Deployment) (domain.Servic d.cli.Apply(command.WithStandardStreams()) }() - logger.Step("launching docker compose project (pulling, building and running)") + logger.Stepf("launching docker compose project (pulling, building and running)") if err = d.compose.Up(ctx, project, api.UpOptions{ Create: api.CreateOptions{ @@ -201,7 +202,7 @@ func (d *docker) Run(ctx context.Context, depl domain.Deployment) (domain.Servic } if d.options.Domain().UseSSL() { - logger.Info("you may have to wait for certificates to be generated before your app is available") + logger.Infof("you may have to wait for certificates to be generated before your app is available") } // Remove dangling images @@ -219,7 +220,7 @@ func (d *docker) Run(ctx context.Context, depl domain.Deployment) (domain.Servic } } else { // If there's an error, we just log it and go on since it's not a critical one - logger.Warn(err.Error()) + logger.Warnf(err.Error()) } return services, nil @@ -364,7 +365,7 @@ func (d *docker) setupComposeIfNeeded() error { // // The goal is really for the user to provide a docker-compose file which runs fine locally // and we should do our best to expose it accordingly without the user providing anything. -func (d *docker) generateProject(depl domain.Deployment, logger log.StepLogger) (*types.Project, domain.Services, error) { +func (d *docker) generateProject(depl domain.Deployment, logger domain.StepLogger) (*types.Project, domain.Services, error) { var ( services domain.Services buildDir = depl.Path(d.options.AppsDir()) diff --git a/internal/deployment/infra/logger.go b/internal/deployment/infra/logger.go new file mode 100644 index 00000000..ae5622e5 --- /dev/null +++ b/internal/deployment/infra/logger.go @@ -0,0 +1,37 @@ +package infra + +import ( + "fmt" + "io" + + "github.com/YuukanOO/seelf/internal/deployment/domain" +) + +type stepLogger struct { + writer io.Writer +} + +// Instantiates a new step logger to provide a simple way to build a deployment logfile. +func NewStepLogger(writer io.Writer) domain.StepLogger { + return &stepLogger{writer} +} + +func (l *stepLogger) Stepf(format string, args ...any) { + l.print("[STEP]", format, args) +} + +func (l *stepLogger) Warnf(format string, args ...any) { + l.print("[WARN]", format, args) +} + +func (l *stepLogger) Infof(format string, args ...any) { + l.print("[INFO]", format, args) +} + +func (l *stepLogger) Error(err error) { + l.print("[ERROR]", err.Error(), nil) +} + +func (l *stepLogger) print(prefix string, format string, args []any) { + l.writer.Write([]byte(fmt.Sprintf("%s %s\n", prefix, fmt.Sprintf(format, args...)))) +} diff --git a/internal/deployment/infra/source/archive/source.go b/internal/deployment/infra/source/archive/source.go index 2c43230c..dcc1b674 100644 --- a/internal/deployment/infra/source/archive/source.go +++ b/internal/deployment/infra/source/archive/source.go @@ -11,8 +11,8 @@ import ( "path/filepath" "github.com/YuukanOO/seelf/internal/deployment/domain" + "github.com/YuukanOO/seelf/internal/deployment/infra" "github.com/YuukanOO/seelf/internal/deployment/infra/source" - "github.com/YuukanOO/seelf/pkg/log" "github.com/YuukanOO/seelf/pkg/ostools" ) @@ -94,7 +94,7 @@ func (t *service) Fetch(ctx context.Context, depl domain.Deployment) error { defer logfile.Close() - logger := log.NewStepLogger(logfile) + logger := infra.NewStepLogger(logfile) buildDir := depl.Path(t.options.AppsDir()) diff --git a/internal/deployment/infra/source/git/source.go b/internal/deployment/infra/source/git/source.go index 6d06d03a..b4658c10 100644 --- a/internal/deployment/infra/source/git/source.go +++ b/internal/deployment/infra/source/git/source.go @@ -8,11 +8,11 @@ import ( sstrings "strings" "github.com/YuukanOO/seelf/internal/deployment/domain" + "github.com/YuukanOO/seelf/internal/deployment/infra" "github.com/go-git/go-git/v5/config" "github.com/YuukanOO/seelf/internal/deployment/infra/source" "github.com/YuukanOO/seelf/pkg/apperr" - "github.com/YuukanOO/seelf/pkg/log" "github.com/YuukanOO/seelf/pkg/monad" "github.com/YuukanOO/seelf/pkg/ostools" "github.com/YuukanOO/seelf/pkg/validation" @@ -115,7 +115,7 @@ func (s *service) Fetch(ctx context.Context, depl domain.Deployment) error { defer logfile.Close() - logger := log.NewStepLogger(logfile) + logger := infra.NewStepLogger(logfile) // Retrieve git url and token from the app app, err := s.reader.GetByID(context.Background(), depl.ID().AppID()) diff --git a/internal/deployment/infra/source/raw/source.go b/internal/deployment/infra/source/raw/source.go index 996115fe..02a6148b 100644 --- a/internal/deployment/infra/source/raw/source.go +++ b/internal/deployment/infra/source/raw/source.go @@ -7,8 +7,8 @@ import ( "path/filepath" "github.com/YuukanOO/seelf/internal/deployment/domain" + "github.com/YuukanOO/seelf/internal/deployment/infra" "github.com/YuukanOO/seelf/internal/deployment/infra/source" - "github.com/YuukanOO/seelf/pkg/log" "github.com/YuukanOO/seelf/pkg/ostools" "github.com/YuukanOO/seelf/pkg/validation" "github.com/YuukanOO/seelf/pkg/validation/strings" @@ -69,7 +69,7 @@ func (s *service) Fetch(ctx context.Context, depl domain.Deployment) error { defer logfile.Close() - logger := log.NewStepLogger(logfile) + logger := infra.NewStepLogger(logfile) buildDir := depl.Path(s.options.AppsDir()) diff --git a/pkg/log/logger.go b/pkg/log/logger.go index e5f90fe7..3deb3393 100644 --- a/pkg/log/logger.go +++ b/pkg/log/logger.go @@ -1,9 +1,6 @@ package log import ( - "fmt" - "io" - "go.uber.org/zap" ) @@ -40,57 +37,3 @@ func NewLogger(verbose bool) Logger { return logger.Sugar() } - -type ( - // Specific logger interface use by deployment jobs to document the deployment process. - StepLogger interface { - Step(string) - Stepf(string, ...any) - Warn(string) - Warnf(string, ...any) - Info(string) - Infof(string, ...any) - Error(error) - } - - stepLogger struct { - writer io.Writer - } -) - -// Instantiates a new step logger to provide a simple way to build a deployment logfile. -func NewStepLogger(writer io.Writer) StepLogger { - return &stepLogger{writer} -} - -func (l *stepLogger) Step(msg string) { - l.print("[STEP]", msg) -} - -func (l *stepLogger) Stepf(format string, args ...any) { - l.Step(fmt.Sprintf(format, args...)) -} - -func (l *stepLogger) Warn(msg string) { - l.print("[WARN]", msg) -} - -func (l *stepLogger) Warnf(format string, args ...any) { - l.Warn(fmt.Sprintf(format, args...)) -} - -func (l *stepLogger) Info(msg string) { - l.print("[INFO]", msg) -} - -func (l *stepLogger) Infof(format string, args ...any) { - l.Info(fmt.Sprintf(format, args...)) -} - -func (l *stepLogger) Error(err error) { - l.print("[ERROR]", err) -} - -func (l *stepLogger) print(prefix string, msg any) { - l.writer.Write([]byte(fmt.Sprintf("%s %s\n", prefix, msg))) -}