Skip to content
This repository has been archived by the owner on Oct 24, 2019. It is now read-only.

Commit

Permalink
Use environment variables instead of settings files
Browse files Browse the repository at this point in the history
  • Loading branch information
frocher committed Dec 3, 2017
1 parent 6b896cc commit 35ce8db
Show file tree
Hide file tree
Showing 23 changed files with 235 additions and 525 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
.secret
.bundle

# Ignore specific config files
/config/database.yml
/config/olb.yml
/config/newrelic.yml
/config/puma.rb

config/application.yml

# Ignore the default SQLite database.
/db/*.sqlite3
Expand Down
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ rvm:
- 2.1.0

before_script:
- cp config/database.yml.example config/database.yml
- cp config/olb.yml.example config/olb.yml
- cp config/puma.rb.example config/puma.rb
- bundle exec rake db:migrate
7 changes: 1 addition & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gem 'sqlite3'
gem 'mysql2'

# settings
gem 'settingslogic'
gem 'figaro'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'
Expand Down Expand Up @@ -77,7 +77,6 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin]
group :test, :development do
gem 'rspec-rails'
gem 'capybara'
gem 'factory_girl_rails'
gem 'faker'
gem 'minitest', '~> 5.3.0'
gem 'rack-mini-profiler'
Expand All @@ -94,8 +93,4 @@ end
gem 'foreman'
gem 'puma'

# Monitoring
gem 'newrelic_rpm'
gem 'newrelic-grape'

gem 'annotate', '~> 2.6.5', group: :development
17 changes: 3 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,12 @@ GEM
equalizer (0.0.11)
erubis (2.7.0)
execjs (2.7.0)
factory_girl (4.9.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.9.0)
factory_girl (~> 4.9.0)
railties (>= 3.0.0)
faker (1.8.4)
i18n (~> 0.5)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
figaro (1.1.1)
thor (~> 0.14)
font-awesome-rails (4.7.0.2)
railties (>= 3.2, < 5.2)
foreman (0.84.0)
Expand Down Expand Up @@ -179,10 +176,6 @@ GEM
multipart-post (2.0.0)
mysql2 (0.4.10)
mysql2 (0.4.10-x86-mingw32)
newrelic-grape (2.1.0)
grape
newrelic_rpm
newrelic_rpm (4.6.0.338)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
nokogiri (1.8.1-x86-mingw32)
Expand Down Expand Up @@ -290,7 +283,6 @@ GEM
sprockets-rails (~> 2.0)
select2-rails (4.0.3)
thor (~> 0.14)
settingslogic (2.0.9)
shoulda-matchers (3.1.2)
activesupport (>= 4.0.0)
simplecov (0.15.1)
Expand Down Expand Up @@ -353,8 +345,8 @@ DEPENDENCIES
chronic
coffee-rails (~> 4.0.0)
devise
factory_girl_rails
faker
figaro
font-awesome-rails
foreman
gon
Expand All @@ -366,8 +358,6 @@ DEPENDENCIES
momentjs-rails
mousetrap-rails
mysql2
newrelic-grape
newrelic_rpm
numerizer
omniauth
omniauth-facebook
Expand All @@ -383,7 +373,6 @@ DEPENDENCIES
rspec-rails
sass-rails (~> 4.0.2)
select2-rails
settingslogic
shoulda-matchers
simplecov
six
Expand Down
47 changes: 38 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ You can use it online here: [www.sofreakingboring.com](https://www.sofreakingbor

Before starting SoFreakingBoring you need to follow these steps:

* copy database.yml.example to database.yml.
* copy olb.yml.example to olb.yml.
* copy puma.rb.example to puma.rb
* adapt the three files to your environment
* migrate database with 'rake db:migrate'
* start in development mode with 'rails s'

Expand All @@ -34,11 +30,44 @@ The Whenever gem is used for cron jobs. To make it work:

Note: SoFreakingBoring works on Linux and Mac OS X. It has not been tested on Windows and the whenever should not work. If you work on Windows you should consider [Vagrant](https://www.vagrantup.com/).

## Configuration

### Credits
This project uses the following environment variables.

I want to thank:
### Mandatory configuration

* [GitLab](https://gitlab.com/): great open source project and more than a source of inspiration.
* [Handsontable](http://handsontable.com/): minimalist Excel-like data grid editor.
* [Gratisography](http://gratisography.com/): free high-resolution pictures that can be used on personal and commercial projects.
| Name | Default Value | Description |
| ----- | ------------- | ------------ |
| DEVISE_SECRET_KEY | none | You must generate a Devise key
| RAILS_ENV | development | Don't forget to switch it to production |
| PORT | 3000 | Puma server port |
| SECRET_TOKEN | none | Rails needs a secret token |


### MySQL Configuration

| Name | Default Value | Description |
| --------|:---------:| -----|
| DB_HOST | localhost | Database host server |
| DB_NAME | sofreaking | Database name |
| DB_PASSWORD | &nbsp; | User password |
| DB_PORT | 3306 | Database port |
| DB_USERNAME | root | User name used to log in |

### External services and mail configuration

| Name | Default Value | Description |
| --------|:---------:| -----|
| GOOGLE_ANALYTICS_KEY | none | if you want to track usage statistics |
| GRAVATAR_HTTPS | false | Must be true if https is used |

### OAuth Configuration

| Name | Default Value | Description |
| --------|:---------:| -----|
| FACEBOOK_KEY | none | facebook key for omniauth |
| FACEBOOK_SECRET | none | facebook secret for omniauth |
| GITHUB_KEY | none | github key for omniauth |
| GITHUB_SECRET | none | github secret for omniauth |
| GOOGLE_KEY | none | google key for omniauth |
| GOOGLE_SECRET | none | google secret for omniauth |
3 changes: 1 addition & 2 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//= require jquery.easing.min
//= require mousetrap
//= require bootstrap
//= require select2
//= require select2-full
//= require admin_lte
//= require jquery.flip
//= require handsontable.full
Expand Down Expand Up @@ -61,4 +61,3 @@
//= require views/projects
//= require views/tasks
//= require views/users

2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ApplicationController < ActionController::Base
protected

def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :name
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
end

def abilities
Expand Down
19 changes: 6 additions & 13 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,18 @@ def avatar_icon(user_email = '', size = nil)
def gravatar_icon(user_email = '', size = nil)
size = 120 if size.nil? || size <= 0

if !Olb.config.gravatar.enabled || user_email.blank?
URI.join(request.url, '/assets/no_avatar.png')
else
gravatar_url = olb_config.https ? Olb.config.gravatar.ssl_url : Olb.config.gravatar.plain_url
user_email.strip!
sprintf gravatar_url, hash: Digest::MD5.hexdigest(user_email.downcase), size: size
end
plain_url = 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon'
ssl_url = 'https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon'
gravatar_url = ENV.fetch("GRAVATAR_HTTPS", false) ? ssl_url : plain_url
user_email.strip!
sprintf gravatar_url, hash: Digest::MD5.hexdigest(user_email.downcase), size: size
end

def randomized_background_image
images = ["/assets/intro-bug.jpg", "/assets/intro-mantis.jpg", "/assets/intro-town.jpg"]
images[rand(images.size)]
end

# shortcut for olb config
def olb_config
Olb.config.olb
end

def date_only(datetime)
datetime.strftime("%b %d, %Y")
end
Expand Down Expand Up @@ -68,5 +61,5 @@ def body_data_page

[namespace, controller.controller_name, controller.action_name].compact.join(":")
end

end
20 changes: 9 additions & 11 deletions app/views/devise/shared/_social.html.slim
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
- if devise_mapping.omniauthable? && Olb.config.omniauth.enabled
.margin.text-center
= link_to user_omniauth_authorize_path(:facebook), class: "btn bg-light-blue btn-circle", title: "Sign in with FaceBook"
i.fa.fa-facebook
| &nbsp;
= link_to user_omniauth_authorize_path(:google_oauth2), class: "btn bg-red btn-circle", title: "Sign in with Google"
i.fa.fa-google
| &nbsp;
= link_to user_omniauth_authorize_path(:github), class: "btn bg-black btn-circle", title: "Sign in with Github"
i.fa.fa-github-alt

.margin.text-center
= link_to user_facebook_omniauth_authorize_path(:facebook), class: "btn bg-light-blue btn-circle", title: "Sign in with FaceBook"
i.fa.fa-facebook
| &nbsp;
= link_to user_google_oauth2_omniauth_authorize_path(:google_oauth2), class: "btn bg-red btn-circle", title: "Sign in with Google"
i.fa.fa-google
| &nbsp;
= link_to user_github_omniauth_authorize_path(:github), class: "btn bg-black btn-circle", title: "Sign in with Github"
i.fa.fa-github-alt
4 changes: 2 additions & 2 deletions app/views/layouts/_footer_panel.html.slim
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- unless Olb.config.olb.google_analytics.nil?
- if ENV.has_key?("GOOGLE_ANALYTICS_KEY")
javascript:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', "#{Olb.config.olb.google_analytics}", 'auto');
ga('create', "#{ENV.fetch('GOOGLE_ANALYTICS_KEY')}", 'auto');
ga('send', 'pageview');
1 change: 0 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
NewRelic::Agent.manual_start
run Rails.application
24 changes: 24 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

default: &default
adapter: mysql2
pool: <%= ENV.fetch("DB_POOL") { 20 } %>
database: <%= ENV.fetch("DB_NAME") { "sofreaking" } %>
username: <%= ENV.fetch("DB_USERNAME") { "root" } %>
password: <%= ENV.fetch("DB_PASSWORD") { "" } %>
host: <%= ENV.fetch("DB_HOST") { "localhost" } %>
port: <%= ENV.fetch("DB_PORT") { 3306 } %>
encoding: utf8
secure_auth: false

development:
<<: *default

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: <%= ENV.fetch("DB_TEST_NAME") { "sofreaking_test" } %>

production:
<<: *default
30 changes: 0 additions & 30 deletions config/database.yml.example

This file was deleted.

File renamed without changes.
18 changes: 0 additions & 18 deletions config/initializers/1_settings.rb

This file was deleted.

25 changes: 0 additions & 25 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@
# time the user will be asked for credentials again. Default is 30 minutes.
config.timeout_in = 60.minutes

# If true, expires auth token on session timeout.
config.expire_auth_token_on_timeout = false

# ==> Configuration for :lockable
# Defines which strategy will be used to lock an account.
Expand Down Expand Up @@ -225,27 +223,4 @@

# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete

# ==> OmniAuth

unless Olb.config.omniauth.providers.nil?
Olb.config.omniauth.providers.each do |provider|
provider_arguments = []

%w[app_id app_secret].each do |argument|
provider_arguments << provider[argument] if provider[argument]
end

case provider['args']
when Array
# An Array from the configuration will be expanded.
provider_arguments.concat provider['args']
when Hash
# A Hash from the configuration will be passed as is.
provider_arguments << provider['args']
end

config.omniauth provider['name'].to_sym, *provider_arguments
end
end
end
6 changes: 6 additions & 0 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET'], scope: 'email,profile'
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET']
provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET']
end
Loading

0 comments on commit 35ce8db

Please sign in to comment.