From 7a75a5cc561ca522ef87c5bd622e502614b3d7c4 Mon Sep 17 00:00:00 2001 From: Issac Kelly Date: Wed, 4 Jun 2025 12:12:10 -0700 Subject: [PATCH 1/4] Allow an ENV var for APPPACK_TOML to specify the path to the toml file. See Issue #10 --- builder/build/apppacktoml.go | 13 ++++++----- builder/build/prebuild.go | 7 +++--- builder/filesystem/filesystem.go | 12 +++++++++- builder/filesystem/filesystem_test.go | 32 +++++++++++++++++++++++---- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/builder/build/apppacktoml.go b/builder/build/apppacktoml.go index 2537d4c..ebc671a 100644 --- a/builder/build/apppacktoml.go +++ b/builder/build/apppacktoml.go @@ -6,6 +6,7 @@ import ( "os" "strings" + "github.com/apppackio/codebuild-image/builder/filesystem" "github.com/BurntSushi/toml" "github.com/rs/zerolog/log" ) @@ -103,19 +104,21 @@ func (a *AppPackToml) GetTestEnv() map[string]string { func ParseAppPackToml(ctx context.Context) (*AppPackToml, error) { var config AppPackToml // if the file doesn't exist, just return an empty config - if _, err := os.Stat("apppack.toml"); os.IsNotExist(err) { - log.Ctx(ctx).Debug().Msg("apppack.toml not found") + filename := filesystem.GetAppPackTomlFilename() + if _, err := os.Stat(filename); os.IsNotExist(err) { + log.Ctx(ctx).Debug().Msg(fmt.Sprintf("%s not found", filename)) return &config, nil } - if _, err := toml.DecodeFile("apppack.toml", &config); err != nil { + if _, err := toml.DecodeFile(filename, &config); err != nil { return nil, err } return &config, nil } func (a AppPackToml) Write(ctx context.Context) error { - log.Ctx(ctx).Debug().Msg("writing apppack.toml") - f, err := os.Create("apppack.toml") + filename := filesystem.GetAppPackTomlFilename() + log.Ctx(ctx).Debug().Msg(fmt.Sprintf("writing %s", filename)) + f, err := os.Create(filename) if err != nil { return err } diff --git a/builder/build/prebuild.go b/builder/build/prebuild.go index 0e50c3f..1066e6c 100644 --- a/builder/build/prebuild.go +++ b/builder/build/prebuild.go @@ -148,15 +148,16 @@ func (b *Build) ConvertAppJson() error { return err } // check if apppack.toml file exists - apppackTomlExists, err := b.state.FileExists("apppack.toml") + filename := filesystem.GetAppPackTomlFilename() + apppackTomlExists, err := b.state.FileExists(filename) if err != nil { return err } if appJsonExists && !apppackTomlExists { // convert app.json to apppack.toml - b.Log().Info().Msg("Converting app.json to apppack.toml") + b.Log().Info().Msg(fmt.Sprintf("Converting %s to %s", "app.json", filename)) t := b.AppJSON.ToApppackToml() - return b.state.WriteTomlToFile("apppack.toml", t) + return b.state.WriteTomlToFile(filename, t) } return nil } diff --git a/builder/filesystem/filesystem.go b/builder/filesystem/filesystem.go index 73c9af0..7960894 100644 --- a/builder/filesystem/filesystem.go +++ b/builder/filesystem/filesystem.go @@ -58,7 +58,9 @@ func (f *FileState) Log() *zerolog.Logger { func (f *FileState) CreateIfNotExists() error { // touch files codebuild expects to exist - for _, filename := range []string{"apppack.toml", "build.log", "metadata.toml", "test.log"} { + apppackToml := GetAppPackTomlFilename() + + for _, filename := range []string{apppackToml, "build.log", "metadata.toml", "test.log"} { exists, err := f.FileExists(filename) if err != nil { return err @@ -177,3 +179,11 @@ func (f *FileState) WriteJsonToFile(filename string, v interface{}) error { } return nil } + +func GetAppPackTomlFilename() string { + filename := "apppack.toml" + if envFile := os.Getenv("APPPACK_TOML"); envFile != "" { + filename = envFile + } + return filename +} diff --git a/builder/filesystem/filesystem_test.go b/builder/filesystem/filesystem_test.go index a4da387..4a79b2f 100644 --- a/builder/filesystem/filesystem_test.go +++ b/builder/filesystem/filesystem_test.go @@ -4,6 +4,7 @@ import ( "archive/tar" "bytes" "context" + "fmt" "io" "os" "testing" @@ -16,8 +17,11 @@ var testContext = zerolog.New(os.Stdout).With().Timestamp().Logger().WithContext func TestCreateIfNotExists(t *testing.T) { fs := afero.Afero{Fs: afero.NewMemMapFs()} - if _, err := fs.Stat("apppack.toml"); !os.IsNotExist(err) { - t.Error("apppack.toml should not exist") + + filename := GetAppPackTomlFilename() + + if _, err := fs.Stat(filename); !os.IsNotExist(err) { + t.Error(fmt.Sprintf("%s should not exist", filename)) } s := &FileState{ fs: fs, @@ -27,8 +31,8 @@ func TestCreateIfNotExists(t *testing.T) { if err != nil { t.Error(err) } - if _, err := fs.Stat("apppack.toml"); os.IsNotExist(err) { - t.Error("apppack.toml should exist") + if _, err := fs.Stat(filename); os.IsNotExist(err) { + t.Error(fmt.Sprintf("%s should exist", filename)) } } @@ -105,6 +109,26 @@ func TestWriteEnvFile(t *testing.T) { } } +func TestGetFilename(t *testing.T) { + // Check that there is no env variable set + if os.Getenv("APPPACK_TOML") != "" { + t.Error("APPPACK_TOML env variable should not be set") + } + // Call GetAppPackTomlFilename and check the default value + + filename := GetAppPackTomlFilename() + if filename != "apppack.toml" { + t.Errorf("expected apppack.toml, got %s", filename) + } + + // Set the env variable and check again + os.Setenv("APPPACK_TOML", "custom.toml") + filename = GetAppPackTomlFilename() + if filename != "custom.toml" { + t.Errorf("expected custom.toml, got %s", filename) + } +} + func dummyTarBuffer() (*io.Reader, error) { var buf bytes.Buffer tw := tar.NewWriter(&buf) From 464de461793088a1a97e0424654cf4b0ff5e86f3 Mon Sep 17 00:00:00 2001 From: Issac Kelly Date: Thu, 12 Jun 2025 21:14:23 -0700 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdbe4e0..ac83925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,3 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed * Release tasks work with latest metadata from Heroku Buildpacks + +## [2.2.0] - 2025-06-12 + +### Improved + +* apppack.toml file is now accessible by APPPACK_TOML environment variable, allowing different services in different environments. \ No newline at end of file From 4faf08d4b810fa71886c68a76fb9e544c1698bca Mon Sep 17 00:00:00 2001 From: Issac Kelly Date: Wed, 18 Jun 2025 21:10:58 -0700 Subject: [PATCH 3/4] Address code comments. * Update changelog verb. * Unset env var after test. * Fix an unnecessary string formatt --- CHANGELOG.md | 2 +- builder/build/prebuild.go | 2 +- builder/filesystem/filesystem_test.go | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac83925..bae175d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2.2.0] - 2025-06-12 -### Improved +### Added * apppack.toml file is now accessible by APPPACK_TOML environment variable, allowing different services in different environments. \ No newline at end of file diff --git a/builder/build/prebuild.go b/builder/build/prebuild.go index 1066e6c..b6ff998 100644 --- a/builder/build/prebuild.go +++ b/builder/build/prebuild.go @@ -155,7 +155,7 @@ func (b *Build) ConvertAppJson() error { } if appJsonExists && !apppackTomlExists { // convert app.json to apppack.toml - b.Log().Info().Msg(fmt.Sprintf("Converting %s to %s", "app.json", filename)) + b.Log().Info().Msg(fmt.Sprintf("Converting app.json to %s", filename)) t := b.AppJSON.ToApppackToml() return b.state.WriteTomlToFile(filename, t) } diff --git a/builder/filesystem/filesystem_test.go b/builder/filesystem/filesystem_test.go index 4a79b2f..dfd62c1 100644 --- a/builder/filesystem/filesystem_test.go +++ b/builder/filesystem/filesystem_test.go @@ -123,6 +123,7 @@ func TestGetFilename(t *testing.T) { // Set the env variable and check again os.Setenv("APPPACK_TOML", "custom.toml") + defer os.Unsetenv("APPPACK_TOML") // Clean up after the test filename = GetAppPackTomlFilename() if filename != "custom.toml" { t.Errorf("expected custom.toml, got %s", filename) From 8c2017ac4f847fbc32f23fb4ca0d7e80691854cf Mon Sep 17 00:00:00 2001 From: Peter Baumgartner Date: Fri, 19 Sep 2025 15:40:51 -0600 Subject: [PATCH 4/4] update release date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bae175d..ed66ee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Release tasks work with latest metadata from Heroku Buildpacks -## [2.2.0] - 2025-06-12 +## [2.2.0] - 2025-09-19 ### Added