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

Commit 3c40e10

Browse files
authored
Merge pull request #378 from weitenghuang/master
Add default project lookup values
2 parents 6d1a0d8 + 37624a1 commit 3c40e10

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

docker/project.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package docker
22

33
import (
4-
"os"
5-
"path/filepath"
6-
74
"golang.org/x/net/context"
85

96
"github.com/Sirupsen/logrus"
@@ -17,31 +14,11 @@ import (
1714
"github.com/docker/libcompose/docker/service"
1815
"github.com/docker/libcompose/docker/volume"
1916
"github.com/docker/libcompose/labels"
20-
"github.com/docker/libcompose/lookup"
2117
"github.com/docker/libcompose/project"
2218
)
2319

2420
// NewProject creates a Project with the specified context.
2521
func NewProject(context *ctx.Context, parseOptions *config.ParseOptions) (project.APIProject, error) {
26-
if context.ResourceLookup == nil {
27-
context.ResourceLookup = &lookup.FileResourceLookup{}
28-
}
29-
30-
if context.EnvironmentLookup == nil {
31-
cwd, err := os.Getwd()
32-
if err != nil {
33-
return nil, err
34-
}
35-
context.EnvironmentLookup = &lookup.ComposableEnvLookup{
36-
Lookups: []config.EnvironmentLookup{
37-
&lookup.EnvfileLookup{
38-
Path: filepath.Join(cwd, ".env"),
39-
},
40-
&lookup.OsEnvLookup{},
41-
},
42-
}
43-
}
44-
4522
if context.AuthLookup == nil {
4623
context.AuthLookup = auth.NewConfigLookup(context.ConfigFile)
4724
}

project/project.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ package project
33
import (
44
"errors"
55
"fmt"
6+
"os"
7+
"path/filepath"
68
"strings"
79

810
"golang.org/x/net/context"
911

1012
log "github.com/Sirupsen/logrus"
1113
"github.com/docker/libcompose/config"
1214
"github.com/docker/libcompose/logger"
15+
"github.com/docker/libcompose/lookup"
1316
"github.com/docker/libcompose/project/events"
1417
"github.com/docker/libcompose/utils"
1518
"github.com/docker/libcompose/yaml"
@@ -57,6 +60,26 @@ func NewProject(context *Context, runtime RuntimeProject, parseOptions *config.P
5760
context.LoggerFactory = &logger.NullLogger{}
5861
}
5962

63+
if context.ResourceLookup == nil {
64+
context.ResourceLookup = &lookup.FileResourceLookup{}
65+
}
66+
67+
if context.EnvironmentLookup == nil {
68+
cwd, err := os.Getwd()
69+
if err != nil {
70+
log.Errorf("Could not get the rooted path name to the current directory: %v", err)
71+
return nil
72+
}
73+
context.EnvironmentLookup = &lookup.ComposableEnvLookup{
74+
Lookups: []config.EnvironmentLookup{
75+
&lookup.EnvfileLookup{
76+
Path: filepath.Join(cwd, ".env"),
77+
},
78+
&lookup.OsEnvLookup{},
79+
},
80+
}
81+
}
82+
6083
context.Project = p
6184

6285
p.listeners = []chan<- events.Event{NewDefaultListener(p)}

project/project_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ func TestParseWithGoodContent(t *testing.T) {
110110
}
111111
}
112112

113+
func TestParseWithDefaultEnvironmentLookup(t *testing.T) {
114+
p := NewProject(&Context{
115+
ComposeBytes: [][]byte{
116+
[]byte("not-garbage:\n image: foo:${version}"),
117+
},
118+
}, nil, nil)
119+
120+
err := p.Parse()
121+
if err != nil {
122+
t.Fatal(err)
123+
}
124+
}
125+
113126
type TestEnvironmentLookup struct {
114127
}
115128

0 commit comments

Comments
 (0)