From 051950e04c3a36e9b1d6bd6e04e39ee0da7c19b4 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Wed, 24 Nov 2021 15:11:00 +0100 Subject: [PATCH 1/4] Remove references to deprecated application.yml config file. Point to .env and other .env.* config files. --- GETTING_STARTED.md | 2 +- config/environments/development.rb | 2 +- config/initializers/geocoder.rb | 2 +- config/schedule.rb | 8 +++----- lib/open_food_network/i18n_config.rb | 2 +- script/setup | 6 ------ 6 files changed, 7 insertions(+), 15 deletions(-) diff --git a/GETTING_STARTED.md b/GETTING_STARTED.md index bab36e6fbe..b13938a14f 100644 --- a/GETTING_STARTED.md +++ b/GETTING_STARTED.md @@ -81,7 +81,7 @@ The tests of all custom engines can be run with: Note: If your OS is not explicitly supported in the setup guides then not all tests may pass. However, you may still be able to develop. -Note: The time zone on your machine should match the one defined in `config/application.yml`. +Note: The time zone on your machine should match the one defined in the `.env[.*]` file. Once [npm dependencies are installed][karma], AngularJS tests can be run with: diff --git a/config/environments/development.rb b/config/environments/development.rb index 4e405680a9..e233b84862 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -60,7 +60,7 @@ Openfoodnetwork::Application.configure do # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # - # To override this, set the appropriate locale in application.yml + # To override this, set the appropriate locale in .env[.*] file. config.time_zone = ENV.fetch("TIMEZONE", "UTC") config.i18n.fallbacks = [:en] diff --git a/config/initializers/geocoder.rb b/config/initializers/geocoder.rb index 893f3d04ae..1d845f945c 100644 --- a/config/initializers/geocoder.rb +++ b/config/initializers/geocoder.rb @@ -1,5 +1,5 @@ # Google requires an API key with a billing account to use their API. -# The key is stored in config/application.yml. +# The key is stored in .env[.*] files. Geocoder.configure( timeout: ENV.fetch('GEOCODER_TIMEOUT', 6).to_i, diff --git a/config/schedule.rb b/config/schedule.rb index 1016d061bc..f2e1c951bb 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -3,9 +3,7 @@ require 'yaml' # Learn more: http://github.com/javan/whenever -app_config = YAML.load_file(File.join(__dir__, 'application.yml')) - -env "MAILTO", app_config["SCHEDULE_NOTIFICATIONS"] if app_config["SCHEDULE_NOTIFICATIONS"] +env "MAILTO", ENV["SCHEDULE_NOTIFICATIONS"] if ENV["SCHEDULE_NOTIFICATIONS"] # If we use -e with a file containing specs, rspec interprets it and filters out our examples job_type :run_file, "cd :path; :environment_variable=:environment bundle exec script/rails runner :task :output" @@ -15,9 +13,9 @@ every 1.month, at: '4:30am' do end every 1.day, at: '2:45am' do - rake 'db2fog:clean' if app_config['S3_BACKUPS_BUCKET'] + rake 'db2fog:clean' if ENV['S3_BACKUPS_BUCKET'] end every 4.hours do - rake 'db2fog:backup' if app_config['S3_BACKUPS_BUCKET'] + rake 'db2fog:backup' if ENV['S3_BACKUPS_BUCKET'] end diff --git a/lib/open_food_network/i18n_config.rb b/lib/open_food_network/i18n_config.rb index 92e48bd6d3..d0d71d0450 100644 --- a/lib/open_food_network/i18n_config.rb +++ b/lib/open_food_network/i18n_config.rb @@ -3,7 +3,7 @@ module OpenFoodNetwork # Provides access to the language settings. # Currently, language settings are read from the environment. - # See: config/application.yml + # See: .env[.*] files. class I18nConfig # Users don't need to select the already selected locale. def self.locale_options diff --git a/script/setup b/script/setup index cbacd2d6e6..73100989ad 100755 --- a/script/setup +++ b/script/setup @@ -34,12 +34,6 @@ fi bundle check || bundle install yarn install -# Set up configurable environment variables -if [ ! -f config/application.yml ]; then - cp config/application.yml.example config/application.yml - printf "${YELLOW}Copied config/application.yml Make sure to fill it with the appropriate configuration values.\n\n${NO_COLOR}" -fi - # Set up the database for both development and test # Confirming the default user and password printf '\n\n' | bundle exec rake db:setup db:test:prepare From abf1b54364057a06175e8b733597b84421db0a55 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Wed, 1 Dec 2021 18:34:39 +0100 Subject: [PATCH 2/4] Fix environment variables loading when running whenever --- config/schedule.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/schedule.rb b/config/schedule.rb index f2e1c951bb..20c240f5ff 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -1,3 +1,6 @@ +# Force manual loading of rails application to get all env variables from dotenv-rails when running whenever cmd +require File.expand_path('../environment', __FILE__) + require 'whenever' require 'yaml' From 2095024f48a4fe70e4fac6509cc21b71d56ccf0e Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Wed, 1 Dec 2021 18:37:26 +0100 Subject: [PATCH 3/4] Don't git-ignore application.yml any more --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index e7cf0f0bc4..8bea552ec5 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,6 @@ config/initializers/feature_toggle.rb NERD_tree* coverage libpeerconnection.log -/config/application.yml /config/newrelic.yml node_modules vendor/bundle/ From 8585c68691e3cb5223576382b56147d44038f8d5 Mon Sep 17 00:00:00 2001 From: Adrien Chauve Date: Wed, 1 Dec 2021 18:39:26 +0100 Subject: [PATCH 4/4] Remove occurences of application.yml.example --- .github/workflows/build.yml | 6 --- config/application.yml.example | 68 ---------------------------------- docker-compose.yml | 2 - 3 files changed, 76 deletions(-) delete mode 100644 config/application.yml.example diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 899ab5688c..65d3292903 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,9 +59,6 @@ jobs: - name: Install JS dependencies run: yarn install --frozen-lockfile - - name: Set up application.yml - run: cp config/application.yml.example config/application.yml - - name: Set up database run: | bundle exec rake db:create @@ -109,9 +106,6 @@ jobs: - name: Install JS dependencies run: yarn install --frozen-lockfile - - name: Set up application.yml - run: cp config/application.yml.example config/application.yml - - name: Set up database run: | bundle exec rake db:create diff --git a/config/application.yml.example b/config/application.yml.example deleted file mode 100644 index 1346dae4c2..0000000000 --- a/config/application.yml.example +++ /dev/null @@ -1,68 +0,0 @@ -# Add application configuration variables here, as shown below. -# -# Change this, it has serious security implications. -# Minimum 30 but usually 128 characters. To obtain run 'rake secret', or faster, 'openssl rand -hex 128' -SECRET_TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -# Time zone must match the operating system time zone in order to pass all tests. -# This string is the key for the MAPPING hash constant in ActiveSupport::TimeZone. -# Documentation including the hash: https://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html -TIMEZONE: Melbourne -# Default country for dropdowns etc. See for codes: http://en.wikipedia.org/wiki/ISO_3166-1 -DEFAULT_COUNTRY_CODE: AU -# Locale for translation. -LOCALE: en -# For multilingual - ENV doesn't have array so pass it as string with commas -AVAILABLE_LOCALES: en,es -# Spree zone. -CHECKOUT_ZONE: Australia -# Find currency codes at http://en.wikipedia.org/wiki/ISO_4217. -CURRENCY: AUD - -# The whenever gem can set the `MAILTO` variable for our cron jobs. -# You can define an email address to notify if any job outputs something. -# But you need a working mail server setup so that the message is delivered. -# See: config/schedule.rb -#SCHEDULE_NOTIFICATIONS: admin@example.com - -# Mail settings -MAIL_HOST: 'example.com' -MAIL_DOMAIN: 'example.com' -MAIL_PORT: '25' -SMTP_USERNAME: 'ofn' -SMTP_PASSWORD: 'f00d' - -# Optional mail settings -# MAIL_SECURE_CONNECTION: 'TLS' # 'None' (default), 'SSL' or 'TLS' -# MAILS_FROM: hello@example.com -# MAIL_BCC: manager@example.com - -# Javascript error reporting via Bugsnag. -#BUGSNAG_JS_KEY: "" - -# SingleSignOn login for Discourse -# -# DISCOURSE_SSO_SECRET should be a random string. It must be the same as provided to your Discourse instance. -#DISCOURSE_SSO_SECRET: "" -# -# DISCOURSE_URL must be the URL of your Discourse instance. -#DISCOURSE_URL: "https://noticeboard.openfoodnetwork.org.au" - -# see: https://developers.google.com/maps/documentation/javascript/get-api-key -# GOOGLE_MAPS_API_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - -# Stripe Connect details for instance account -# Find these under 'API keys' and 'Connect' in your Stripe account dashboard -> Account Settings -# Under 'Connect', the Redirect URI should be set to https://YOUR_SERVER_URL/stripe/callbacks (e.g. https://openfoodnetwork.org.uk/stripe/callbacks) -# Under 'Webhooks', you should set up a Connect endpoint pointing to https://YOUR_SERVER_URL/stripe/webhooks e.g. (https://openfoodnetwork.org.uk/stripe/webhooks) -# STRIPE_INSTANCE_SECRET_KEY: "sk_test_xxxxxx" # This can be a test key or a live key -# STRIPE_INSTANCE_PUBLISHABLE_KEY: "pk_test_xxxx" # This can be a test key or a live key -# STRIPE_CLIENT_ID: "ca_xxxx" # This can be a development ID or a production ID -# STRIPE_ENDPOINT_SECRET: "whsec_xxxx" - -# Feature toggles -# -# Adding user emails separated by commas will enable them the use of certain features. See -# config/initializers/feature_toggles.rb for details. -# -# BETA_TESTERS: ofn@example.com,superadmin@example.com diff --git a/docker-compose.yml b/docker-compose.yml index bd7e2dc386..13049721f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,6 @@ services: - .:/usr/src/app - gems:/bundles - ./config/database.yml:/usr/src/app/config/database.yml - - ./config/application.yml.example:/usr/src/app/config/application.yml depends_on: - db - redis @@ -59,7 +58,6 @@ services: - .:/usr/src/app - gems:/bundles - ./config/database.yml:/usr/src/app/config/database.yml - - ./config/application.yml.example:/usr/src/app/config/application.yml depends_on: - db - redis