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

Merge pull request #135 from tboerger/label-schema

Integrated label-schema.org labels
This commit is contained in:
Brad Rydzewski 2017-07-21 09:13:20 -04:00 committed by GitHub
commit b02ecf7f9b
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", 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,6 +182,7 @@ func run(c *cli.Context) error {
Email: c.String("docker.email"), Email: c.String("docker.email"),
}, },
Build: Build{ Build: Build{
Remote: c.String("remote.url"),
Name: c.String("commit.sha"), Name: c.String("commit.sha"),
Dockerfile: c.String("dockerfile"), Dockerfile: c.String("dockerfile"),
Context: c.String("context"), Context: c.String("context"),
@ -181,6 +192,7 @@ func run(c *cli.Context) error {
Pull: c.BoolT("pull-image"), Pull: c.BoolT("pull-image"),
Compress: c.Bool("compress"), Compress: c.Bool("compress"),
Repo: c.String("repo"), Repo: c.String("repo"),
LabelSchema: c.StringSlice("label-schema"),
}, },
Daemon: Daemon{ Daemon: Daemon{
Registry: c.String("docker.registry"), Registry: c.String("docker.registry"),

View File

@ -41,6 +41,7 @@ type (
// Build defines Docker build parameters. // Build defines Docker build parameters.
Build struct { Build struct {
Remote string // Git remote URL
Name string // Docker build using default named tag Name string // Docker build using default named tag
Dockerfile string // Docker build Dockerfile Dockerfile string // Docker build Dockerfile
Context string // Docker build context Context string // Docker build context
@ -50,6 +51,7 @@ type (
Pull bool // Docker build pull Pull bool // Docker build pull
Compress bool // Docker build compress Compress bool // Docker build compress
Repo string // Docker build repository Repo string // Docker build repository
LabelSchema []string // Label schema map
} }
// Plugin defines the Docker plugin parameters. // Plugin defines the Docker plugin parameters.
@ -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...)
} }