woodpecker-docker-buildx/cmd/docker-buildx/main.go

69 lines
1.4 KiB
Go
Raw Normal View History

2021-01-10 23:01:27 +00:00
package main
import (
"os"
2021-10-13 03:40:58 +00:00
"codeberg.org/woodpecker-plugins/plugin-docker-buildx/plugin"
2021-01-10 23:01:27 +00:00
"github.com/joho/godotenv"
"github.com/urfave/cli/v2"
2021-01-10 23:01:27 +00:00
"github.com/drone-plugins/drone-plugin-lib/errors"
"github.com/drone-plugins/drone-plugin-lib/urfave"
2021-01-10 23:01:27 +00:00
)
var version = "unknown"
2021-01-10 23:01:27 +00:00
func main() {
settings := &plugin.Settings{}
if _, err := os.Stat("/run/drone/env"); err == nil {
godotenv.Overload("/run/drone/env")
2021-01-10 23:01:27 +00:00
}
2023-10-08 14:01:53 +00:00
if envFile, set := os.LookupEnv("PLUGIN_ENV_FILE"); set {
godotenv.Overload(envFile)
}
2021-01-10 23:01:27 +00:00
app := &cli.App{
2021-10-13 03:44:14 +00:00
Name: "docker-buildx",
Usage: "build docker container with DinD and buildx",
Version: version,
Flags: append(settingsFlags(settings), urfave.Flags()...),
Action: run(settings),
2021-01-10 23:01:27 +00:00
}
if err := app.Run(os.Args); err != nil {
errors.HandleExit(err)
2021-01-10 23:01:27 +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
plugin := plugin.New(
*settings,
urfave.PipelineFromContext(ctx),
urfave.NetworkFromContext(ctx),
)
if err := plugin.Validate(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
2021-01-10 23:01:27 +00:00
}
return errors.ExitMessagef("validation failed: %w", err)
2021-01-10 23:01:27 +00:00
}
if err := plugin.Execute(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("execution failed: %w", err)
}
return nil
}
2021-01-10 23:01:27 +00:00
}