Skip to content

Instantly share code, notes, and snippets.

@coffeencoke
Last active May 19, 2017 08:02
Show Gist options
  • Select an option

  • Save coffeencoke/4422617 to your computer and use it in GitHub Desktop.

Select an option

Save coffeencoke/4422617 to your computer and use it in GitHub Desktop.

Revisions

  1. coffeencoke revised this gist Mar 19, 2013. 1 changed file with 10 additions and 8 deletions.
    18 changes: 10 additions & 8 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -16,11 +16,13 @@ Added an issue in github: https://github.com/capistrano/capistrano/issues/379
    Work around is to manually run the rake assets precompile method in app/shared/cached-copy
    and move the assets/admin/manifest.yml file to /app/shared/assets/manifest.yml

    $ cap ui deploy:setup deploy:cold # this will fail, but will setup our files for us
    $ ssh [email protected]
    $ cd ~/apps/admin-app.coffeencoke.com/shared/cached-copy
    $ bundle install --without test development
    $ bundle exec rake RAILS_ENV=qa RAILS_GROUPS=assets assets:precompile
    $ cp -- public/admin/assets/manifest.yml ../assets/
    $ exit
    $ cap ui deploy:cold
    ```
    $ cap ui deploy:setup deploy:cold # this will fail, but will setup our files for us
    $ ssh [email protected]
    $ cd ~/apps/admin-app.coffeencoke.com/shared/cached-copy
    $ bundle install --without test development
    $ bundle exec rake RAILS_ENV=qa RAILS_GROUPS=assets assets:precompile
    $ cp -- public/admin/assets/manifest.yml ../assets/
    $ exit
    $ cap ui deploy:cold
    ```
  2. coffeencoke revised this gist Mar 19, 2013. 1 changed file with 18 additions and 1 deletion.
    19 changes: 18 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,21 @@ For example, if you have an app at `/home/coffeencoke/apps/app.coffeencoke.com/c

    ```bash
    ln -s /home/coffeencoke/apps/admin-app.coffeencoke.com/current/public /home/coffeencoke/apps/app.coffeencoke.com/current/public/admin
    ```
    ```

    Also...

    Issue when deploying a fresh environment and running deploy:cold
    you may get an error that says "cannot stat /....manifest.yml"
    Added an issue in github: https://github.com/capistrano/capistrano/issues/379
    Work around is to manually run the rake assets precompile method in app/shared/cached-copy
    and move the assets/admin/manifest.yml file to /app/shared/assets/manifest.yml

    $ cap ui deploy:setup deploy:cold # this will fail, but will setup our files for us
    $ ssh [email protected]
    $ cd ~/apps/admin-app.coffeencoke.com/shared/cached-copy
    $ bundle install --without test development
    $ bundle exec rake RAILS_ENV=qa RAILS_GROUPS=assets assets:precompile
    $ cp -- public/admin/assets/manifest.yml ../assets/
    $ exit
    $ cap ui deploy:cold
  3. coffeencoke revised this gist Feb 21, 2013. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # Symlink for static files

    Among applying the changes in the other files in this gist, you need to symlink the directory you are serving the app with in the root app's public directory so that NGINX can serve the static files in the sub-app.

    For example, if you have an app at `/home/coffeencoke/apps/app.coffeencoke.com/current/public` as your root app, and you have the sub app served at <http://app.coffeencoke.com/admin>, then you need to symlink `/home/coffeencoke/apps/admin-app.coffeencoke.com/current/public` to `/home/coffeencoke/apps/app.coffeencoke.com/current/public/admin` like so:

    ```bash
    ln -s /home/coffeencoke/apps/admin-app.coffeencoke.com/current/public /home/coffeencoke/apps/app.coffeencoke.com/current/public/admin
    ```
  4. coffeencoke revised this gist Feb 20, 2013. 6 changed files with 71 additions and 64 deletions.
    14 changes: 14 additions & 0 deletions application.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # This is for the admin app only
    #
    # Among other app config things, add these two lines within your Application.configure block
    #
    # You can also put this in the config file for each individual environment. So you can still use
    # localhost:3000 w/out the subdirectory for development mode and tests and such.
    #
    AppAdmin::Application.configure do
    # ...

    # Serve the app from host/admin
    config.root_directory = '/admin'
    config.assets.prefix = '/admin/assets/'
    end
    8 changes: 0 additions & 8 deletions development.rb
    Original file line number Diff line number Diff line change
    @@ -1,8 +0,0 @@
    # goes in config/environments/development.rb

    MyApp::Application.configure do
    # Contains configurations for the production environment
    # ...

    # Does not include config.root_directory
    end
    69 changes: 42 additions & 27 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,44 @@
    # Goes in /etc/nginx/sites-available/myapp.conf
    upstream unicorn_socket_for_myapp {
    server unix:/home/coffeencoke/apps/myapp/current/tmp/sockets/unicorn.sock fail_timeout=0;
    worker_processes 1;

    events {
    worker_connections 1024;
    }

    server {
    listen 80;
    server_name coffeencoke.com www.coffeencoke.com;
    access_log /var/log/nginx/myapp.access.log;
    error_log /var/log/nginx/myapp.error.log debug;
    root /home/coffeencoke/apps/myapp/current/public;

    # If static file exists, load directly from Nginx, bypass Rails
    # Otherwise, pass request off to unicorn proxy
    location /myapp/ {
    try_files $uri @unicorn_proxy;

    http {
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    keepalive_timeout 65;

    server {
    listen 80;
    server_name app.coffeencoke.com app;
    access_log /var/log/nginx/app.coffeencoke.com.access.log;
    error_log /var/log/nginx/app.coffeencoke.com.error.log info;
    root /home/coffeencoke/app.coffeencoke.com/public;

    location / {
    try_files $uri @unicorn_proxy;
    }

    location @unicorn_proxy {
    proxy_pass http://127.0.0.1:8081;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /admin {
    try_files $uri @unicorn_proxy_admin;
    }

    location @unicorn_proxy_admin {
    proxy_pass http://127.0.0.1:8080;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Forwarded-Proto $scheme;
    }
    }

    location @unicorn_proxy {
    proxy_pass http://unix:/home/coffeencoke/apps/myapp/current/tmp/sockets/unicorn.sock;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    error_page 500 502 503 504 /500.html;
    }
    }
    9 changes: 0 additions & 9 deletions production.rb
    Original file line number Diff line number Diff line change
    @@ -1,9 +0,0 @@
    # goes in config/environments/production.rb

    MyApp::Application.configure do
    # Contains configurations for the production environment
    # ...

    # Serve the application at /myapp
    config.root_directory = '/myapp'
    end
    11 changes: 0 additions & 11 deletions route_scoper.rb
    Original file line number Diff line number Diff line change
    @@ -1,11 +0,0 @@
    # goes in lib/route_scoper.rb

    require 'rails/application'

    module RouteScoper
    def self.root
    Rails.application.config.root_directory
    rescue NameError
    '/'
    end
    end
    24 changes: 15 additions & 9 deletions routes.rb
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,18 @@
    # goes in config/routes.rb

    require_relative '../lib/route_scoper'

    MyApp::Application.routes.draw do
    require 'rails/application'

    module RouteScoper
    # Keep the rescue so that you can revert to not having a
    # subdirectory when in development and test modes
    def self.root
    Rails.application.config.root_directory
    rescue NameError
    '/'
    end
    end

    MagnetTesterAdmin::Application.routes.draw do
    scope RouteScoper.root do
    root :to => 'registrations#new'

    # other routes are always inside this block
    # ...
    resource :session, only: :new
    root :to => 'awesome_rootness#show'
    end
    end
  5. coffeencoke created this gist Dec 31, 2012.
    8 changes: 8 additions & 0 deletions development.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # goes in config/environments/development.rb

    MyApp::Application.configure do
    # Contains configurations for the production environment
    # ...

    # Does not include config.root_directory
    end
    29 changes: 29 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    # Goes in /etc/nginx/sites-available/myapp.conf

    upstream unicorn_socket_for_myapp {
    server unix:/home/coffeencoke/apps/myapp/current/tmp/sockets/unicorn.sock fail_timeout=0;
    }

    server {
    listen 80;
    server_name coffeencoke.com www.coffeencoke.com;
    access_log /var/log/nginx/myapp.access.log;
    error_log /var/log/nginx/myapp.error.log debug;
    root /home/coffeencoke/apps/myapp/current/public;

    # If static file exists, load directly from Nginx, bypass Rails
    # Otherwise, pass request off to unicorn proxy
    location /myapp/ {
    try_files $uri @unicorn_proxy;
    }

    location @unicorn_proxy {
    proxy_pass http://unix:/home/coffeencoke/apps/myapp/current/tmp/sockets/unicorn.sock;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    error_page 500 502 503 504 /500.html;
    }
    9 changes: 9 additions & 0 deletions production.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # goes in config/environments/production.rb

    MyApp::Application.configure do
    # Contains configurations for the production environment
    # ...

    # Serve the application at /myapp
    config.root_directory = '/myapp'
    end
    11 changes: 11 additions & 0 deletions route_scoper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # goes in lib/route_scoper.rb

    require 'rails/application'

    module RouteScoper
    def self.root
    Rails.application.config.root_directory
    rescue NameError
    '/'
    end
    end
    12 changes: 12 additions & 0 deletions routes.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # goes in config/routes.rb

    require_relative '../lib/route_scoper'

    MyApp::Application.routes.draw do
    scope RouteScoper.root do
    root :to => 'registrations#new'

    # other routes are always inside this block
    # ...
    end
    end