Skip to content

Commit

Permalink
Merge pull request #13 from ninech/env-force-https
Browse files Browse the repository at this point in the history
feat: enable env vars from upstream buildpack
  • Loading branch information
ctrox authored Jan 30, 2024
2 parents cf133a4 + a325441 commit 2338f02
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 2338f02

Please sign in to comment.