Skip to content

Commit

Permalink
🐞 fix value passed to --env
Browse files Browse the repository at this point in the history
The rack environment is hard-coded to the value `RACK_ENV=production`
which appears to be a conflation of setting an ENV variable, and passing
the value value via the `--env` flag to `rackup`.

This commit makes two changes:
1. The value passed to the flag `--env` is now `production`, not
   `RACK_ENV=production`, and changes to the associated tests.
2. The value `production`, while still hard-coded, is interpolated into
   the process args. This should make it easier to make the value
   dynamic in the future. See paketo-buildpacks#281

Addresses paketo-buildpacks#355
  • Loading branch information
aramprice committed Dec 21, 2022
1 parent ca5248a commit c983534
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func Build(logger scribe.Emitter) packit.BuildFunc {
}
logger.Debug.Break()

// Use RACK_ENV=production since Rack v1.6.0+ defaults the host to local host in development mode (default)
// Hardcode `--env production` since Rack v1.6.0+ defaults the host to local host in development mode (default)
// The order of precedence in setting the port is:
// 1. the $PORT variable if it is set
// 2. A port listed in config.ru with the -p or --port flag
// 3. 1 and 2 are not met, and the fallback port is set to the default of 9292.
args := fmt.Sprintf(`bundle exec rackup --env RACK_ENV=production -p "${PORT:-%s}"`, port)
args := fmt.Sprintf(`bundle exec rackup --env %s -p "${PORT:-%s}"`, "production", port)
processes := []packit.Process{
{
Type: "web",
Expand Down
6 changes: 3 additions & 3 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
{
Type: "web",
Command: "bash",
Args: []string{"-c", `bundle exec rackup --env RACK_ENV=production -p "${PORT:-9292}"`},
Args: []string{"-c", `bundle exec rackup --env production -p "${PORT:-9292}"`},
Default: true,
Direct: true,
},
Expand Down Expand Up @@ -126,7 +126,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
{
Type: "web",
Command: "bash",
Args: []string{"-c", `bundle exec rackup --env RACK_ENV=production -p "${PORT:-3000}"`},
Args: []string{"-c", `bundle exec rackup --env production -p "${PORT:-3000}"`},
Default: true,
Direct: true,
},
Expand Down Expand Up @@ -175,7 +175,7 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
{
Type: "web",
Command: "bash",
Args: []string{"-c", `bundle exec rackup --env RACK_ENV=production -p "${PORT:-3000}"`},
Args: []string{"-c", `bundle exec rackup --env production -p "${PORT:-3000}"`},
Default: true,
Direct: true,
},
Expand Down
4 changes: 2 additions & 2 deletions integration/config_port_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func testConfigPortApp(t *testing.T, context spec.G, it spec.S) {
" config.ru specifies a port: 3000",
"",
" Assigning launch processes:",
` web (default): bash -c bundle exec rackup --env RACK_ENV=production -p "${PORT:-3000}"`,
` web (default): bash -c bundle exec rackup --env production -p "${PORT:-3000}"`,
))

Eventually(func() string {
Expand Down Expand Up @@ -133,7 +133,7 @@ func testConfigPortApp(t *testing.T, context spec.G, it spec.S) {
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" Writing start command",
" Assigning launch processes:",
` web (default): bash -c bundle exec rackup --env RACK_ENV=production -p "${PORT:-3000}"`,
` web (default): bash -c bundle exec rackup --env production -p "${PORT:-3000}"`,
))

Eventually(func() string {
Expand Down
4 changes: 2 additions & 2 deletions integration/simple_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func testSimpleApp(t *testing.T, context spec.G, it spec.S) {
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" Writing start command",
" Assigning launch processes:",
` web (default): bash -c bundle exec rackup --env RACK_ENV=production -p "${PORT:-9292}"`,
` web (default): bash -c bundle exec rackup --env production -p "${PORT:-9292}"`,
))
})
})
Expand Down Expand Up @@ -117,7 +117,7 @@ func testSimpleApp(t *testing.T, context spec.G, it spec.S) {
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" Writing start command",
" Assigning launch processes:",
` web (default): bash -c bundle exec rackup --env RACK_ENV=production -p "${PORT:-9292}"`,
` web (default): bash -c bundle exec rackup --env production -p "${PORT:-9292}"`,
))
})
})
Expand Down
2 changes: 1 addition & 1 deletion integration/sinatra_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func testSinatraApp(t *testing.T, context spec.G, it spec.S) {
MatchRegexp(fmt.Sprintf(`%s \d+\.\d+\.\d+`, settings.Buildpack.Name)),
" Writing start command",
" Assigning launch processes:",
` web (default): bash -c bundle exec rackup --env RACK_ENV=production -p "${PORT:-9292}"`,
` web (default): bash -c bundle exec rackup --env production -p "${PORT:-9292}"`,
))
})
})
Expand Down

0 comments on commit c983534

Please sign in to comment.