diff --git a/main.go b/main.go index 128119b..ba172db 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,11 @@ func main() { Usage: "dry run disables docker push", EnvVar: "PLUGIN_DRY_RUN", }, + cli.StringFlag{ + Name: "remote.url", + Usage: "git remote url", + EnvVar: "DRONE_REMOTE_URL", + }, cli.StringFlag{ Name: "commit.sha", Usage: "git commit sha", @@ -134,6 +139,11 @@ func main() { Usage: "docker repository", EnvVar: "PLUGIN_REPO", }, + cli.StringSliceFlag{ + Name: "label-schema", + Usage: "label-schema labels", + EnvVar: "PLUGIN_LABEL_SCHEMA", + }, cli.StringFlag{ Name: "docker.registry", Usage: "docker registry", @@ -172,15 +182,17 @@ func run(c *cli.Context) error { 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"), - Squash: c.Bool("squash"), - Pull: c.BoolT("pull-image"), - Compress: c.Bool("compress"), - Repo: c.String("repo"), + Remote: c.String("remote.url"), + Name: c.String("commit.sha"), + Dockerfile: c.String("dockerfile"), + Context: c.String("context"), + Tags: c.StringSlice("tags"), + Args: c.StringSlice("args"), + Squash: c.Bool("squash"), + Pull: c.BoolT("pull-image"), + Compress: c.Bool("compress"), + Repo: c.String("repo"), + LabelSchema: c.StringSlice("label-schema"), }, Daemon: Daemon{ Registry: c.String("docker.registry"), diff --git a/plugin.go b/plugin.go index 78ac379..df28fb9 100644 --- a/plugin.go +++ b/plugin.go @@ -41,15 +41,17 @@ type ( // Build defines Docker build parameters. Build struct { - Name string // Docker build using default named tag - Dockerfile string // Docker build Dockerfile - Context string // Docker build context - Tags []string // Docker build tags - Args []string // Docker build args - Squash bool // Docker build squash - Pull bool // Docker build pull - Compress bool // Docker build compress - Repo string // Docker build repository + Remote string // Git remote URL + Name string // Docker build using default named tag + Dockerfile string // Docker build Dockerfile + Context string // Docker build context + Tags []string // Docker build tags + Args []string // Docker build args + Squash bool // Docker build squash + Pull bool // Docker build pull + Compress bool // Docker build compress + Repo string // Docker build repository + LabelSchema []string // Label schema map } // Plugin defines the Docker plugin parameters. @@ -110,8 +112,8 @@ func (p Plugin) Exec() error { addProxyBuildArgs(&p.Build) var cmds []*exec.Cmd - cmds = append(cmds, commandVersion()) // docker version - cmds = append(cmds, commandInfo()) // docker info + cmds = append(cmds, commandVersion()) // docker version + cmds = append(cmds, commandInfo()) // docker info cmds = append(cmds, commandBuild(p.Build)) // docker build @@ -200,6 +202,20 @@ func commandBuild(build Build) *exec.Cmd { args = append(args, "--build-arg", arg) } + labelSchema := []string{ + fmt.Sprintf("build-date=%s", time.Now().Format(time.RFC3339)), + fmt.Sprintf("vcs-ref=%s", build.Name), + fmt.Sprintf("vcs-url=%s", build.Remote), + } + + if len(build.LabelSchema) > 0 { + labelSchema = append(labelSchema, build.LabelSchema...) + } + + for _, label := range labelSchema { + args = append(args, "--label", fmt.Sprintf("org.label-schema.%s", label)) + } + return exec.Command(dockerExe, args...) }