From a4f0b0fabb45533ca635b0be32bd1cfed070f1bc Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Fri, 13 Jun 2025 11:06:02 -0700 Subject: [PATCH 1/2] Update environment variable handling to use RACK_ENV consistently across configurations --- README.md | 4 ++-- docs/configuration.md | 4 ++++ docs/instrument_plugins.md | 4 ++-- lib/hooks/core/config_loader.rb | 2 +- script/hooks | 4 ++-- spec/acceptance/config/hooks.yaml | 2 +- spec/acceptance/docker-compose.yml | 1 + 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0fd7b933..44af5fbf 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 diff --git a/docs/configuration.md b/docs/configuration.md index 3c618f54..3f719a22 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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` diff --git a/docs/instrument_plugins.md b/docs/instrument_plugins.md index 3610582f..16812694 100644 --- a/docs/instrument_plugins.md +++ b/docs/instrument_plugins.md @@ -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 @@ -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 diff --git a/lib/hooks/core/config_loader.rb b/lib/hooks/core/config_loader.rb index 46145d90..69fd677a 100644 --- a/lib/hooks/core/config_loader.rb +++ b/lib/hooks/core/config_loader.rb @@ -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, diff --git a/script/hooks b/script/hooks index fa317544..ccc122c4 100755 --- a/script/hooks +++ b/script/hooks @@ -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 diff --git a/spec/acceptance/config/hooks.yaml b/spec/acceptance/config/hooks.yaml index 8da97489..474691d9 100644 --- a/spec/acceptance/config/hooks.yaml +++ b/spec/acceptance/config/hooks.yaml @@ -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 diff --git a/spec/acceptance/docker-compose.yml b/spec/acceptance/docker-compose.yml index fc2a766b..62c50cdc 100644 --- a/spec/acceptance/docker-compose.yml +++ b/spec/acceptance/docker-compose.yml @@ -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" From 41d3b693a46a794200478bafd94c7c5757405d0f Mon Sep 17 00:00:00 2001 From: GrantBirki Date: Fri, 13 Jun 2025 11:06:29 -0700 Subject: [PATCH 2/2] bump version --- Gemfile.lock | 2 +- lib/hooks/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1a925adf..074d8e77 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/lib/hooks/version.rb b/lib/hooks/version.rb index 8241be9b..639e0a42 100644 --- a/lib/hooks/version.rb +++ b/lib/hooks/version.rb @@ -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