diff --git a/Dockerfile b/Dockerfile index fe7fc7548..e8247182d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,8 @@ ARG builder_image=ghcr.io/alphagov/govuk-ruby-builder:$ruby_version FROM $builder_image AS builder ENV DEVISE_PEPPER=unused \ - DEVISE_SECRET_KEY=unused + DEVISE_SECRET_KEY=unused \ + GOVUK_ENVIRONMENT_NAME=unused WORKDIR $APP_HOME COPY Gemfile* .ruby-version ./ diff --git a/app/models/govuk_environment.rb b/app/models/govuk_environment.rb index 11ec64bf8..4f7298e38 100644 --- a/app/models/govuk_environment.rb +++ b/app/models/govuk_environment.rb @@ -3,7 +3,7 @@ def self.name if Rails.env.development? || Rails.env.test? "development" else - ENV["GOVUK_ENVIRONMENT_NAME"] + ENV.fetch("GOVUK_ENVIRONMENT_NAME") end end diff --git a/config/initializers/govuk_admin_template.rb b/config/initializers/govuk_admin_template.rb index 8bd10ed96..cdb9fc963 100644 --- a/config/initializers/govuk_admin_template.rb +++ b/config/initializers/govuk_admin_template.rb @@ -8,5 +8,5 @@ c.disable_google_analytics = false end -GovukAdminTemplate.environment_label = (GovukEnvironment.name || "development").titleize +GovukAdminTemplate.environment_label = GovukEnvironment.name.titleize GovukAdminTemplate.environment_style = GovukEnvironment.production? ? "production" : "preview" diff --git a/docs/environment-variables.md b/docs/environment-variables.md index acb315e96..b9f0b8f1b 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -40,10 +40,6 @@ Used to configure `GovukAdminTemplate` and in `Healthcheck::ApiTokens#expiring_t * `GOVUK_ENVIRONMENT_NAME` -Used in various bits of logic to detect the production instance of the app and used to display various environment-specific strings. - -* `INSTANCE_NAME` - ## Splunk Used to stream event logs to Splunk for analysis of Signon usage patterns and anomalies. diff --git a/test/models/govuk_environment_test.rb b/test/models/govuk_environment_test.rb index 1dbbb9c79..50cec20fe 100644 --- a/test/models/govuk_environment_test.rb +++ b/test/models/govuk_environment_test.rb @@ -28,11 +28,18 @@ class GovukEnvironmentTest < ActionMailer::TestCase setup do Rails.env.stubs(:development?).returns(false) Rails.env.stubs(:test?).returns(false) - ENV.stubs(:[]).with("GOVUK_ENVIRONMENT_NAME").returns("govuk-environment-name") end - should "return value of GOVUK_ENVIRONMENT_NAME env var" do - assert_equal "govuk-environment-name", GovukEnvironment.name + should "return value of GOVUK_ENVIRONMENT_NAME if it is set" do + ClimateControl.modify(GOVUK_ENVIRONMENT_NAME: "govuk-environment-name") do + assert_equal "govuk-environment-name", GovukEnvironment.name + end + end + + should "fail fast if GOVUK_ENVIRONMENT_NAME is not set" do + ClimateControl.modify(GOVUK_ENVIRONMENT_NAME: nil) do + assert_raises(KeyError) { GovukEnvironment.name } + end end end end