0
0
mirror of https://github.com/thegeeklab/wp-docker-buildx.git synced 2024-11-13 22:50:41 +00:00
wp-docker-buildx/main.go

175 lines
4.1 KiB
Go
Raw Normal View History

2015-05-15 05:12:50 +00:00
package main
import (
2016-08-23 19:44:50 +00:00
"fmt"
2015-05-15 05:12:50 +00:00
"os"
"github.com/Sirupsen/logrus"
"github.com/joho/godotenv"
2016-07-22 18:13:39 +00:00
"github.com/urfave/cli"
2015-05-15 05:12:50 +00:00
)
2016-08-23 19:44:50 +00:00
var build = "0" // build number set at compile-time
2015-05-15 05:12:50 +00:00
func main() {
2016-05-03 23:17:16 +00:00
app := cli.NewApp()
2016-05-03 23:34:08 +00:00
app.Name = "docker plugin"
app.Usage = "docker plugin"
2016-05-03 23:17:16 +00:00
app.Action = run
2016-08-23 19:44:50 +00:00
app.Version = fmt.Sprintf("1.0.%s", build)
2016-05-03 23:17:16 +00:00
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "dry-run",
Usage: "dry run disables docker push",
EnvVar: "PLUGIN_DRY_RUN",
},
cli.StringFlag{
Name: "commit.sha",
Usage: "git commit sha",
EnvVar: "DRONE_COMMIT_SHA",
2016-05-03 23:34:08 +00:00
Value: "00000000",
2016-05-03 23:17:16 +00:00
},
cli.StringFlag{
Name: "daemon.mirror",
Usage: "docker daemon registry mirror",
2016-05-20 19:59:51 +00:00
EnvVar: "PLUGIN_MIRROR",
2016-05-03 23:17:16 +00:00
},
cli.StringFlag{
Name: "daemon.storage-driver",
Usage: "docker daemon storage driver",
EnvVar: "PLUGIN_STORAGE_DRIVER",
},
cli.StringFlag{
2016-05-03 23:34:08 +00:00
Name: "daemon.storage-path",
2016-05-03 23:17:16 +00:00
Usage: "docker daemon storage path",
Value: "/var/lib/docker",
2016-05-03 23:17:16 +00:00
EnvVar: "PLUGIN_STORAGE_PATH",
},
cli.StringFlag{
Name: "daemon.bip",
Usage: "docker daemon bride ip address",
EnvVar: "PLUGIN_BIP",
},
2016-07-25 21:45:31 +00:00
cli.StringFlag{
Name: "daemon.mtu",
Usage: "docker daemon custom mtu setting",
EnvVar: "PLUGIN_MTU",
},
2016-05-03 23:17:16 +00:00
cli.StringSliceFlag{
Name: "daemon.dns",
Usage: "docker daemon dns server",
EnvVar: "PLUGIN_DNS",
},
cli.BoolFlag{
Name: "daemon.insecure",
Usage: "docker daemon allows insecure registries",
EnvVar: "PLUGIN_INSECURE",
},
cli.BoolFlag{
Name: "daemon.debug",
Usage: "docker daemon executes in debug mode",
EnvVar: "PLUGIN_DEBUG,DOCKER_LAUNCH_DEBUG",
},
cli.BoolFlag{
Name: "daemon.off",
Usage: "docker daemon executes in debug mode",
EnvVar: "PLUGIN_DAEMON_OFF",
},
cli.StringFlag{
Name: "dockerfile",
Usage: "build dockerfile",
Value: "Dockerfile",
EnvVar: "PLUGIN_DOCKERFILE",
},
cli.StringFlag{
Name: "context",
Usage: "build context",
Value: ".",
EnvVar: "PLUGIN_CONTEXT",
},
cli.StringSliceFlag{
Name: "tags",
Usage: "build tags",
Value: &cli.StringSlice{"latest"},
EnvVar: "PLUGIN_TAG,PLUGIN_TAGS",
},
cli.StringSliceFlag{
Name: "args",
Usage: "build args",
2016-05-03 23:34:08 +00:00
EnvVar: "PLUGIN_BUILD_ARGS",
2016-05-03 23:17:16 +00:00
},
cli.StringFlag{
Name: "repo",
Usage: "docker repository",
EnvVar: "PLUGIN_REPO",
},
cli.StringFlag{
Name: "docker.registry",
Usage: "docker username",
Value: defaultRegistry,
EnvVar: "DOCKER_REGISTRY,PLUGIN_REGISTRY",
},
cli.StringFlag{
Name: "docker.username",
Usage: "docker username",
EnvVar: "DOCKER_USERNAME,PLUGIN_USERNAME",
},
cli.StringFlag{
Name: "docker.password",
Usage: "docker password",
EnvVar: "DOCKER_PASSWORD,PLUGIN_PASSWORD",
},
cli.StringFlag{
Name: "docker.email",
Usage: "docker email",
EnvVar: "DOCKER_EMAIL,PLUGIN_EMAIL",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
},
2016-05-03 23:17:16 +00:00
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
2016-05-03 23:17:16 +00:00
}
2015-10-28 00:53:51 +00:00
func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}
2016-05-03 23:17:16 +00:00
plugin := Plugin{
Dryrun: c.Bool("dry-run"),
Login: Login{
Registry: c.String("docker.registry"),
Username: c.String("docker.username"),
Password: c.String("docker.password"),
Email: c.String("docker.email"),
},
Build: Build{
Name: c.String("commit.sha"),
Dockerfile: c.String("dockerfile"),
Context: c.String("context"),
Tags: c.StringSlice("tags"),
Args: c.StringSlice("args"),
Repo: c.String("repo"),
},
Daemon: Daemon{
Registry: c.String("docker.registry"),
Mirror: c.String("daemon.mirror"),
StorageDriver: c.String("daemon.storage-driver"),
StoragePath: c.String("daemon.storage-path"),
Insecure: c.Bool("daemon.insecure"),
Disabled: c.Bool("daemon.off"),
2016-05-03 23:34:08 +00:00
Debug: c.Bool("daemon.debug"),
2016-05-03 23:17:16 +00:00
Bip: c.String("daemon.bip"),
DNS: c.StringSlice("daemon.dns"),
2016-07-26 10:09:00 +00:00
MTU: c.String("daemon.mtu"),
2016-05-03 23:17:16 +00:00
},
}
return plugin.Exec()
2015-05-15 05:12:50 +00:00
}