Skip to content

Commit

Permalink
feat: enable env vars from upstream buildpack
Browse files Browse the repository at this point in the history
This enables this buildpack to make use of the same env vars as the
upstream nginx buildpack by re-using the same load logic.
  • Loading branch information
ctrox committed Jan 30, 2024
1 parent cf133a4 commit a325441
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/paketo-buildpacks/nginx"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/scribe"
"github.com/paketo-buildpacks/packit/v2/servicebindings"
)

func Build(logger scribe.Emitter) packit.BuildFunc {
Expand All @@ -31,19 +32,23 @@ func Build(logger scribe.Emitter) packit.BuildFunc {
nginxConf := filepath.Join(context.WorkingDir, nginx.ConfFile)
if _, err := os.Stat(nginxConf); err != nil {
if errors.Is(err, os.ErrNotExist) {
confGen := NewDefaultConfigGenerator(logger)
if err := confGen.Generate(Configuration{
// we re-use LoadConfiguration from the nginx buildpack to support some of the env variables.
cfg, err := nginx.LoadConfiguration(os.Environ(), servicebindings.NewResolver(), os.Getenv("CNB_PLATFORM_DIR"))
if err != nil {
return packit.BuildResult{}, packit.Fail.WithMessage("unable to load config: %s", err)
}
cfg.NGINXConfLocation = nginxConf
cfg.WebServerRoot = webRoot

if err := NewDefaultConfigGenerator(logger).Generate(Configuration{
// we set the last-modified header to the current time
// during build. This works around the issue described in:
// https://github.com/paketo-buildpacks/nginx/issues/447
LastModifiedValue: time.Now().UTC().Format(http.TimeFormat),
ETag: false,
// allow from Pod CIDR
SetRealIPFrom: "10.42.0.0/16",
Configuration: nginx.Configuration{
NGINXConfLocation: nginxConf,
WebServerRoot: webRoot,
},
Configuration: cfg,
}); err != nil {
return packit.BuildResult{}, packit.Fail.WithMessage("unable to create nginx.conf: %s", err)
}
Expand Down

0 comments on commit a325441

Please sign in to comment.