Skip to content

Commit 3842cf3

Browse files
committed
Allow an ENV var for APPPACK_TOML to specify the path to the toml file. See Issue #10
1 parent 9a75db4 commit 3842cf3

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

builder/build/apppacktoml.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,27 @@ func (a *AppPackToml) GetTestEnv() map[string]string {
103103
func ParseAppPackToml(ctx context.Context) (*AppPackToml, error) {
104104
var config AppPackToml
105105
// if the file doesn't exist, just return an empty config
106-
if _, err := os.Stat("apppack.toml"); os.IsNotExist(err) {
107-
log.Ctx(ctx).Debug().Msg("apppack.toml not found")
106+
filename := "apppack.toml"
107+
if envFile := os.Getenv("APPPACK_TOML"); envFile != "" {
108+
filename = envFile
109+
}
110+
if _, err := os.Stat(filename); os.IsNotExist(err) {
111+
log.Ctx(ctx).Debug().Msg(fmt.Sprintf("%s not found", filename))
108112
return &config, nil
109113
}
110-
if _, err := toml.DecodeFile("apppack.toml", &config); err != nil {
114+
if _, err := toml.DecodeFile(filename, &config); err != nil {
111115
return nil, err
112116
}
113117
return &config, nil
114118
}
115119

116120
func (a AppPackToml) Write(ctx context.Context) error {
117-
log.Ctx(ctx).Debug().Msg("writing apppack.toml")
118-
f, err := os.Create("apppack.toml")
121+
filename := "apppack.toml"
122+
if envFile := os.Getenv("APPPACK_TOML"); envFile != "" {
123+
filename = envFile
124+
}
125+
log.Ctx(ctx).Debug().Msg(fmt.Sprintf("writing %s", filename))
126+
f, err := os.Create(filename)
119127
if err != nil {
120128
return err
121129
}

builder/build/prebuild.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,19 @@ func (b *Build) ConvertAppJson() error {
148148
return err
149149
}
150150
// check if apppack.toml file exists
151-
apppackTomlExists, err := b.state.FileExists("apppack.toml")
151+
filename := "apppack.toml"
152+
if envFile := os.Getenv("APPPACK_TOML"); envFile != "" {
153+
filename = envFile
154+
}
155+
apppackTomlExists, err := b.state.FileExists(filename)
152156
if err != nil {
153157
return err
154158
}
155159
if appJsonExists && !apppackTomlExists {
156160
// convert app.json to apppack.toml
157-
b.Log().Info().Msg("Converting app.json to apppack.toml")
161+
b.Log().Info().Msg(fmt.Sprintf("Converting %s to %s", "app.json", filename))
158162
t := b.AppJSON.ToApppackToml()
159-
return b.state.WriteTomlToFile("apppack.toml", t)
163+
return b.state.WriteTomlToFile(filename, t)
160164
}
161165
return nil
162166
}

builder/filesystem/filesystem.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ func (f *FileState) Log() *zerolog.Logger {
5858

5959
func (f *FileState) CreateIfNotExists() error {
6060
// touch files codebuild expects to exist
61-
for _, filename := range []string{"apppack.toml", "build.log", "metadata.toml", "test.log"} {
61+
apppackToml := "apppack.toml"
62+
if envFile := os.Getenv("APPPACK_TOML"); envFile != "" {
63+
apppackToml = envFile
64+
}
65+
66+
for _, filename := range []string{apppackToml, "build.log", "metadata.toml", "test.log"} {
6267
exists, err := f.FileExists(filename)
6368
if err != nil {
6469
return err

builder/filesystem/filesystem_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ var testContext = zerolog.New(os.Stdout).With().Timestamp().Logger().WithContext
1616

1717
func TestCreateIfNotExists(t *testing.T) {
1818
fs := afero.Afero{Fs: afero.NewMemMapFs()}
19-
if _, err := fs.Stat("apppack.toml"); !os.IsNotExist(err) {
20-
t.Error("apppack.toml should not exist")
19+
20+
filename := "apppack.toml"
21+
if envFile := os.Getenv("APPPACK_TOML"); envFile != "" {
22+
filename = envFile
23+
}
24+
25+
if _, err := fs.Stat(filename); !os.IsNotExist(err) {
26+
t.Error(fmt.Sprintf("%s should not exist", filename))
2127
}
2228
s := &FileState{
2329
fs: fs,
@@ -27,8 +33,8 @@ func TestCreateIfNotExists(t *testing.T) {
2733
if err != nil {
2834
t.Error(err)
2935
}
30-
if _, err := fs.Stat("apppack.toml"); os.IsNotExist(err) {
31-
t.Error("apppack.toml should exist")
36+
if _, err := fs.Stat(filename); os.IsNotExist(err) {
37+
t.Error(fmt.Sprintf("%s should exist", filename))
3238
}
3339
}
3440

0 commit comments

Comments
 (0)