Skip to content

rack env is the way #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
hooks-ruby (0.0.7)
hooks-ruby (0.1.0)
dry-schema (~> 1.14, >= 1.14.1)
grape (~> 2.3)
puma (~> 6.6)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Here is a very high-level overview of how Hooks works:
health_path: /health
version_path: /version

environment: development
environment: development # will be overridden by the RACK_ENV environment variable if set
```

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:
Expand Down Expand Up @@ -196,7 +196,7 @@ health_path: /health
version_path: /version

# Runtime behavior
environment: development # or production
environment: development # or production (will be overridden by the RACK_ENV environment variable if set)
```

#### 2. Create your endpoint configurations
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ The path for the version endpoint. This endpoint returns the server's version in

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.

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.

**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.

**Default:** `production`
**Example:** `development`

Expand Down
4 changes: 2 additions & 2 deletions docs/instrument_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Failbot < Hooks::Plugins::Instruments::FailbotBase
# Initialize your error reporting client
@client = MyErrorService.new(
api_key: ENV["ERROR_REPORTING_API_KEY"],
environment: ENV["RAILS_ENV"] || "production"
environment: ENV["RACK_ENV"] || "production"
)
end

Expand Down Expand Up @@ -243,7 +243,7 @@ class SentryFailbot < Hooks::Plugins::Instruments::FailbotBase
require "sentry-ruby"
Sentry.init do |config|
config.dsn = ENV["SENTRY_DSN"]
config.environment = ENV["RAILS_ENV"] || "production"
config.environment = ENV["RACK_ENV"] || "production"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/core/config_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ConfigLoader
root_path: "/webhooks",
health_path: "/health",
version_path: "/version",
environment: "production",
environment: ENV.fetch("RACK_ENV", "production"),
production: true,
endpoints_dir: "./config/endpoints",
use_catchall_route: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
module Hooks
# Current version of the Hooks webhook framework
# @return [String] The version string following semantic versioning
VERSION = "0.0.7".freeze
VERSION = "0.1.0".freeze
end
4 changes: 2 additions & 2 deletions script/hooks
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class HooksCLI
config_file: "hooks.yaml",
port: 4567,
host: "0.0.0.0",
environment: "development",
threads: "5:5"
environment: ENV.fetch("RACK_ENV", "development"),
threads: "0:16" # Default Puma thread pool size
}
end

Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/config/hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ health_path: /health
version_path: /version

# Runtime behavior
environment: development
# environment: development # it is better to use the environment variable RACK_ENV to control the environment

# Available endpoints
# Each endpoint configuration file should be placed in the endpoints directory
Expand Down
1 change: 1 addition & 0 deletions spec/acceptance/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
ports:
- "8080:8080"
environment:
RACK_ENV: development # controls both puma and hooks server environment setting
LOG_LEVEL: DEBUG
GITHUB_WEBHOOK_SECRET: "octoawesome-secret"
ALT_WEBHOOK_SECRET: "octoawesome-2-secret"
Expand Down