diff --git a/Gemfile b/Gemfile index 4890a76..cebd327 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ ruby (ENV['RUBY_VERSION'] || '2.0.0') unless ENV['CI'] RAILS_VERSION = '~> 3.2.15' +gem 'rails', RAILS_VERSION gem 'actionmailer', RAILS_VERSION gem 'actionpack', RAILS_VERSION gem 'railties', RAILS_VERSION diff --git a/Gemfile.lock b/Gemfile.lock index e97ba77..472caba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -413,6 +413,7 @@ DEPENDENCIES quiet_assets rack-ssl rack-ssl-enforcer + rails (~> 3.2.15) rails_autolink railties (~> 3.2.15) ri_cal diff --git a/config/cloud/cloud66/deploy_hooks.yml b/config/cloud/cloud66/deploy_hooks.yml new file mode 100644 index 0000000..b7a4538 --- /dev/null +++ b/config/cloud/cloud66/deploy_hooks.yml @@ -0,0 +1,131 @@ +production: + after_checkout: + - source: /config/cloud/cloud66/files/Procfile + destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/_load_config.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/initializers/_load_config.rb + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/config.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/config.yml + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/mongoid.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/mongoid.yml + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/secret_token.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/initializers/secret_token.rb + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/seeds.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/db/seeds.rb + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/unicorn.rb.cloud66 + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/unicorn.rb.cloud66 + target: rails + run_on: all_servers + after_rails: + - source: /config/cloud/cloud66/scripts/bundle.sh + destination: /tmp/bundle.sh + target: rails + apply_during: build_only + execute: true + sudo: true + - source: /config/cloud/cloud66/scripts/env_vars.sh + destination: /tmp/env_vars.sh + target: rails + apply_during: build_only + execute: true + sudo: true +staging: + after_checkout: + - source: /config/cloud/cloud66/files/Procfile + destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/_load_config.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/initializers/_load_config.rb + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/config.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/config.yml + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/mongoid.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/mongoid.yml + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/secret_token.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/initializers/secret_token.rb + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/seeds.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/db/seeds.rb + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/unicorn.rb.cloud66 + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/unicorn.rb.cloud66 + target: rails + run_on: all_servers + after_rails: + - source: /config/cloud/cloud66/scripts/bundle.sh + destination: /tmp/bundle.sh + target: rails + apply_during: build_only + execute: true + sudo: true + - source: /config/cloud/cloud66/scripts/env_vars.sh + destination: /tmp/env_vars.sh + target: rails + apply_during: build_only + execute: true + sudo: true + parse: true +development: + after_checkout: + - source: /config/cloud/cloud66/files/Procfile + destination: <%= ENV['RAILS_STACK_PATH'] %>/Procfile + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/_load_config.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/initializers/_load_config.rb + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/config.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/config.yml + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/mongoid.yml + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/mongoid.yml + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/secret_token.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/initializers/secret_token.rb + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/seeds.rb + destination: <%= ENV['RAILS_STACK_PATH'] %>/db/seeds.rb + target: rails + run_on: all_servers + - source: /config/cloud/cloud66/files/unicorn.rb.cloud66 + destination: <%= ENV['RAILS_STACK_PATH'] %>/config/unicorn.rb.cloud66 + target: rails + run_on: all_servers + after_rails: + - source: /config/cloud/cloud66/scripts/bundle.sh + destination: /tmp/bundle.sh + target: rails + apply_during: build_only + execute: true + sudo: true + - source: /config/cloud/cloud66/scripts/env_vars.sh + destination: /tmp/env_vars.sh + target: rails + apply_during: build_only + execute: true + sudo: true + parse: true diff --git a/config/cloud/cloud66/files/Procfile b/config/cloud/cloud66/files/Procfile new file mode 100644 index 0000000..b46e45f --- /dev/null +++ b/config/cloud/cloud66/files/Procfile @@ -0,0 +1,2 @@ +web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb +custom_web: bundle exec unicorn_rails -c config/unicorn.rb.cloud66 -E $RAILS_ENV -D \ No newline at end of file diff --git a/config/cloud/cloud66/files/_load_config.rb b/config/cloud/cloud66/files/_load_config.rb new file mode 100644 index 0000000..a1339c9 --- /dev/null +++ b/config/cloud/cloud66/files/_load_config.rb @@ -0,0 +1,82 @@ +require 'ostruct' +default_config_file = Rails.root.join("config", "config.yml") + +# Allow a Rails Engine to override config by defining it earlier +unless defined?(Errbit::Config) + Errbit::Config = OpenStruct.new + + Errbit::Config.host = ENV['ERRBIT_HOST'] + Errbit::Config.email_from = ENV['ERRBIT_EMAIL_FROM'] + # Not really easy to use like an env because need an array and ENV return a string :( + # Errbit::Config.email_at_notices = ENV['ERRBIT_EMAIL_AT_NOTICES'] + Errbit::Config.confirm_resolve_err = ENV['ERRBIT_CONFIRM_RESOLVE_ERR'].to_i == 0 + Errbit::Config.user_has_username = ENV['ERRBIT_USER_HAS_USERNAME'].to_i == 1 + Errbit::Config.allow_comments_with_issue_tracker = ENV['ERRBIT_ALLOW_COMMENTS_WITH_ISSUE_TRACKER'].to_i == 0 + Errbit::Config.enforce_ssl = ENV['ERRBIT_ENFORCE_SSL'] + + Errbit::Config.use_gravatar = ENV['ERRBIT_USE_GRAVATAR'] + Errbit::Config.gravatar_default = ENV['ERRBIT_GRAVATAR_DEFAULT'] + + Errbit::Config.github_authentication = ENV['GITHUB_AUTHENTICATION'] + Errbit::Config.github_client_id = ENV['GITHUB_CLIENT_ID'] + Errbit::Config.github_secret = ENV['GITHUB_SECRET'] + Errbit::Config.github_access_scope = ENV['GITHUB_ACCESS_SCOPE'].split(',').map(&:strip) if ENV['GITHUB_ACCESS_SCOPE'] + + Errbit::Config.smtp_settings = { + :address => ENV['SMTP_SERVER'] || 'smtp.sendgrid.net', + :port => ENV['SMTP_PORT'] || 25, + :authentication => :plain, + :user_name => ENV['SMTP_USERNAME'] || ENV['SENDGRID_USERNAME'], + :password => ENV['SMTP_PASSWORD'] || ENV['SENDGRID_PASSWORD'], + :domain => ENV['SMTP_DOMAIN'] || ENV['SENDGRID_DOMAIN'] + } + + # Use example config for test environment. + config_file = Rails.env == "test" ? default_config_file : Rails.root.join("config", "config.yml") + + # Load config if config file exists. + if File.exists?(config_file) + config = YAML.load_file(config_file) + config.merge!(config.delete(Rails.env)) if config.has_key?(Rails.env) + config.each do |k,v| + Errbit::Config.send("#{k}=", v) + end + # Show message if we are not running tests, not running on Heroku, and config.yml doesn't exist. + elsif not use_env + puts "Please copy 'config/config.example.yml' to 'config/config.yml' and configure your settings. Using default settings." + end + + # Set default devise modules + Errbit::Config.devise_modules = [:database_authenticatable, + :recoverable, :rememberable, :trackable, + :validatable, :token_authenticatable, :omniauthable] +end + +# Set default settings from config.example.yml if key is missing from config.yml +default_config = YAML.load_file(default_config_file) +default_config.each do |k,v| + Errbit::Config.send("#{k}=", v) if Errbit::Config.send(k) === nil +end + +# Disable GitHub oauth if gem is missing +Errbit::Config.github_authentication = false unless defined?(OmniAuth::Strategies::GitHub) + +# Set SMTP settings if given. +if smtp = Errbit::Config.smtp_settings + ActionMailer::Base.delivery_method = :smtp + ActionMailer::Base.smtp_settings = smtp +end + +if sendmail = Errbit::Config.sendmail_settings + ActionMailer::Base.delivery_method = :sendmail + ActionMailer::Base.sendmail_settings = sendmail +end + +# Set config specific values +(ActionMailer::Base.default_url_options ||= {}).tap do |default| + default.merge! :host => Errbit::Config.host if default[:host].blank? +end + +if Rails.env.production? + Rails.application.config.consider_all_requests_local = Errbit::Config.display_internal_errors +end diff --git a/config/cloud/cloud66/files/config.yml b/config/cloud/cloud66/files/config.yml new file mode 100644 index 0000000..cea2318 --- /dev/null +++ b/config/cloud/cloud66/files/config.yml @@ -0,0 +1,98 @@ +# The host of your errbit server + +# Enforce SSL connections +enforce_ssl: false + +# The email address which email notifications +# will be sent from. +#email_from: + +# If you turn on this option, email_at_notices can be +# configured on a per app basis, at the App edit page +per_app_email_at_notices: false + +# Configure when emails are sent for an error. +# [1,3,7] = 1st, 3rd, and 7th occurence triggers +# an email notification. +email_at_notices: [1, 10, 100] + +# If you turn on this option, notify_at_notices can be +# configured on a per app basis, at the App edit page +per_app_notify_at_notices: false + +# Configure when emails are sent for an error. +# [1,3,7] = 1st, 3rd, and 7th occurence triggers +# [0] for all notices, provided notification service is configured +notify_at_notices: [0] + +# Configure whether or not the user should be prompted before resolving an error. +confirm_resolve_err: true + +# Add an optional 'username' field to Users. +# Helpful when you need to plug in a custom authentication strategy, such as LDAP. +user_has_username: false + +# Allow comments while an issue tracker is configured. +# This is useful if the err is not critical enough to create a ticket, +# but you want to leave a short comment. +allow_comments_with_issue_tracker: true + +# Display internal errors in production +# Since this is an internal application, you might like to see what caused Errbit to crash. +# Pull requests are always welcome! +# However, you might be more comfortable setting this to false if your server can be accessed by anyone. +display_internal_errors: true +# The host of your errbit server + +allow_comments_with_issue_tracker: true +# Enable Gravatar. +use_gravatar: true +# Default Gravatar image, can be: mm, identicon, monsterid, wavatar, retro. +gravatar_default: identicon + +# Setup your deploy options for capistrano. +#deployment: +# hosts: +# web: errbit.example.com +# app: errbit.example.com +# db: errbit.example.com +# repository: http://github.com/errbit/errbit.git +# branch: master +# user: deploy +# deploy_to: /var/www/apps/errbit +# # setup path to unicorn pids folder (or deploy_to/shared/pids will be used) +# # pids: /var/www/apps/errbit/shared/pids + +# GitHub OAuth configuration +# If you want to allow authentication via GitHub, you will need to register +# your app at: https://github.com/settings/applications +# If you hosted Errbit at errbit.example.com, you would fill in: +# +# URL: http://errbit.example.com/ +# Callback URL: http://errbit.example.com/users/auth/github +# +# After you have registered your app, copy your Client ID and Secret key below. + +# GitHub Permissions to request from user +# ['repo'] - Allow creating issues for public and private repos. +# ['public_repo'] - Only allow creating issues for public repos. +# [] - No permission to create issues on any repos. +github_access_scope: ['repo'] + +# Configure SMTP settings. If you are running Errbit on Heroku, +# sendgrid will be configured by default. +# ------------------------------------------------------------------------ +#smtp_settings: +# :address: +# :domain: +# :port: +# :authentication: :plain +# :enable_starttls_auto: +# :user_name: +# :password: + + +# If you want send your email by your sendmail +# sendmail_settings: +# :location: '/usr/sbin/sendmail' +# :arguments: '-i -t' \ No newline at end of file diff --git a/config/cloud/cloud66/files/mongoid.yml b/config/cloud/cloud66/files/mongoid.yml new file mode 100644 index 0000000..f0eb2f2 --- /dev/null +++ b/config/cloud/cloud66/files/mongoid.yml @@ -0,0 +1,38 @@ +# Mongoid Configuration +# ===================== +# +# Copy this file to config/mongoid.yml and +# modify it accordingly. This file will automatically +# be copied to shared/config on the server when +# `cap deploy:setup` is ran the first time. Be sure +# to place production specific settings there + +development: + sessions: + default: + database: errbit_development + hosts: + - '<%=ENV["MONGODB_ADDRESS"]%>:27017' + options: + identity_map_enabled: true + use_utc: true + +test: + sessions: + default: + hosts: + - localhost:27017 + database: errbit_test + options: + identity_map_enabled: true + use_utc: true + +# set these environment variables on your prod server +production: + sessions: + default: + database: errbit + hosts: + - '<%=ENV["MONGODB_ADDRESS"]%>:27017' + options: + identity_map_enabled: true \ No newline at end of file diff --git a/config/cloud/cloud66/files/secret_token.rb b/config/cloud/cloud66/files/secret_token.rb new file mode 100644 index 0000000..d5358c2 --- /dev/null +++ b/config/cloud/cloud66/files/secret_token.rb @@ -0,0 +1,2 @@ +Errbit::Application.config.secret_token = '<%= ENV['SECRET_TOKEN'] %>' +Devise.secret_key = Errbit::Application.config.secret_token diff --git a/config/cloud/cloud66/files/seeds.rb b/config/cloud/cloud66/files/seeds.rb new file mode 100644 index 0000000..619a846 --- /dev/null +++ b/config/cloud/cloud66/files/seeds.rb @@ -0,0 +1,25 @@ +puts "Seeding database" +puts "-------------------------------" + +# Create an initial Admin User +admin_username = "errbit" +admin_email = "errbit@host.com" +admin_pass = 'password' + +puts "Creating an initial admin user:" +puts "-- username: #{admin_username}" if Errbit::Config.user_has_username +puts "-- email: #{admin_email}" +puts "-- password: #{admin_pass}" +puts "" +puts "Be sure to change these credentials ASAP!" +user = User.where(:email => admin_email).first || User.new({ + :name => 'Errbit Admin', + :email => admin_email, + :password => admin_pass, + :password_confirmation => admin_pass + }) +user.username = admin_username if Errbit::Config.user_has_username + +user.admin = true +user.save! + diff --git a/config/cloud/cloud66/files/unicorn.rb.cloud66 b/config/cloud/cloud66/files/unicorn.rb.cloud66 new file mode 100644 index 0000000..15b912d --- /dev/null +++ b/config/cloud/cloud66/files/unicorn.rb.cloud66 @@ -0,0 +1,36 @@ +worker_processes 3 +timeout 30 + +working_directory "#{ENV['RAILS_STACK_PATH']}" + +listen "/tmp/web_server.sock", :backlog => 64 + +pid '/tmp/web_server.pid' + +stderr_path "#{ENV['RAILS_STACK_PATH']}/log/unicorn.stderr.log" +stdout_path "#{ENV['RAILS_STACK_PATH']}/log/unicorn.stdout.log" + +preload_app true +GC.respond_to?(:copy_on_write_friendly=) and + GC.copy_on_write_friendly = true + +check_client_connection false + +before_fork do |server, worker| + old_pid = '/tmp/web_server.pid.oldbin' + if File.exists?(old_pid) && server.pid != old_pid + begin + Process.kill("QUIT", File.read(old_pid).to_i) + rescue Errno::ENOENT, Errno::ESRCH + # someone else did our job for us + end + end + + defined?(ActiveRecord::Base) and + ActiveRecord::Base.connection.disconnect! +end + +after_fork do |server, worker| + defined?(ActiveRecord::Base) and + ActiveRecord::Base.establish_connection +end \ No newline at end of file diff --git a/config/cloud/cloud66/manifest.yml b/config/cloud/cloud66/manifest.yml new file mode 100644 index 0000000..caf4991 --- /dev/null +++ b/config/cloud/cloud66/manifest.yml @@ -0,0 +1,24 @@ +production: + rails: + server: + unique_name: frontend + configuration: + ruby_version: 2.0.0 + environment_variables: + SECRET_TOKEN: AUTO_GENERATE_30 +staging: + rails: + server: + unique_name: frontend + configuration: + ruby_version: 2.0.0 + environment_variables: + SECRET_TOKEN: AUTO_GENERATE_30 +development: + rails: + server: + unique_name: frontend + configuration: + ruby_version: 2.0.0 + environment_variables: + SECRET_TOKEN: AUTO_GENERATE_30 diff --git a/config/cloud/cloud66/scripts/bundle.sh b/config/cloud/cloud66/scripts/bundle.sh new file mode 100644 index 0000000..6427785 --- /dev/null +++ b/config/cloud/cloud66/scripts/bundle.sh @@ -0,0 +1,12 @@ +#!/bin/bash +FILE=/tmp/bundle_done + +if [ -f $FILE ] +then + echo "File $FILE exists..." +else + cd $STACK_PATH + bundle exec rake db:mongoid:create_indexes + bundle exec rake db:seed + touch /tmp/bundle_done +fi \ No newline at end of file diff --git a/config/cloud/cloud66/scripts/env_vars.sh b/config/cloud/cloud66/scripts/env_vars.sh new file mode 100644 index 0000000..3fe5ff5 --- /dev/null +++ b/config/cloud/cloud66/scripts/env_vars.sh @@ -0,0 +1,24 @@ +#!/bin/bash +FILE=/tmp/env_vars_done + +if [ -f $FILE ] +then + echo "File $FILE exists..." +else + cd $RAILS_STACK_PATH + echo "github_authentication: $GITHUB_AUTHENTICATION + github_client_id: $GITHUB_CLIENT_ID + github_secret: $GITHUB_SECRET + ERRBIT_EMAIL_FROM: $MAILER_SENDER + host: $ERRBIT_HOST + email_from: $MAILER_SENDER + smtp_settings: + :address: $SMTP_ADDRESS + :domain: $SMTP_DOMAIN + :port: $SMTP_PORT + :authentication: :plain + :enable_starttls_auto: "true" + :user_name: $SMTP_USERNAME + :password: $SMTP_PASSWORD" >> config/config.yml + touch /tmp/env_vars_done +fi \ No newline at end of file -- libgit2 0.21.2