Merge pull request #135 from tboerger/label-schema
Integrated label-schema.org labels
This commit is contained in:
commit
b02ecf7f9b
12
main.go
12
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,6 +182,7 @@ func run(c *cli.Context) error {
|
||||
Email: c.String("docker.email"),
|
||||
},
|
||||
Build: Build{
|
||||
Remote: c.String("remote.url"),
|
||||
Name: c.String("commit.sha"),
|
||||
Dockerfile: c.String("dockerfile"),
|
||||
Context: c.String("context"),
|
||||
@ -181,6 +192,7 @@ func run(c *cli.Context) error {
|
||||
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"),
|
||||
|
16
plugin.go
16
plugin.go
@ -41,6 +41,7 @@ type (
|
||||
|
||||
// Build defines Docker build parameters.
|
||||
Build struct {
|
||||
Remote string // Git remote URL
|
||||
Name string // Docker build using default named tag
|
||||
Dockerfile string // Docker build Dockerfile
|
||||
Context string // Docker build context
|
||||
@ -50,6 +51,7 @@ type (
|
||||
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.
|
||||
@ -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...)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user