2021-01-10 23:01:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-04-25 10:51:42 +00:00
|
|
|
"fmt"
|
2021-01-10 23:01:27 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
2022-06-02 13:00:33 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2021-01-11 20:54:49 +00:00
|
|
|
"github.com/thegeeklab/drone-docker-buildx/plugin"
|
|
|
|
"github.com/urfave/cli/v2"
|
2021-01-10 23:01:27 +00:00
|
|
|
|
2022-06-02 13:00:33 +00:00
|
|
|
"github.com/thegeeklab/drone-plugin-lib/v2/urfave"
|
2021-01-10 23:01:27 +00:00
|
|
|
)
|
|
|
|
|
2022-04-25 10:51:42 +00:00
|
|
|
var (
|
|
|
|
BuildVersion = "devel"
|
|
|
|
BuildDate = "00000000"
|
|
|
|
)
|
2021-01-10 23:01:27 +00:00
|
|
|
|
|
|
|
func main() {
|
2021-01-11 20:54:49 +00:00
|
|
|
settings := &plugin.Settings{}
|
|
|
|
|
|
|
|
if _, err := os.Stat("/run/drone/env"); err == nil {
|
2022-04-25 10:51:42 +00:00
|
|
|
_ = 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)
|
2021-01-10 23:01:27 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 20:54:49 +00:00
|
|
|
app := &cli.App{
|
|
|
|
Name: "drone-docker-buildx",
|
|
|
|
Usage: "build docker container with DinD and buildx",
|
2022-04-25 10:51:42 +00:00
|
|
|
Version: BuildVersion,
|
2022-06-02 19:26:34 +00:00
|
|
|
Flags: append(settingsFlags(settings, urfave.FlagsPluginCategory), urfave.Flags()...),
|
2021-01-11 20:54:49 +00:00
|
|
|
Action: run(settings),
|
2021-01-10 23:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
2022-06-02 13:00:33 +00:00
|
|
|
logrus.Fatal(err)
|
2021-01-10 23:01:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-11 20:54:49 +00:00
|
|
|
func run(settings *plugin.Settings) cli.ActionFunc {
|
|
|
|
return func(ctx *cli.Context) error {
|
|
|
|
urfave.LoggingFromContext(ctx)
|
2021-01-10 23:01:27 +00:00
|
|
|
|
2021-01-11 20:54:49 +00:00
|
|
|
plugin := plugin.New(
|
|
|
|
*settings,
|
|
|
|
urfave.PipelineFromContext(ctx),
|
|
|
|
urfave.NetworkFromContext(ctx),
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := plugin.Validate(); err != nil {
|
2022-06-02 13:00:33 +00:00
|
|
|
return fmt.Errorf("validation failed: %w", err)
|
2021-01-10 23:01:27 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 20:54:49 +00:00
|
|
|
if err := plugin.Execute(); err != nil {
|
2022-06-02 13:00:33 +00:00
|
|
|
return fmt.Errorf("execution failed: %w", err)
|
2021-01-11 20:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-01-10 23:01:27 +00:00
|
|
|
}
|