mirror of
https://github.com/thegeeklab/wp-ansible.git
synced 2024-12-01 07:10:34 +00:00
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
|
||
|
"github.com/joho/godotenv"
|
||
|
"github.com/owncloud-ci/drone-ansible/plugin"
|
||
|
"github.com/urfave/cli/v2"
|
||
|
|
||
|
"github.com/drone-plugins/drone-plugin-lib/errors"
|
||
|
"github.com/drone-plugins/drone-plugin-lib/urfave"
|
||
|
)
|
||
|
|
||
|
var version = "unknown"
|
||
|
|
||
|
func main() {
|
||
|
settings := &plugin.Settings{}
|
||
|
|
||
|
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||
|
godotenv.Overload("/run/drone/env")
|
||
|
}
|
||
|
|
||
|
app := &cli.App{
|
||
|
Name: "drone-ansible",
|
||
|
Usage: "provision infrastructure with Ansible",
|
||
|
Version: version,
|
||
|
Flags: append(settingsFlags(settings), urfave.Flags()...),
|
||
|
Action: run(settings),
|
||
|
}
|
||
|
|
||
|
if err := app.Run(os.Args); err != nil {
|
||
|
errors.HandleExit(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func run(settings *plugin.Settings) cli.ActionFunc {
|
||
|
return func(ctx *cli.Context) error {
|
||
|
urfave.LoggingFromContext(ctx)
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
return errors.ExitMessagef("validation failed: %w", err)
|
||
|
}
|
||
|
|
||
|
if err := plugin.Execute(); err != nil {
|
||
|
if e, ok := err.(errors.ExitCoder); ok {
|
||
|
return e
|
||
|
}
|
||
|
|
||
|
return errors.ExitMessagef("execution failed: %w", err)
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
}
|