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

Commit a2526fd

Browse files
* Factorize the 3 file names used in docker-app
* Cleaned a useless yaml annotation Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
1 parent 450c1f3 commit a2526fd

5 files changed

Lines changed: 12 additions & 9 deletions

File tree

internal/names.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const (
1414
ImageLabel = "com.docker.application"
1515
)
1616

17+
var (
18+
// Application file names, in order.
19+
FileNames = []string{"metadata.yml", "docker-compose.yml", "settings.yml"}
20+
)
21+
1722
var appNameRe, _ = regexp.Compile("^[a-zA-Z][a-zA-Z0-9_-]+$")
1823

1924
// AppNameFromDir takes a path to an app directory and returns

internal/packager/extract.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ func extractSingleFile(appname, appDir string) error {
153153
if len(parts) != 3 {
154154
return fmt.Errorf("malformed single-file application: expected 3 documents")
155155
}
156-
names := []string{"metadata.yml", "docker-compose.yml", "settings.yml"}
157156
for i, p := range parts {
158157
data := ""
159158
if i == 0 {
@@ -164,7 +163,7 @@ func extractSingleFile(appname, appDir string) error {
164163
data = d[1]
165164
}
166165
}
167-
err = ioutil.WriteFile(filepath.Join(appDir, names[i]), []byte(data), 0644)
166+
err = ioutil.WriteFile(filepath.Join(appDir, internal.FileNames[i]), []byte(data), 0644)
168167
if err != nil {
169168
return errors.Wrap(err, "failed to write application file")
170169
}

internal/packager/packing.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ func tarAddDir(tarout *tar.Writer, path string) error {
4343
// Pack packs the app as a single file
4444
func Pack(appname string, target io.Writer) error {
4545
tarout := tar.NewWriter(target)
46-
files := []string{"metadata.yml", "docker-compose.yml", "settings.yml"}
47-
for _, f := range files {
46+
for _, f := range internal.FileNames {
4847
err := tarAdd(tarout, f, filepath.Join(appname, f))
4948
if err != nil {
5049
return err

internal/packager/split.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"io/ioutil"
66
"os"
77
"path/filepath"
8+
9+
"github.com/docker/app/internal"
810
)
911

1012
// Split converts an app package to the split version
@@ -13,8 +15,7 @@ func Split(appname string, outputDir string) error {
1315
if err != nil {
1416
return err
1517
}
16-
names := []string{"metadata.yml", "docker-compose.yml", "settings.yml"}
17-
for _, n := range names {
18+
for _, n := range internal.FileNames {
1819
input, err := ioutil.ReadFile(filepath.Join(appname, n))
1920
if err != nil {
2021
return err
@@ -29,8 +30,7 @@ func Split(appname string, outputDir string) error {
2930

3031
// Merge converts an app-package to the single-file merged version
3132
func Merge(appname string, target io.Writer) error {
32-
names := []string{"metadata.yml", "docker-compose.yml", "settings.yml"}
33-
for i, n := range names {
33+
for i, n := range internal.FileNames {
3434
input, err := ioutil.ReadFile(filepath.Join(appname, n))
3535
if err != nil {
3636
return err

internal/types/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type AppMetadata struct {
3333
Version string
3434
Name string
3535
Description string
36-
Namespace string `yaml:"namespace"`
36+
Namespace string
3737
Maintainers Maintainers
3838
Targets ApplicationTarget
3939
}

0 commit comments

Comments
 (0)