2022-05-03 09:45:54 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
2022-05-29 10:37:09 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2022-05-29 11:56:55 +00:00
|
|
|
"github.com/thegeeklab/drone-plugin-lib/v2/urfave"
|
2022-05-03 09:45:54 +00:00
|
|
|
"github.com/thegeeklab/drone-s3-sync/plugin"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
BuildVersion = "devel"
|
|
|
|
BuildDate = "00000000"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
settings := &plugin.Settings{}
|
|
|
|
|
|
|
|
if _, err := os.Stat("/run/drone/env"); err == nil {
|
|
|
|
_ = godotenv.Overload("/run/drone/env")
|
|
|
|
}
|
|
|
|
|
|
|
|
cli.VersionPrinter = func(c *cli.Context) {
|
|
|
|
fmt.Printf("%s version=%s date=%s\n", c.App.Name, c.App.Version, BuildDate)
|
|
|
|
}
|
|
|
|
|
|
|
|
app := &cli.App{
|
|
|
|
Name: "drone-s3-sync",
|
|
|
|
Usage: "synchronize a directory with an S3 bucket",
|
|
|
|
Version: BuildVersion,
|
2022-05-29 11:56:55 +00:00
|
|
|
Flags: append(settingsFlags(settings, urfave.FlagsPluginCategory), urfave.Flags()...),
|
2022-05-03 09:45:54 +00:00
|
|
|
Action: run(settings),
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
2022-05-29 10:37:09 +00:00
|
|
|
logrus.Fatal(err)
|
2022-05-03 09:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func run(settings *plugin.Settings) cli.ActionFunc {
|
|
|
|
return func(ctx *cli.Context) error {
|
|
|
|
urfave.LoggingFromContext(ctx)
|
|
|
|
|
2022-05-29 20:36:25 +00:00
|
|
|
settings.ACL = ctx.Generic("acl").(*StringMapFlag).Get()
|
2022-05-03 09:45:54 +00:00
|
|
|
settings.CacheControl = ctx.Generic("cache-control").(*StringMapFlag).Get()
|
|
|
|
settings.ContentType = ctx.Generic("content-type").(*StringMapFlag).Get()
|
|
|
|
settings.ContentEncoding = ctx.Generic("content-encoding").(*StringMapFlag).Get()
|
|
|
|
settings.Metadata = ctx.Generic("metadata").(*DeepStringMapFlag).Get()
|
|
|
|
settings.Redirects = ctx.Generic("redirects").(*MapFlag).Get()
|
|
|
|
|
|
|
|
plugin := plugin.New(
|
|
|
|
*settings,
|
|
|
|
urfave.PipelineFromContext(ctx),
|
|
|
|
urfave.NetworkFromContext(ctx),
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := plugin.Validate(); err != nil {
|
2022-05-29 10:37:09 +00:00
|
|
|
return fmt.Errorf("validation failed: %w", err)
|
2022-05-03 09:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := plugin.Execute(); err != nil {
|
2022-05-29 10:37:09 +00:00
|
|
|
return fmt.Errorf("execution failed: %w", err)
|
2022-05-03 09:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|