Explorar o código

make more things configurable with .env and pull out deployment defaults

Andrew Cantino %!s(int64=12) %!d(string=hai) anos
pai
achega
24049c2c1d

+ 35 - 4
.env.example

@@ -1,6 +1,37 @@
+# ==== Required configuration settings for Huginn ====
+
+# Replace the following with the output from "rake secret"
 APP_SECRET_TOKEN=REPLACE_ME_NOW!
+
+# This is the domain where your Huginn instance will be running.  The default should work
+# for development, but it needs to be changed when you deploy to a production environment.
 DOMAIN=localhost:3000
-GOOGLE_APPS_DOMAIN=your-domain-here.com
-GMAIL_USERNAME=you@gmail.com
-GMAIL_PASSWORD=somepassword
-EMAIL_FROM_ADDRESS=from_address@gmail.com
+
+# Database Setup
+DATABASE_ADAPTER=mysql2
+DATABASE_ENCODING=utf8
+DATABASE_RECONNECT=true
+DATABASE_NAME=huginn_development
+DATABASE_POOL=5
+DATABASE_USERNAME=root
+DATABASE_PASSWORD=
+DATABASE_SOCKET=/tmp/mysql.sock
+
+# ==== Additional required production settings ====
+
+# Outgoing email settings.  To use Gmail or Google Apps, put your Google Apps domain or gmail.com
+# as the SMTP_DOMAIN and your Gmail username and password as the SMTP_USER_NAME and SMTP_PASSWORD.
+SMTP_DOMAIN=your-domain-here.com
+SMTP_USER_NAME=you@gmail.com
+SMTP_PASSWORD=somepassword
+SMTP_SERVER=smtp.gmail.com
+SMTP_PORT=587
+SMTP_AUTHENTICATION=plain
+SMTP_ENABLE_STARTTLS_AUTO=true
+
+# The address from which system emails will appear to be sent.
+EMAIL_FROM_ADDRESS=from_address@gmail.com
+
+# This invitation code will be required for users to signup with your Huginn installation.
+# You can see its use in user.rb.
+INVITATION_CODE=try-huginn

+ 0 - 7
Gemfile

@@ -40,14 +40,7 @@ platforms :ruby_18 do
   gem 'fastercsv'
 end
 
-group :production do
-  gem 'unicorn'
-end
-
 group :development do
-  gem 'capistrano'
-  gem 'capistrano-unicorn', :require => false
-  gem 'rvm-capistrano'
   gem 'pry'
 end
 

+ 0 - 28
Gemfile.lock

@@ -44,14 +44,6 @@ GEM
     bootstrap-sass (2.3.0.1)
       sass (~> 3.2)
     builder (3.0.4)
-    capistrano (2.14.2)
-      highline
-      net-scp (>= 1.0.0)
-      net-sftp (>= 2.0.0)
-      net-ssh (>= 2.0.14)
-      net-ssh-gateway (>= 1.1.0)
-    capistrano-unicorn (0.1.6)
-      capistrano
     coderay (1.0.9)
     coffee-rails (3.2.2)
       coffee-script (>= 2.2.0)
@@ -103,7 +95,6 @@ GEM
       rails (~> 3.0)
     haml (4.0.0)
       tilt
-    highline (1.6.15)
     hike (1.2.1)
     http_parser.rb (0.5.3)
     httparty (0.10.2)
@@ -123,7 +114,6 @@ GEM
     kaminari (0.14.1)
       actionpack (>= 3.0.0)
       activesupport (>= 3.0.0)
-    kgio (2.8.0)
     kramdown (0.14.2)
     mail (2.4.4)
       i18n (>= 0.4.0)
@@ -136,13 +126,6 @@ GEM
     multipart-post (1.2.0)
     mysql2 (0.3.11)
     nested_form (0.3.1)
-    net-scp (1.0.4)
-      net-ssh (>= 1.99.1)
-    net-sftp (2.1.1)
-      net-ssh (>= 2.6.5)
-    net-ssh (2.6.6)
-    net-ssh-gateway (1.2.0)
-      net-ssh (>= 2.6.5)
     nokogiri (1.5.6)
     orm_adapter (0.4.0)
     polyglot (0.3.3)
@@ -190,7 +173,6 @@ GEM
       rake (>= 0.8.7)
       rdoc (~> 3.4)
       thor (>= 0.14.6, < 2.0)
-    raindrops (0.10.0)
     rake (10.0.3)
     rdoc (3.12.2)
       json (~> 1.4)
@@ -213,8 +195,6 @@ GEM
       rspec-mocks (~> 2.13.0)
     rufus-scheduler (2.0.18)
       tzinfo (>= 0.3.23)
-    rvm-capistrano (1.2.7)
-      capistrano (>= 2.0.0)
     safe_yaml (0.8.4)
     sass (3.2.7)
     sass-rails (3.2.6)
@@ -251,10 +231,6 @@ GEM
     uglifier (1.3.0)
       execjs (>= 0.3.0)
       multi_json (~> 1.0, >= 1.0.2)
-    unicorn (4.6.2)
-      kgio (~> 2.6)
-      rack
-      raindrops (~> 0.7)
     warden (1.2.1)
       rack (>= 1.0)
     webmock (1.11.0)
@@ -270,8 +246,6 @@ PLATFORMS
 
 DEPENDENCIES
   bootstrap-kaminari-views
-  capistrano
-  capistrano-unicorn
   coffee-rails (~> 3.2.1)
   daemons
   delayed_job!
@@ -296,7 +270,6 @@ DEPENDENCIES
   rspec
   rspec-rails
   rufus-scheduler
-  rvm-capistrano
   sass-rails (~> 3.2.3)
   select2-rails
   system_timer
@@ -304,6 +277,5 @@ DEPENDENCIES
   twitter-stream (>= 0.1.16)
   typhoeus
   uglifier (>= 1.0.3)
-  unicorn
   webmock
   wunderground

+ 2 - 28
README.md

@@ -39,12 +39,9 @@ And now, some example screenshots.  Below them are instructions to get you start
 
 If you just want to play around, you can simply clone this repository, then perform the following steps:
 
-* Copy .env.example to .env `cp .env.example .env`
-* Edit the configuration options in .env
-* Edit the APP_SECRET_TOKEN environment variable and replace `REPLACE_ME_NOW!` with the output of `rake secret`.
+* Copy `.env.example` to `.env` (`cp .env.example .env`) and edit `.env`, at least updating the `APP_SECRET_TOKEN` variable.
 * Run `rake db:create`, `rake db:migrate`, and then `rake db:seed` to create a development MySQL database with some example seed data.
 * Run `foreman start`, visit `http://localhost:5000`, and login with the username of `admin` and the password of `password`.
-* Make some extra Terminal windows and run `bundle exec rails runner bin/schedule.rb`, `bundle exec rails runner bin/twitter_stream.rb`, and `script/delayed_job run` in separate windows.
 * Setup some Agents!
 
 ### Real Start
@@ -70,26 +67,7 @@ Follow these instructions if you wish to deploy your own version of Huginn or co
 
 ## Deployment
 
-Deployment right now is configured with Capistrano, Unicorn, and nginx.  You should feel free to deploy in a different way, however, and please submit your deployment solutions back!
-
-### Required Setup
-
-In your private copy of Huginn, do the following:
-
-* Edit `app/models/user.rb` and change the invitation code(s) in `INVITATION_CODES`.  This controls who can signup to use your installation.
-* Edit `app/mailers/system_mailer.rb` and set your default from address.
-* Edit `config/environments/production.rb` and change the value of `DOMAIN` and the `config.action_mailer.smtp_settings` setup, which is currently setup for sending email through a Google Apps account on Gmail.
-* Setup a place for Huginn to run.  I recommend making a dedicated user on your server for Huginn, but this is not required.  Setup nginx or Apache to proxy pass to unicorn.  There is an example nginx script in `config/nginx/production.conf`.
-* Setup a production MySQL database for your installation.
-* Edit `config/unicorn/production.rb` and replace instances of *you* with the correct username for your server.
-* Edit `config/deploy.rb` and change all instances of `you` and `yourdomain` to the appropriate values for your server setup.  If you want RVM to be used and installed, uncomment the appropriate lines.  Then, run `cap deploy:setup` followed by `cap deploy`.  If everything goes well, this should start some unicorn workers on your server to run the Huginn web app.
-* After deploying with capistrano, SSH into your server, go to the deployment directory, and run `RAILS_ENV=production bundle exec rake db:seed` to generate your admin user.  Immediately login to your new Huginn installation with the username of `admin` and the password of `password` and change your email and password!
-* You'll need to run bin/schedule.rb and bin/twitter_stream.rb in a daemonized way.  I've just been using screen sessions, but please contribute something better!
-
-
-        RAILS_ENV=production bundle exec rails runner bin/schedule.rb
-        RAILS_ENV=production bundle exec rails runner bin/twitter_stream.rb
-
+Please see [the Huginn Wiki](https://github.com/cantino/huginn/wiki#deploying-huginn) for detailed deployment strategies for different providers.
 
 ### Optional Setup
 
@@ -111,10 +89,6 @@ You can use [Post Location](https://github.com/cantino/post_location) on your iP
 
 We assume your deployment will run over SSL. This is a very good idea! However, if you wish to turn this off, you'll probably need to edit `config/initializers/devise.rb` and modify the line containing `config.rememberable_options = { :secure => true }`.  You will also need to edit `config/environments/production.rb` and modify the value of `config.force_ssl`.
 
-#### Setup Backups
-
-Checkout `config/example_backup.rb` for an example script that you can use with the Backup gem.
-
 ## License
 
 Huginn is provided under the MIT License.

+ 1 - 1
app/models/user.rb

@@ -5,7 +5,7 @@ class User < ActiveRecord::Base
   devise :database_authenticatable, :registerable,
          :recoverable, :rememberable, :trackable, :validatable, :lockable
 
-  INVITATION_CODES = %w[try-huginn]
+  INVITATION_CODES = [ENV['INVITATION_CODE'] || 'try-huginn']
 
   # Virtual attribute for authenticating by either username or email
   # This is in addition to a real persisted field like 'username'

+ 16 - 16
config/database.yml

@@ -1,12 +1,12 @@
 development:
-  adapter: mysql2
-  database: huginn_development
-  username: root
-  password:
-  socket: <%= ["/var/run/mysqld/mysqld.sock", "/opt/local/var/run/mysql5/mysqld.sock", "/tmp/mysql.sock"].find{ |path| File.exist? path } %>
-  encoding: utf8
-  reconnect: true
-  pool: 5
+  adapter: <%= ENV['DATABASE_ADAPTER'] || "mysql2" %>
+  encoding: <%= ENV['DATABASE_ENCODING'] || "utf8" %>
+  reconnect: <%= ENV['DATABASE_RECONNECT'] || "true" %>
+  database: <%= ENV['DATABASE_NAME'] || "huginn_development" %>
+  pool: <%= ENV['DATABASE_POOL'] || "5" %>
+  username: <%= ENV['DATABASE_USERNAME'] || "root" %>
+  password: <%= ENV['DATABASE_PASSWORD'] || "" %>
+  socket: <%= ENV['DATABASE_SOCKET'] || ["/var/run/mysqld/mysqld.sock", "/opt/local/var/run/mysql5/mysqld.sock", "/tmp/mysql.sock"].find{ |path| File.exist? path } %>
 
 # Warning: The database defined as "test" will be erased and
 # re-generated from your development database when you run "rake".
@@ -22,11 +22,11 @@ test:
   pool: 5
 
 production:
-  adapter: mysql2
-  encoding: utf8
-  reconnect: true
-  database: huginn_production
-  pool: 5
-  username: root
-  password: password
-  socket: /var/run/mysqld/mysqld.sock
+  adapter: <%= ENV['DATABASE_ADAPTER'] || "mysql2" %>
+  encoding: <%= ENV['DATABASE_ENCODING'] || "utf8" %>
+  reconnect: <%= ENV['DATABASE_RECONNECT'] || "true" %>
+  database: <%= ENV['DATABASE_NAME'] || "huginn_production" %>
+  pool: <%= ENV['DATABASE_POOL'] || "5" %>
+  username: <%= ENV['DATABASE_USERNAME'] || "root" %>
+  password: <%= ENV['DATABASE_PASSWORD'] || "password" %>
+  socket: <%= ENV['DATABASE_SOCKET'] || ["/var/run/mysqld/mysqld.sock", "/opt/local/var/run/mysql5/mysqld.sock", "/tmp/mysql.sock"].find{ |path| File.exist? path } %>

+ 7 - 7
config/environments/development.rb

@@ -38,12 +38,12 @@ Huginn::Application.configure do
   config.action_mailer.raise_delivery_errors = true
   config.action_mailer.delivery_method = :smtp
   config.action_mailer.smtp_settings = {
-      address: "smtp.gmail.com",
-      port: 587,
-      domain: ENV['GOOGLE_APPS_DOMAIN'],
-      authentication: "plain",
-      enable_starttls_auto: true,
-      user_name: ENV['GMAIL_USERNAME'],
-      password: ENV['GMAIL_PASSWORD']
+      address: ENV['SMTP_SERVER'] || 'smtp.gmail.com',
+      port: ENV['SMTP_PORT'] || 587,
+      domain: ENV['SMTP_DOMAIN'],
+      authentication: ENV['SMTP_AUTHENTICATION'] || 'plain',
+      enable_starttls_auto: ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true' ? true : false,
+      user_name: ENV['SMTP_USER_NAME'],
+      password: ENV['SMTP_PASSWORD']
   }
 end

+ 7 - 7
config/environments/production.rb

@@ -68,12 +68,12 @@ Huginn::Application.configure do
   config.action_mailer.raise_delivery_errors = true
   config.action_mailer.delivery_method = :smtp
   config.action_mailer.smtp_settings = {
-      address: "smtp.gmail.com",
-      port: 587,
-      domain: ENV['GOOGLE_APPS_DOMAIN'],
-      authentication: "plain",
-      enable_starttls_auto: true,
-      user_name: ENV['GMAIL_USERNAME'],
-      password: ENV['GMAIL_PASSWORD']
+      address: ENV['SMTP_SERVER'] || 'smtp.gmail.com',
+      port: ENV['SMTP_PORT'] || 587,
+      domain: ENV['SMTP_DOMAIN'],
+      authentication: ENV['SMTP_AUTHENTICATION'] || 'plain',
+      enable_starttls_auto: ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true' ? true : false,
+      user_name: ENV['SMTP_USER_NAME'],
+      password: ENV['SMTP_PASSWORD']
   }
 end

+ 6 - 12
config/example_backup.rb → doc/deployment/backup/example_backup.rb

@@ -10,23 +10,17 @@
 
 # You'll also need to install the backup gem on your server, as well as the net-ssh, excon, net-scp, and fog gems.
 
-database_yml = '/home/you/app/current/config/database.yml'
-rails_env    = ENV['RAILS_ENV'] || 'production'
-
-require 'yaml'
-config = YAML.load_file(database_yml)
-
 Backup::Model.new(:huginn_backup, 'The Huginn backup configuration') do
 
   split_into_chunks_of 4000
 
   database MySQL do |database|
-    database.name               = config[rails_env]["database"]
-    database.username           = config[rails_env]["username"]
-    database.password           = config[rails_env]["password"]
-    database.host               = config[rails_env]["host"]
-    database.port               = config[rails_env]["port"]
-    database.socket             = config[rails_env]["socket"]
+    database.name               = "your-database-name"
+    database.username           = "your-database-username"
+    database.password           = "your-database-password"
+    database.host               = "your-database-host"
+    database.port               = "your-database-port"
+    database.socket             = "your-database-socket"
     database.additional_options = ['--single-transaction', '--quick', '--hex-blob', '--add-drop-table']
   end
 

+ 19 - 9
config/deploy.rb → doc/deployment/capistrano/deploy.rb

@@ -25,21 +25,31 @@ after 'deploy', 'deploy:cleanup'
 
 set :bundle_without, [:development, :test]
 
-after "deploy:stop", "delayed_job:stop"
-after "deploy:start", "delayed_job:start"
-after "deploy:restart", "delayed_job:restart"
+after 'deploy:stop', 'delayed_job:stop'
+after 'deploy:start', 'delayed_job:start'
+after 'deploy:restart', 'delayed_job:restart'
+after 'deploy:update_code', 'deploy:symlink_env_config'
+
+namespace :deploy do
+  desc 'Link the environment file from shared/config/.env into the new deploy directory'
+  task :symlink_env_config, :roles => :app do
+    run <<-CMD
+      cd #{latest_release} && ln -nfs #{shared_path}/config/.env #{latest_release}/.env
+    CMD
+  end
+end
 
 # If you want to use command line options, for example to start multiple workers,
 # define a Capistrano variable delayed_job_args:
 #
 #   set :delayed_job_args, "-n 2"
 
-# If you want to use rvm on the server:
-# set :rvm_ruby_string, '1.9.3-p286@huginn'
-# set :rvm_type, :user
-# before 'deploy', 'rvm:install_rvm'
-# before 'deploy', 'rvm:install_ruby'
-# require "rvm/capistrano"
+# If you want to use rvm on your server and have it maintained by Capistrano, uncomment these lines:
+#   set :rvm_ruby_string, '1.9.3-p286@huginn'
+#   set :rvm_type, :user
+#   before 'deploy', 'rvm:install_rvm'
+#   before 'deploy', 'rvm:install_ruby'
+#   require "rvm/capistrano"
 
 # Load Capistrano additions
 Dir[File.expand_path("../../lib/capistrano/*.rb", __FILE__)].each{|f| load f }

+ 0 - 0
config/nginx/production.conf → doc/deployment/nginx/production.conf


+ 0 - 0
config/unicorn/production.rb → doc/deployment/unicorn/production.rb