Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: smashingboxes/personas
base: b270c9b07c
...
head fork: smashingboxes/personas
compare: 1f760f6f3a
  • 3 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
2  .gitignore
View
@@ -13,3 +13,5 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
+
+/config/database.yml
5 Capfile
View
@@ -0,0 +1,5 @@
+load 'deploy'
+# Uncomment if you are using Rails' asset pipeline
+load 'deploy/assets'
+Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
+load 'config/deploy' # remove this line to skip loading any of the default tasks
2  Gemfile
View
@@ -5,11 +5,13 @@ gem 'rails', '3.2.3'
gem 'activerecord-postgres-hstore'
gem 'bcrypt-ruby'
gem 'cancan'
+gem 'capistrano'
gem 'nokogiri'
gem 'oauth2-provider', :git => 'http://github.com/freerange/oauth2-provider.git'
gem 'pg'
gem 'rails_admin', :git => 'git://github.com/reedlaw/rails_admin.git'
gem 'rabl'
+gem 'unicorn'
# Gems used only for assets and not required
# in production environments by default.
22 Gemfile.lock
View
@@ -65,6 +65,12 @@ GEM
bootstrap-sass (2.0.2)
builder (3.0.0)
cancan (1.6.7)
+ capistrano (2.12.0)
+ highline
+ net-scp (>= 1.0.0)
+ net-sftp (>= 2.0.0)
+ net-ssh (>= 2.0.14)
+ net-ssh-gateway (>= 1.1.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -84,6 +90,7 @@ GEM
execjs (1.3.0)
multi_json (~> 1.0)
haml (3.1.4)
+ highline (1.6.11)
hike (1.2.1)
hpricot (0.8.6)
httpauth (0.1)
@@ -100,12 +107,20 @@ GEM
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
railties (>= 3.0.0)
+ kgio (2.7.4)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
multi_json (1.2.0)
+ net-scp (1.0.4)
+ net-ssh (>= 1.99.1)
+ net-sftp (2.0.5)
+ net-ssh (>= 2.0.9)
+ net-ssh (2.3.0)
+ net-ssh-gateway (1.1.0)
+ net-ssh (>= 1.99.1)
nokogiri (1.5.2)
pg (0.13.2)
polyglot (0.3.3)
@@ -137,6 +152,7 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
+ raindrops (0.8.0)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
@@ -159,6 +175,10 @@ GEM
uglifier (1.2.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
+ unicorn (4.3.0)
+ kgio (~> 2.6)
+ rack
+ raindrops (~> 0.7)
PLATFORMS
ruby
@@ -167,6 +187,7 @@ DEPENDENCIES
activerecord-postgres-hstore
bcrypt-ruby
cancan
+ capistrano
coffee-rails (~> 3.2.1)
debugger
jquery-rails
@@ -178,3 +199,4 @@ DEPENDENCIES
rails_admin!
sass-rails (~> 3.2.3)
uglifier (>= 1.0.3)
+ unicorn
6 app/controllers/sessions_controller.rb
View
@@ -19,8 +19,8 @@ def create
def destroy
# Remove user's session and return url
session[:user_id] = session[:return_url] = nil
- if params[:redirect]
- redirect_to params[:redirect]
+ if params[:redirect]
+ redirect_to params[:redirect]
else
redirect_to root_url, :notice => "Logged out!"
end
@@ -29,7 +29,7 @@ def destroy
private
def render_login(error = nil)
# Check if user is coming from another site
- ref = make_absolute(request.env['HTTP_REFERER'])
+ ref = make_absolute(URI.encode(request.env['HTTP_REFERER']))
host = make_absolute(request.url)
if host != ref || session[:ref].present?
# User is coming from client app
17 config/database.example.yml
View
@@ -0,0 +1,17 @@
+development:
+ adapter: postgresql
+ host: 127.0.0.1
+ database: personas
+ encoding: unicode
+ username: postgres
+ password: secret
+ pool: 5
+
+# 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:
+ adapter: postgresql
+
+production:
+ adapter: postgresql
51 config/deploy.rb
View
@@ -0,0 +1,51 @@
+require "bundler/capistrano"
+
+server "ec2-23-22-29-114.compute-1.amazonaws.com", :web, :app, :db, primary: true
+
+set :application, "personas"
+set :user, "personas"
+set :deploy_to, "/srv/#{application}"
+set :deploy_via, :remote_cache
+set :use_sudo, false
+
+set :scm, "git"
+set :repository, "git@github.com:smashingboxes/#{application}.git"
+set :branch, "master"
+
+default_run_options[:pty] = true
+ssh_options[:forward_agent] = true
+
+after "deploy", "deploy:cleanup" # keep only the last 5 releases
+
+namespace :deploy do
+ %w[start stop restart].each do |command|
+ desc "#{command} unicorn server"
+ task command, roles: :app, except: {no_release: true} do
+ run "/etc/init.d/unicorn_#{application} #{command}"
+ end
+ end
+
+ task :setup_config, roles: :app do
+ sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
+ sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
+ run "mkdir -p #{shared_path}/config"
+ put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
+ puts "Now edit the config files in #{shared_path}."
+ end
+ after "deploy:setup", "deploy:setup_config"
+
+ task :symlink_config, roles: :app do
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
+ end
+ after "deploy:finalize_update", "deploy:symlink_config"
+
+ desc "Make sure local git is in sync with remote."
+ task :check_revision, roles: :web do
+ unless `git rev-parse HEAD` == `git rev-parse origin/master`
+ puts "WARNING: HEAD is not the same as origin/master"
+ puts "Run `git push` to sync changes."
+ exit
+ end
+ end
+ before "deploy", "deploy:check_revision"
+end
27 config/nginx.conf
View
@@ -0,0 +1,27 @@
+upstream unicorn {
+ server unix:/tmp/unicorn.personas.sock fail_timeout=0;
+}
+
+server {
+ listen 80 default deferred;
+ # server_name example.com;
+ root /srv/personas/current/public;
+
+ location ^~ /assets/ {
+ gzip_static on;
+ expires max;
+ add_header Cache-Control public;
+ }
+
+ try_files $uri/index.html $uri @unicorn;
+ location @unicorn {
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header Host $http_host;
+ proxy_redirect off;
+ proxy_pass http://unicorn;
+ }
+
+ error_page 500 502 503 504 /500.html;
+ client_max_body_size 4G;
+ keepalive_timeout 10;
+}
9 config/unicorn.rb
View
@@ -0,0 +1,9 @@
+root = "/srv/personas/current"
+working_directory root
+pid "#{root}/tmp/pids/unicorn.pid"
+stderr_path "#{root}/log/unicorn.log"
+stdout_path "#{root}/log/unicorn.log"
+
+listen "/tmp/unicorn.personas.sock"
+worker_processes 2
+timeout 30
84 config/unicorn_init.sh
View
@@ -0,0 +1,84 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: unicorn
+# Required-Start: $remote_fs $syslog
+# Required-Stop: $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Manage unicorn server
+# Description: Start, stop, restart unicorn server for a specific application.
+### END INIT INFO
+set -e
+
+# Feel free to change any of the following variables for your app:
+TIMEOUT=${TIMEOUT-60}
+APP_ROOT=/srv/personas/current
+PID=$APP_ROOT/tmp/pids/unicorn.pid
+CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
+AS_USER=deployer
+set -u
+
+OLD_PIN="$PID.oldbin"
+
+sig () {
+ test -s "$PID" && kill -$1 `cat $PID`
+}
+
+oldsig () {
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
+}
+
+run () {
+ if [ "$(id -un)" = "$AS_USER" ]; then
+ eval $1
+ else
+ su -c "$1" - $AS_USER
+ fi
+}
+
+case "$1" in
+start)
+ sig 0 && echo >&2 "Already running" && exit 0
+ run "$CMD"
+ ;;
+stop)
+ sig QUIT && exit 0
+ echo >&2 "Not running"
+ ;;
+force-stop)
+ sig TERM && exit 0
+ echo >&2 "Not running"
+ ;;
+restart|reload)
+ sig HUP && echo reloaded OK && exit 0
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
+ run "$CMD"
+ ;;
+upgrade)
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
+ then
+ n=$TIMEOUT
+ while test -s $OLD_PIN && test $n -ge 0
+ do
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
+ done
+ echo
+
+ if test $n -lt 0 && test -s $OLD_PIN
+ then
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
+ exit 1
+ fi
+ exit 0
+ fi
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
+ run "$CMD"
+ ;;
+reopen-logs)
+ sig USR1
+ ;;
+*)
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
+ exit 1
+ ;;
+esac

No commit comments for this range

Something went wrong with that request. Please try again.