provision storage outside of builder
1 file changed, 23 insertions(+), 8 deletions(-)
changed files
M cmd/build/main.go → cmd/build/main.go
@@ -6,6 +6,7 @@ "os" "go.alanpearce.eu/website/internal/builder" "go.alanpearce.eu/website/internal/config" + "go.alanpearce.eu/website/internal/storage/files" "go.alanpearce.eu/website/internal/vcs" "go.alanpearce.eu/x/log"@@ -15,33 +16,47 @@ ) const branch = "main" +type Options struct { + *builder.Options + Destination string `conf:"default:./public,short:d,flag:dest"` + Compress bool `conf:"default:true"` +} + func main() { - builderOptions := &builder.Options{} - if help, err := conf.Parse("", builderOptions); err != nil { + options := &Options{} + if help, err := conf.Parse("", options); err != nil { if errors.Is(err, conf.ErrHelpWanted) { fmt.Println(help) os.Exit(1) } panic("error parsing configuration: " + err.Error()) } - log := log.Configure(!builderOptions.Development) + log := log.Configure(!options.Development) repo, _, err := vcs.CloneOrOpen(&vcs.Options{ - LocalPath: builderOptions.Source, - RemoteURL: builderOptions.VCSRemoteURL, + LocalPath: options.Source, + RemoteURL: options.VCSRemoteURL, Branch: branch, }, log.Named("vcs")) if err != nil { panic("could not open repository: " + err.Error()) } - builderOptions.Repo = repo + options.Repo = repo + + storage, err := files.NewWriter(options.Destination, log.Named("storage"), &files.Options{ + Compress: options.Compress, + }) + if err != nil { + panic("could not create storage: " + err.Error()) + } + options.Storage = storage log.Debug("starting build process") - cfg, err := config.GetConfig(builderOptions.Source, log) + cfg, err := config.GetConfig(options.Source, log) if err != nil { log.Error("could not read config", "error", err) } - _, err = builder.BuildSite(builderOptions, cfg, log) + _, err = builder.BuildSite(options.Options, cfg, log) if err != nil { log.Error("could not build site", "error", err) os.Exit(1)