2022-09-28 00:16:57 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2022-12-21 17:11:09 +00:00
|
|
|
"github.com/6543/go-version"
|
2022-09-28 00:16:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Labels returns list of labels to use for image
|
|
|
|
func (p *Plugin) Labels() []string {
|
|
|
|
l := p.settings.Build.Labels.Value()
|
|
|
|
// As described in https://github.com/opencontainers/image-spec/blob/main/annotations.md
|
|
|
|
l = append(l, fmt.Sprintf("org.opencontainers.image.created=%s", time.Now().UTC().Format(time.RFC3339)))
|
|
|
|
if p.settings.Build.Remote != "" {
|
|
|
|
l = append(l, fmt.Sprintf("org.opencontainers.image.source=%s", p.settings.Build.Remote))
|
|
|
|
}
|
|
|
|
if p.pipeline.Repo.Link != "" {
|
|
|
|
l = append(l, fmt.Sprintf("org.opencontainers.image.url=%s", p.pipeline.Repo.Link))
|
|
|
|
}
|
|
|
|
if p.pipeline.Commit.SHA != "" {
|
|
|
|
l = append(l, fmt.Sprintf("org.opencontainers.image.revision=%s", p.pipeline.Commit.SHA))
|
|
|
|
}
|
2022-12-21 17:11:09 +00:00
|
|
|
if p.settings.Build.Ref != "" && strings.HasPrefix(p.settings.Build.Ref, tagRefPrefix) {
|
|
|
|
v, err := version.NewSemver(stripTagPrefix(p.settings.Build.Ref))
|
2022-09-28 00:16:57 +00:00
|
|
|
if err == nil && v != nil {
|
|
|
|
l = append(l, fmt.Sprintf("org.opencontainers.image.version=%s", v.String()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return l
|
|
|
|
}
|