Skip to content

Commit 900161a

Browse files
authored
Merge pull request #47 from github/rack-env
rack env is the way
2 parents 2fa69c7 + 41d3b69 commit 900161a

File tree

9 files changed

+15
-10
lines changed

9 files changed

+15
-10
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
hooks-ruby (0.0.7)
4+
hooks-ruby (0.1.0)
55
dry-schema (~> 1.14, >= 1.14.1)
66
grape (~> 2.3)
77
puma (~> 6.6)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Here is a very high-level overview of how Hooks works:
4242
health_path: /health
4343
version_path: /version
4444

45-
environment: development
45+
environment: development # will be overridden by the RACK_ENV environment variable if set
4646
```
4747
4848
2. Then in your `config/endpoints` directory, you can define all your webhook endpoints in separate files. Here is an example of a simple endpoint configuration file:
@@ -196,7 +196,7 @@ health_path: /health
196196
version_path: /version
197197
198198
# Runtime behavior
199-
environment: development # or production
199+
environment: development # or production (will be overridden by the RACK_ENV environment variable if set)
200200
```
201201

202202
#### 2. Create your endpoint configurations

docs/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ The path for the version endpoint. This endpoint returns the server's version in
8585

8686
Specifies the runtime environment for the server. This can affect logging, error handling, and other behaviors. Warning - running in development mode will return full stack traces in error responses.
8787

88+
If the `RACK_ENV` environment variable is set, it will override this value. It should be noted that using `RACK_ENV` is the **recommended** way to set the environment, as it is a standard convention in Rack-based applications. You should just omit the `environment` key in your `hooks.yaml` file if you want to use `RACK_ENV`. The `RACK_ENV` variable is automatically set to `production` if it is not defined. It also controls the environment for the puma server and the Hooks application so that they are consistent.
89+
90+
**TL;DR**: If you want to use `RACK_ENV`, just don't set the `environment` key in your `hooks.yaml` file. Plus you should really just use `RACK_ENV` anyway, as it is the standard way to set the environment in Rack-based applications.
91+
8892
**Default:** `production`
8993
**Example:** `development`
9094

docs/instrument_plugins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Failbot < Hooks::Plugins::Instruments::FailbotBase
7676
# Initialize your error reporting client
7777
@client = MyErrorService.new(
7878
api_key: ENV["ERROR_REPORTING_API_KEY"],
79-
environment: ENV["RAILS_ENV"] || "production"
79+
environment: ENV["RACK_ENV"] || "production"
8080
)
8181
end
8282

@@ -243,7 +243,7 @@ class SentryFailbot < Hooks::Plugins::Instruments::FailbotBase
243243
require "sentry-ruby"
244244
Sentry.init do |config|
245245
config.dsn = ENV["SENTRY_DSN"]
246-
config.environment = ENV["RAILS_ENV"] || "production"
246+
config.environment = ENV["RACK_ENV"] || "production"
247247
end
248248
end
249249

lib/hooks/core/config_loader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ConfigLoader
1616
root_path: "/webhooks",
1717
health_path: "/health",
1818
version_path: "/version",
19-
environment: "production",
19+
environment: ENV.fetch("RACK_ENV", "production"),
2020
production: true,
2121
endpoints_dir: "./config/endpoints",
2222
use_catchall_route: false,

lib/hooks/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
module Hooks
55
# Current version of the Hooks webhook framework
66
# @return [String] The version string following semantic versioning
7-
VERSION = "0.0.7".freeze
7+
VERSION = "0.1.0".freeze
88
end

script/hooks

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class HooksCLI
2222
config_file: "hooks.yaml",
2323
port: 4567,
2424
host: "0.0.0.0",
25-
environment: "development",
26-
threads: "5:5"
25+
environment: ENV.fetch("RACK_ENV", "development"),
26+
threads: "0:16" # Default Puma thread pool size
2727
}
2828
end
2929

spec/acceptance/config/hooks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ health_path: /health
1616
version_path: /version
1717

1818
# Runtime behavior
19-
environment: development
19+
# environment: development # it is better to use the environment variable RACK_ENV to control the environment
2020

2121
# Available endpoints
2222
# Each endpoint configuration file should be placed in the endpoints directory

spec/acceptance/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
ports:
88
- "8080:8080"
99
environment:
10+
RACK_ENV: development # controls both puma and hooks server environment setting
1011
LOG_LEVEL: DEBUG
1112
GITHUB_WEBHOOK_SECRET: "octoawesome-secret"
1213
ALT_WEBHOOK_SECRET: "octoawesome-2-secret"

0 commit comments

Comments
 (0)