Integrated label-schema.org labels
This commit is contained in:
parent
7bcc544685
commit
576f26207d
30
main.go
30
main.go
@ -28,6 +28,11 @@ func main() {
|
|||||||
Usage: "dry run disables docker push",
|
Usage: "dry run disables docker push",
|
||||||
EnvVar: "PLUGIN_DRY_RUN",
|
EnvVar: "PLUGIN_DRY_RUN",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "remote.url",
|
||||||
|
Usage: "git remote url",
|
||||||
|
EnvVar: "DRONE_REMOTE_URL",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "commit.sha",
|
Name: "commit.sha",
|
||||||
Usage: "git commit sha",
|
Usage: "git commit sha",
|
||||||
@ -134,6 +139,11 @@ func main() {
|
|||||||
Usage: "docker repository",
|
Usage: "docker repository",
|
||||||
EnvVar: "PLUGIN_REPO",
|
EnvVar: "PLUGIN_REPO",
|
||||||
},
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "label-schema",
|
||||||
|
Usage: "label-schema labels",
|
||||||
|
EnvVar: "PLUGIN_LABEL_SCHEMA",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "docker.registry",
|
Name: "docker.registry",
|
||||||
Usage: "docker registry",
|
Usage: "docker registry",
|
||||||
@ -172,15 +182,17 @@ func run(c *cli.Context) error {
|
|||||||
Email: c.String("docker.email"),
|
Email: c.String("docker.email"),
|
||||||
},
|
},
|
||||||
Build: Build{
|
Build: Build{
|
||||||
Name: c.String("commit.sha"),
|
Remote: c.String("remote.url"),
|
||||||
Dockerfile: c.String("dockerfile"),
|
Name: c.String("commit.sha"),
|
||||||
Context: c.String("context"),
|
Dockerfile: c.String("dockerfile"),
|
||||||
Tags: c.StringSlice("tags"),
|
Context: c.String("context"),
|
||||||
Args: c.StringSlice("args"),
|
Tags: c.StringSlice("tags"),
|
||||||
Squash: c.Bool("squash"),
|
Args: c.StringSlice("args"),
|
||||||
Pull: c.BoolT("pull-image"),
|
Squash: c.Bool("squash"),
|
||||||
Compress: c.Bool("compress"),
|
Pull: c.BoolT("pull-image"),
|
||||||
Repo: c.String("repo"),
|
Compress: c.Bool("compress"),
|
||||||
|
Repo: c.String("repo"),
|
||||||
|
LabelSchema: c.StringSlice("label-schema"),
|
||||||
},
|
},
|
||||||
Daemon: Daemon{
|
Daemon: Daemon{
|
||||||
Registry: c.String("docker.registry"),
|
Registry: c.String("docker.registry"),
|
||||||
|
38
plugin.go
38
plugin.go
@ -41,15 +41,17 @@ type (
|
|||||||
|
|
||||||
// Build defines Docker build parameters.
|
// Build defines Docker build parameters.
|
||||||
Build struct {
|
Build struct {
|
||||||
Name string // Docker build using default named tag
|
Remote string // Git remote URL
|
||||||
Dockerfile string // Docker build Dockerfile
|
Name string // Docker build using default named tag
|
||||||
Context string // Docker build context
|
Dockerfile string // Docker build Dockerfile
|
||||||
Tags []string // Docker build tags
|
Context string // Docker build context
|
||||||
Args []string // Docker build args
|
Tags []string // Docker build tags
|
||||||
Squash bool // Docker build squash
|
Args []string // Docker build args
|
||||||
Pull bool // Docker build pull
|
Squash bool // Docker build squash
|
||||||
Compress bool // Docker build compress
|
Pull bool // Docker build pull
|
||||||
Repo string // Docker build repository
|
Compress bool // Docker build compress
|
||||||
|
Repo string // Docker build repository
|
||||||
|
LabelSchema []string // Label schema map
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin defines the Docker plugin parameters.
|
// Plugin defines the Docker plugin parameters.
|
||||||
@ -110,8 +112,8 @@ func (p Plugin) Exec() error {
|
|||||||
addProxyBuildArgs(&p.Build)
|
addProxyBuildArgs(&p.Build)
|
||||||
|
|
||||||
var cmds []*exec.Cmd
|
var cmds []*exec.Cmd
|
||||||
cmds = append(cmds, commandVersion()) // docker version
|
cmds = append(cmds, commandVersion()) // docker version
|
||||||
cmds = append(cmds, commandInfo()) // docker info
|
cmds = append(cmds, commandInfo()) // docker info
|
||||||
|
|
||||||
cmds = append(cmds, commandBuild(p.Build)) // docker build
|
cmds = append(cmds, commandBuild(p.Build)) // docker build
|
||||||
|
|
||||||
@ -200,6 +202,20 @@ func commandBuild(build Build) *exec.Cmd {
|
|||||||
args = append(args, "--build-arg", arg)
|
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...)
|
return exec.Command(dockerExe, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user