0
0
mirror of https://github.com/thegeeklab/wp-docker-buildx.git synced 2024-11-25 09:10:39 +00:00

Integrated label-schema.org labels

This commit is contained in:
Thomas Boerger 2017-07-17 21:51:02 +02:00
parent 7bcc544685
commit 576f26207d
No known key found for this signature in database
GPG Key ID: 5A388F55283960B6
2 changed files with 48 additions and 20 deletions

12
main.go
View File

@ -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"),

View File

@ -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...)
}