Files

67 lines
2.2 KiB
Go

package coolifycasting
import (
"bytes"
"context"
"log/slog"
"path/filepath"
"github.com/hanzoai/o11y-foundry/api/v1alpha1/installation"
rootcasting "github.com/hanzoai/o11y-foundry/internal/casting"
"github.com/hanzoai/o11y-foundry/internal/domain"
"github.com/hanzoai/o11y-foundry/internal/errors"
"github.com/hanzoai/o11y-foundry/internal/molding"
)
var _ rootcasting.Casting = (*coolifyCasting)(nil)
type coolifyCasting struct {
logger *slog.Logger
castings []*domain.Template
}
func New(logger *slog.Logger) *coolifyCasting {
return &coolifyCasting{
logger: logger,
castings: []*domain.Template{
coolifyYAMLTemplate,
},
}
}
func (c *coolifyCasting) Enricher(ctx context.Context, config *installation.Casting) (molding.MoldingEnricher, error) {
return newCoolifyMoldingEnricher(config)
}
func (c *coolifyCasting) Forge(ctx context.Context, config installation.Casting, poursPath string) ([]domain.Material, error) {
buf := bytes.NewBuffer(nil)
err := coolifyYAMLTemplate.Execute(buf, config)
if err != nil {
return nil, errors.Wrapf(err, errors.TypeInternal, "failed to execute coolify yaml template")
}
coolifyMaterial, err := domain.NewYAMLMaterial(buf.Bytes(), filepath.Join(rootcasting.DeploymentDir, "coolify.yaml"))
if err != nil {
return nil, errors.Wrapf(err, errors.TypeInternal, "failed to create coolify yaml material")
}
return []domain.Material{coolifyMaterial}, nil
}
func (c *coolifyCasting) Cast(ctx context.Context, config installation.Casting, poursPath string) error {
c.logger.InfoContext(ctx, "Please run 'forge' first to generate the Coolify Casting",
slog.String("pours_path", poursPath))
c.logger.InfoContext(ctx, "After forging, deploy coolify.yaml to Coolify using the stack feature",
slog.String("docs", "https://coolify.io/docs/knowledge-base/docker/compose"))
return nil
}
func getCoolifyMaterial(config *installation.Casting, path string) (domain.StructuredMaterial, error) {
buf := bytes.NewBuffer(nil)
err := coolifyYAMLTemplate.Execute(buf, config)
if err != nil {
return nil, errors.Wrapf(err, errors.TypeInternal, "failed to execute coolify yaml template")
}
return domain.NewYAMLMaterial(buf.Bytes(), path)
}