Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 515c08d

Browse files
author
Matthieu Nottale
committed
save: Add labels 'com.docker.application' and 'maintainers'.
Signed-off-by: Matthieu Nottale <[email protected]>
1 parent 133bfaa commit 515c08d

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

packager/registry.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,28 @@ func Save(appname, prefix, tag string) (string, error) {
2929
return "", err
3030
}
3131
defer cleanup()
32-
if prefix == "" || tag == "" {
33-
metaFile := filepath.Join(appname, "metadata.yml")
34-
metaContent, err := ioutil.ReadFile(metaFile)
35-
if err != nil {
36-
return "", err
37-
}
38-
var meta types.AppMetadata
39-
err = yaml.Unmarshal(metaContent, &meta)
40-
if err != nil {
41-
return "", err
42-
}
43-
if tag == "" {
44-
tag = meta.Version
45-
}
46-
if prefix == "" {
47-
prefix = meta.RepositoryPrefix
48-
}
32+
metaFile := filepath.Join(appname, "metadata.yml")
33+
metaContent, err := ioutil.ReadFile(metaFile)
34+
if err != nil {
35+
return "", err
36+
}
37+
var meta types.AppMetadata
38+
err = yaml.Unmarshal(metaContent, &meta)
39+
if err != nil {
40+
return "", err
41+
}
42+
if tag == "" {
43+
tag = meta.Version
44+
}
45+
if prefix == "" {
46+
prefix = meta.RepositoryPrefix
4947
}
50-
dockerfile := `
48+
dockerfile := fmt.Sprintf(`
5149
FROM scratch
50+
LABEL com.docker.application=%s
51+
LABEL maintainers="%v"
5252
COPY / /
53-
`
53+
`, meta.Name, meta.Maintainers)
5454
df := filepath.Join(appname, "__Dockerfile-docker-app__")
5555
ioutil.WriteFile(df, []byte(dockerfile), 0644)
5656
di := filepath.Join(appname, ".dockerignore")

renderer/inspect.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77
"path/filepath"
88
"sort"
9-
"strings"
109
"text/tabwriter"
1110

1211
"github.com/docker/lunchbox/packager"
@@ -48,11 +47,7 @@ func Inspect(appname string) error {
4847
}
4948
sort.Slice(settingsKeys, func(i, j int) bool { return settingsKeys[i] < settingsKeys[j] })
5049
// build maintainers string
51-
maintainers := ""
52-
for _, m := range meta.Maintainers {
53-
maintainers += m.Name + " <" + m.Email + ">, "
54-
}
55-
maintainers = strings.TrimSuffix(maintainers, ", ")
50+
maintainers := meta.Maintainers.String()
5651
fmt.Printf("%s %s\n", meta.Name, meta.Version)
5752
if maintainers != "" {
5853
fmt.Printf("Maintained by: %s\n", maintainers)

types/metadata.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
package types
22

3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
38
// Maintainer represents one of the apps's maintainers
49
type Maintainer struct {
510
Name string
611
Email string
712
}
813

14+
// Maintainers is a list of maintainers
15+
type Maintainers []Maintainer
16+
17+
// String gives a string representation of a list of maintainers
18+
func (ms Maintainers) String() string {
19+
res := make([]string, len(ms))
20+
for i, m := range ms {
21+
res[i] = m.String()
22+
}
23+
return strings.Join(res, ",")
24+
}
25+
26+
// String gives a string representation of a maintainer
27+
func (m Maintainer) String() string {
28+
return fmt.Sprintf("%s <%s>", m.Name, m.Email)
29+
}
30+
931
// AppMetadata is the format of the data found inside the metadata.yml file
1032
type AppMetadata struct {
1133
Version string
1234
Name string
1335
Description string
1436
RepositoryPrefix string `yaml:"repository_prefix"`
15-
Maintainers []Maintainer
37+
Maintainers Maintainers
1638
Targets ApplicationTarget
1739
}
1840

0 commit comments

Comments
 (0)