@@ -3,3 +3,5 @@ |
||
3 | 3 |
# available. Otherwise it will execute while your application is stopped |
4 | 4 |
# before the deploy step. This script gets executed directly, so it |
5 | 5 |
# could be python, php, ruby, etc. |
6 |
+ |
|
7 |
+echo "-> Build step" |
@@ -4,6 +4,41 @@ |
||
4 | 4 |
# up again. This script gets executed directly, so it could be python, php, |
5 | 5 |
# ruby, etc. |
6 | 6 |
|
7 |
+echo "-> Deploy step" |
|
8 |
+ |
|
7 | 9 |
pushd ${OPENSHIFT_REPO_DIR} > /dev/null |
10 |
+ |
|
11 |
+if [ -f ${OPENSHIFT_REPO_DIR}/.env.example ] |
|
12 |
+then |
|
13 |
+ # Default to the environment variable values set in .env.example |
|
14 |
+# source ${OPENSHIFT_REPO_DIR}/.env.example |
|
15 |
+# |
|
16 |
+# grep = ${OPENSHIFT_REPO_DIR}/.env.example | sed -e 's/^#[^ ]//' | grep -v -e '^#' | cut -d= -f1 | \ |
|
17 |
+# while read var ; do |
|
18 |
+# eval "echo \"$var=\\\"\${HUGINN_$var:-\$$var}\\\"\"" |
|
19 |
+# done | grep -v -e ^= > ${OPENSHIFT_REPO_DIR}/.env |
|
20 |
+ |
|
21 |
+ echo "DATABASE_NAME=${OPENSHIFT_APP_NAME}" > ${OPENSHIFT_REPO_DIR}/.env |
|
22 |
+ echo "DATABASE_USERNAME=${OPENSHIFT_MYSQL_DB_USERNAME}" >> ${OPENSHIFT_REPO_DIR}/.env |
|
23 |
+ echo "DATABASE_PASSWORD=${OPENSHIFT_MYSQL_DB_PASSWORD}" >> ${OPENSHIFT_REPO_DIR}/.env |
|
24 |
+ echo "DATABASE_HOST=${OPENSHIFT_MYSQL_DB_HOST}" >> ${OPENSHIFT_REPO_DIR}/.env |
|
25 |
+ echo "DATABASE_PORT=${OPENSHIFT_MYSQL_DB_PORT}" >> ${OPENSHIFT_REPO_DIR}/.env |
|
26 |
+ echo "DATABASE_SOCKET=${OPENSHIFT_MYSQL_DB_SOCKET}" >> ${OPENSHIFT_REPO_DIR}/.env |
|
27 |
+ |
|
28 |
+ chmod ugo+r ${OPENSHIFT_REPO_DIR}/.env |
|
29 |
+ |
|
30 |
+ source ${OPENSHIFT_REPO_DIR}/.env |
|
31 |
+else |
|
32 |
+ cat <<EOM |
|
33 |
+*** |
|
34 |
+* |
|
35 |
+* WARNING: No .env.example file found. |
|
36 |
+* |
|
37 |
+*** |
|
38 |
+EOM |
|
39 |
+fi |
|
40 |
+ |
|
41 |
+gem install bundler |
|
42 |
+echo "Migrating" |
|
8 | 43 |
RAILS_ENV="production" bundle exec rake db:migrate |
9 | 44 |
popd > /dev/null |
@@ -2,3 +2,5 @@ |
||
2 | 2 |
# This is a simple post deploy hook executed after your application |
3 | 3 |
# is deployed and started. This script gets executed directly, so |
4 | 4 |
# it could be python, php, ruby, etc. |
5 |
+ |
|
6 |
+echo "-> Post deploy step" |
@@ -13,3 +13,4 @@ |
||
13 | 13 |
# Application start and stop is subject to different timeouts |
14 | 14 |
# throughout the system. |
15 | 15 |
|
16 |
+echo "-> Post start ruby step" |
@@ -12,3 +12,5 @@ |
||
12 | 12 |
# prevent your application from stopping cleanly or starting at all. |
13 | 13 |
# Application start and stop is subject to different timeouts |
14 | 14 |
# throughout the system. |
15 |
+ |
|
16 |
+echo "-> Post stop ruby step" |
@@ -4,6 +4,8 @@ |
||
4 | 4 |
# before the build step. This script gets executed directly, so it |
5 | 5 |
# could be python, php, ruby, etc. |
6 | 6 |
|
7 |
+echo "-> Pre-build step" |
|
8 |
+ |
|
7 | 9 |
STORED_ASSETS="${OPENSHIFT_DATA_DIR}/assets" |
8 | 10 |
LIVE_ASSETS="${OPENSHIFT_REPO_DIR}/public/assets" |
9 | 11 |
|
@@ -13,20 +13,16 @@ |
||
13 | 13 |
# Application start and stop is subject to different timeouts |
14 | 14 |
# throughout the system. |
15 | 15 |
|
16 |
+echo "-> Pro start ruby step" |
|
17 |
+ |
|
16 | 18 |
if [ -f ${OPENSHIFT_REPO_DIR}/.env.example ] |
17 | 19 |
then |
18 |
- grep = ${OPENSHIFT_REPO_DIR}/.env.example | sed -e 's/^#[^ ]//' | grep -v -e '^#' | cut -d= -f1 | \ |
|
19 |
- while read var ; do |
|
20 |
- eval "echo \"$var=\\\"\${$var:-\$$var}\\\"\"" |
|
21 |
- done | grep -v -e ^= > ${OPENSHIFT_REPO_DIR}/.env |
|
22 |
- |
|
23 |
- chmod ugo+r ${OPENSHIFT_REPO_DIR}/.env |
|
24 | 20 |
source ${OPENSHIFT_REPO_DIR}/.env |
25 | 21 |
else |
26 | 22 |
cat <<EOM |
27 | 23 |
*** |
28 | 24 |
* |
29 |
-* WARNING: No .env.example file found. |
|
25 |
+* WARNING: No .env file found. |
|
30 | 26 |
* |
31 | 27 |
*** |
32 | 28 |
EOM |
@@ -12,3 +12,5 @@ |
||
12 | 12 |
# prevent your application from stopping cleanly or starting at all. |
13 | 13 |
# Application start and stop is subject to different timeouts |
14 | 14 |
# throughout the system. |
15 |
+ |
|
16 |
+echo "-> Pre stop ruby step" |
@@ -66,7 +66,7 @@ module WebRequestConcern |
||
66 | 66 |
|
67 | 67 |
module ClassMethods |
68 | 68 |
def default_user_agent |
69 |
- ENV.fetch('DEFAULT_HTTP_USER_AGENT', Faraday.new.headers[:user_agent]) |
|
69 |
+ ENV.fetch('DEFAULT_HTTP_USER_AGENT', "Huginn - https://github.com/cantino/huginn") |
|
70 | 70 |
end |
71 | 71 |
end |
72 | 72 |
end |
@@ -1,5 +1,5 @@ |
||
1 | 1 |
class SystemMailer < ActionMailer::Base |
2 |
- default :from => ENV['EMAIL_FROM_ADDRESS'] || 'you@example.com' |
|
2 |
+ default :from => ENV['EMAIL_FROM_ADDRESS'].presence || 'you@example.com' |
|
3 | 3 |
|
4 | 4 |
def send_message(options) |
5 | 5 |
@groups = options[:groups] |
@@ -1,6 +1,6 @@ |
||
1 | 1 |
#!/usr/bin/env ruby |
2 |
-require 'open3' |
|
3 |
-require 'io/console' |
|
2 |
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'setup_tools')) |
|
3 |
+include SetupTools |
|
4 | 4 |
|
5 | 5 |
unless `which heroku` =~ /heroku/ |
6 | 6 |
puts "It looks like the heroku command line tool hasn't been installed yet. Please install" |
@@ -9,56 +9,25 @@ unless `which heroku` =~ /heroku/ |
||
9 | 9 |
exit 1 |
10 | 10 |
end |
11 | 11 |
|
12 |
-def capture(cmd, opts = {}) |
|
13 |
- o, s = Open3.capture2e(cmd, opts) |
|
14 |
- o.strip |
|
15 |
-end |
|
16 |
- |
|
17 |
-def ask(question, opts = {}) |
|
18 |
- print question + " " |
|
19 |
- STDOUT.flush |
|
20 |
- (opts[:noecho] ? STDIN.noecho(&:gets) : gets).strip |
|
21 |
-end |
|
22 |
- |
|
23 |
-def nag(question, opts = {}) |
|
24 |
- answer = '' |
|
25 |
- while answer.length == 0 |
|
26 |
- answer = ask(question, opts) |
|
27 |
- end |
|
28 |
- answer |
|
29 |
-end |
|
30 |
- |
|
31 |
-def yes?(question) |
|
32 |
- ask(question + " (y/n)") =~ /^y/i |
|
12 |
+def grab_heroku_config! |
|
13 |
+ grab_config_with_cmd!("heroku config -s") |
|
33 | 14 |
end |
34 | 15 |
|
35 |
-def grab_heroku_config! |
|
36 |
- config_data = capture("heroku config -s") |
|
37 |
- $config = {} |
|
38 |
- if config_data !~ /has no config vars/ |
|
39 |
- config_data.split("\n").map do |line| |
|
40 |
- next if line =~ /^\s*(#|$)/ # skip comments and empty lines |
|
41 |
- first_equal_sign = line.index('=') |
|
42 |
- $config[line.slice(0, first_equal_sign)] = line.slice(first_equal_sign + 1, line.length) |
|
43 |
- end |
|
44 |
- end |
|
16 |
+def set_env(key, value) |
|
17 |
+ capture("heroku config:set #{key}=#{value}") |
|
45 | 18 |
end |
46 | 19 |
|
47 |
-def set_value(key, value, options = {}) |
|
48 |
- if $config[key].nil? || $config[key] == '' || ($config[key] != value && options[:force] != false) |
|
49 |
- puts "Setting #{key} to #{value}" unless options[:silent] |
|
50 |
- puts capture("heroku config:set #{key}=#{value}") |
|
51 |
- $config[key] = value |
|
20 |
+def check_login! |
|
21 |
+ unless File.exists?(File.expand_path("~/.netrc")) && File.read(File.expand_path("~/.netrc")) =~ /heroku/ |
|
22 |
+ puts "It looks like you need to log in to Heroku. Please run 'heroku auth:login' before continuing." |
|
23 |
+ exit 1 |
|
52 | 24 |
end |
53 |
-end |
|
54 | 25 |
|
55 |
-unless File.exists?(File.expand_path("~/.netrc")) && File.read(File.expand_path("~/.netrc")) =~ /heroku/ |
|
56 |
- puts "It looks like you need to log in to Heroku. Please run 'heroku auth:login' before continuing." |
|
57 |
- exit 1 |
|
26 |
+ puts "Welcome #{`heroku auth:whoami`.strip}! It looks like you're logged into Heroku." |
|
27 |
+ puts |
|
58 | 28 |
end |
59 | 29 |
|
60 |
-puts "Welcome #{`heroku auth:whoami`.strip}! It looks like you're logged into Heroku." |
|
61 |
-puts |
|
30 |
+check_login! |
|
62 | 31 |
|
63 | 32 |
info = capture("heroku info") |
64 | 33 |
if info =~ /No app specified/i |
@@ -74,26 +43,10 @@ if info =~ /No app specified/i |
||
74 | 43 |
end |
75 | 44 |
|
76 | 45 |
app_name = info.scan(/http:\/\/([\w\d-]+)\.herokuapp\.com/).flatten.first |
77 |
- |
|
78 |
-unless yes?("Your Heroku app name is #{app_name}. Is this correct?") |
|
79 |
- puts "Well, then I'm not sure what to do here, sorry." |
|
80 |
- exit 1 |
|
81 |
-end |
|
82 |
- |
|
46 |
+confirm_app_name app_name |
|
83 | 47 |
grab_heroku_config! |
84 |
- |
|
85 |
-if $config.length > 0 |
|
86 |
- puts |
|
87 |
- puts "Your current Heroku config:" |
|
88 |
- $config.each do |key, value| |
|
89 |
- puts ' ' + key + ' ' * (25 - [key.length, 25].min) + '= ' + value |
|
90 |
- end |
|
91 |
-end |
|
92 |
- |
|
93 |
-unless $config['APP_SECRET_TOKEN'] |
|
94 |
- puts "Setting up APP_SECRET_TOKEN..." |
|
95 |
- puts capture("heroku config:set APP_SECRET_TOKEN=`rake secret`") |
|
96 |
-end |
|
48 |
+print_config |
|
49 |
+set_defaults! |
|
97 | 50 |
|
98 | 51 |
unless $config['DOMAIN'] |
99 | 52 |
set_value 'DOMAIN', "#{app_name}.herokuapp.com", force: false |
@@ -103,17 +56,6 @@ end |
||
103 | 56 |
set_value 'BUILDPACK_URL', "https://github.com/ddollar/heroku-buildpack-multi.git" |
104 | 57 |
set_value 'PROCFILE_PATH', "deployment/heroku/Procfile.heroku", force: false |
105 | 58 |
set_value 'ON_HEROKU', "true" |
106 |
-set_value 'FORCE_SSL', "true" |
|
107 |
-set_value 'USE_GRAPHVIZ_DOT', 'dot' |
|
108 |
- |
|
109 |
-unless $config['INVITATION_CODE'] |
|
110 |
- puts "You need to set an invitation code for your Huginn instance. If you plan to share this instance, you will" |
|
111 |
- puts "tell this code to anyone who you'd like to invite. If you won't share it, then just set this to something" |
|
112 |
- puts "that people will not guess." |
|
113 |
- |
|
114 |
- invitation_code = nag("What code would you like to use?") |
|
115 |
- set_value 'INVITATION_CODE', invitation_code |
|
116 |
-end |
|
117 | 59 |
|
118 | 60 |
unless $config['SMTP_DOMAIN'] && $config['SMTP_USER_NAME'] && $config['SMTP_PASSWORD'] && $config['SMTP_SERVER'] && $config['EMAIL_FROM_ADDRESS'] |
119 | 61 |
puts "Okay, let's setup outgoing email settings. The simplest solution is to use the free sendgrid Heroku addon." |
@@ -0,0 +1,141 @@ |
||
1 |
+#!/usr/bin/env ruby |
|
2 |
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'setup_tools')) |
|
3 |
+include SetupTools |
|
4 |
+ |
|
5 |
+if ARGV.length > 0 |
|
6 |
+ mode = ARGV.shift |
|
7 |
+else |
|
8 |
+ mode = '' |
|
9 |
+end |
|
10 |
+ |
|
11 |
+unless `which rhc` =~ /rhc/ |
|
12 |
+ puts "It looks like the 'rhc' command line tool hasn't been installed yet. Please install" |
|
13 |
+ puts "it with 'gem install rhc', run 'rhc setup', and then run this script again." |
|
14 |
+ exit 1 |
|
15 |
+end |
|
16 |
+ |
|
17 |
+def grab_openshift_config! |
|
18 |
+ grab_config_with_cmd!("rhc env list") |
|
19 |
+end |
|
20 |
+ |
|
21 |
+def set_env(key, value) |
|
22 |
+ capture("rhc env set #{key}=#{value}") |
|
23 |
+end |
|
24 |
+ |
|
25 |
+def check_login! |
|
26 |
+ unless Dir[File.join(File.expand_path('~/.openshift'), 'token_*')].length > 0 |
|
27 |
+ puts "It looks like you need to log in to OpenShift. Please run 'rhc setup' before continuing a choose the option to 'Generate a token now'." |
|
28 |
+ exit 1 |
|
29 |
+ end |
|
30 |
+ |
|
31 |
+ puts "Welcome #{`rhc account`.scan(/Login (.*?) on /).first.first}! It looks like you're logged into OpenShift." |
|
32 |
+ puts |
|
33 |
+end |
|
34 |
+ |
|
35 |
+check_login! |
|
36 |
+ |
|
37 |
+info = capture("rhc app show") |
|
38 |
+just_made = false |
|
39 |
+if info =~ /must specify an application/i |
|
40 |
+ foreman_cartridge = 'http://cartreflect-claytondev.rhcloud.com/reflect?github=cantino/huginn-openshift-foreman-cartridge' |
|
41 |
+ cmd = "rhc app create huginn ruby-2.0 mysql-5.5 #{foreman_cartridge} -s -r tmp-huginn" |
|
42 |
+ puts "It looks like you don't have an OpenShift app set up yet for this repo. I can make one for you." |
|
43 |
+ if yes?("Would you like me to create an OpenShift app for you now in this repo?") |
|
44 |
+ puts `#{cmd}` |
|
45 |
+ |
|
46 |
+ git_config = capture("git config --list -f tmp-huginn/.git/config").split("\n") |
|
47 |
+ git_config.grep(/^rhc\./).each do |line| |
|
48 |
+ path, value = line.split('=') |
|
49 |
+ puts `git config #{path} #{value}` |
|
50 |
+ end |
|
51 |
+ |
|
52 |
+ url = git_config.grep(/^remote\.origin\.url/).first.split('=').last |
|
53 |
+ puts "Adding remote #{url}" |
|
54 |
+ puts `git remote add openshift #{url}` |
|
55 |
+ |
|
56 |
+ puts "Removing tmp OpenShift repo" |
|
57 |
+ puts `rm -rf ./tmp-huginn` |
|
58 |
+ |
|
59 |
+ puts "Updating git" |
|
60 |
+ puts `git fetch openshift` |
|
61 |
+ |
|
62 |
+ info = capture("rhc app show") |
|
63 |
+ just_made = true |
|
64 |
+ else |
|
65 |
+ puts "Okay, exiting so you can do it." |
|
66 |
+ exit 0 |
|
67 |
+ end |
|
68 |
+elsif info =~ /Application '.*?' not found/ |
|
69 |
+ puts "It looks like you've deleted your OpenShift app. If that's the case, you should" |
|
70 |
+ puts "edit .git/config and remove the sections under [rhc] and under [remote \"openshift\"]." |
|
71 |
+ exit 1 |
|
72 |
+end |
|
73 |
+ |
|
74 |
+app_name, app_url = info.scan(/^([\w\d]+) @ https?:\/\/([^\/ ]+)/i).flatten |
|
75 |
+confirm_app_name app_name unless just_made |
|
76 |
+grab_openshift_config! |
|
77 |
+print_config |
|
78 |
+set_defaults! |
|
79 |
+ |
|
80 |
+first_time = mode =~ /^first/i |
|
81 |
+unless $config['DOMAIN'] |
|
82 |
+ set_value 'DOMAIN', app_url, force: false |
|
83 |
+ first_time = true |
|
84 |
+end |
|
85 |
+ |
|
86 |
+set_value 'BUNDLE_WITHOUT', 'development:test' |
|
87 |
+puts `rhc ssh huginn 'gem install bundler'` |
|
88 |
+ |
|
89 |
+puts |
|
90 |
+puts "To setup outbound email, we suggest using Gmail. See the 'Outgoing email settings' section in .env.example." |
|
91 |
+puts "You'll need to set those environment variables in OpenShift using 'rhc env set VARIABLE=VALUE'" |
|
92 |
+puts |
|
93 |
+ |
|
94 |
+branch = capture("git rev-parse --abbrev-ref HEAD") |
|
95 |
+if first_time || yes?("Should I push your current branch (#{branch}) to OpenShift?") |
|
96 |
+ puts "This may take a moment..." |
|
97 |
+ puts capture("git push openshift #{branch}:master -f") |
|
98 |
+end |
|
99 |
+ |
|
100 |
+if first_time |
|
101 |
+ puts "Restarting..." |
|
102 |
+ puts capture("rhc app restart") |
|
103 |
+ puts capture("rhc cartridge restart foreman") |
|
104 |
+ puts "Done!" |
|
105 |
+ puts |
|
106 |
+ puts |
|
107 |
+ puts "I can make an admin user on your new Huginn instance and setup some example Agents." |
|
108 |
+ if yes?("Should I create a new admin user and some example Agents?") |
|
109 |
+ done = false |
|
110 |
+ while !done |
|
111 |
+ seed_email = nag "Okay, what is your email address?" |
|
112 |
+ seed_username = nag "And what username would you like to login as?" |
|
113 |
+ seed_password = nag "Finally, what password would you like to use?", noecho: true |
|
114 |
+ puts "\nJust a moment..." |
|
115 |
+ |
|
116 |
+ result = capture("rhc ssh huginn 'cd $OPENSHIFT_REPO_DIR && RAILS_ENV=production bundle exec rake db:seed SEED_EMAIL=#{seed_email} SEED_USERNAME=#{seed_username} SEED_PASSWORD=#{seed_password}'") |
|
117 |
+ puts result |
|
118 |
+ if result =~ /Validation failed/ |
|
119 |
+ puts "ERROR:" |
|
120 |
+ puts |
|
121 |
+ puts result |
|
122 |
+ puts |
|
123 |
+ else |
|
124 |
+ done = true |
|
125 |
+ end |
|
126 |
+ end |
|
127 |
+ puts |
|
128 |
+ puts |
|
129 |
+ puts "Okay, you should be all set! Visit http://#{app_url} and login as '#{seed_username}' with your password." |
|
130 |
+ puts |
|
131 |
+ puts "If you'd like to make more users, you can visit http://#{app_url}/users/sign_up and use the invitation code:" |
|
132 |
+ else |
|
133 |
+ puts |
|
134 |
+ puts "Visit https://#{app_url}/users/sign_up and use the invitation code shown below:" |
|
135 |
+ end |
|
136 |
+ puts |
|
137 |
+ puts "\t#{$config['INVITATION_CODE']}" |
|
138 |
+end |
|
139 |
+ |
|
140 |
+puts |
|
141 |
+puts "Done!" |
@@ -18,7 +18,7 @@ module Huginn |
||
18 | 18 |
|
19 | 19 |
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. |
20 | 20 |
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. |
21 |
- config.time_zone = ENV['TIMEZONE'].present? ? ENV['TIMEZONE'] : "Pacific Time (US & Canada)" |
|
21 |
+ config.time_zone = ENV['TIMEZONE'].presence || "Pacific Time (US & Canada)" |
|
22 | 22 |
|
23 | 23 |
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. |
24 | 24 |
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] |
@@ -1,37 +1,37 @@ |
||
1 | 1 |
development: |
2 |
- adapter: <%= ENV['DATABASE_ADAPTER'] || "mysql2" %> |
|
3 |
- encoding: <%= ENV['DATABASE_ENCODING'] || "utf8" %> |
|
4 |
- reconnect: <%= ENV['DATABASE_RECONNECT'] || "true" %> |
|
5 |
- database: <%= ENV['DATABASE_NAME'] || "huginn_development" %> |
|
6 |
- pool: <%= ENV['DATABASE_POOL'] || "5" %> |
|
7 |
- username: <%= ENV['DATABASE_USERNAME'] || "root" %> |
|
2 |
+ adapter: <%= ENV['DATABASE_ADAPTER'].presence || "mysql2" %> |
|
3 |
+ encoding: <%= ENV['DATABASE_ENCODING'].presence || "utf8" %> |
|
4 |
+ reconnect: <%= ENV['DATABASE_RECONNECT'].presence || "true" %> |
|
5 |
+ database: <%= ENV['DATABASE_NAME'].presence || "huginn_development" %> |
|
6 |
+ pool: <%= ENV['DATABASE_POOL'].presence || "5" %> |
|
7 |
+ username: <%= ENV['DATABASE_USERNAME'].presence || "root" %> |
|
8 | 8 |
password: <%= ENV['DATABASE_PASSWORD'] || "" %> |
9 | 9 |
host: <%= ENV['DATABASE_HOST'] || "" %> |
10 | 10 |
port: <%= ENV['DATABASE_PORT'] || "" %> |
11 |
- socket: <%= ENV['DATABASE_SOCKET'] || ["/var/run/mysqld/mysqld.sock", "/opt/local/var/run/mysql5/mysqld.sock", "/tmp/mysql.sock"].find{ |path| File.exist? path } %> |
|
11 |
+ socket: <%= ENV['DATABASE_SOCKET'] || ["/var/run/mysqld/mysqld.sock", "/opt/local/var/run/mysql5/mysqld.sock", "/tmp/mysql.sock"].find { |path| File.exist? path } %> |
|
12 | 12 |
|
13 | 13 |
# Warning: The database defined as "test" will be erased and |
14 | 14 |
# re-generated from your development database when you run "rake". |
15 | 15 |
# Do not set this db to the same as development or production. |
16 | 16 |
test: |
17 |
- adapter: <%= ENV['DATABASE_ADAPTER'] || "mysql2" %> |
|
18 |
- database: <%= ENV['TEST_DATABASE_NAME'] || "huginn_test" %> |
|
19 |
- username: <%= ENV['DATABASE_USERNAME'] || "root" %> |
|
20 |
- password: <%= ENV['DATABASE_PASSWORD'] || "" %> |
|
21 |
- socket: <%= ENV['DATABASE_SOCKET'] || ["/var/run/mysqld/mysqld.sock", "/opt/local/var/run/mysql5/mysqld.sock", "/tmp/mysql.sock"].find{ |path| File.exist? path } %> |
|
22 |
- encoding: <%= ENV['DATABASE_ENCODING'] || "utf8" %> |
|
23 |
- reconnect: <%= ENV['DATABASE_RECONNECT'] || "true" %> |
|
17 |
+ adapter: <%= ENV['DATABASE_ADAPTER'].presence || "mysql2" %> |
|
18 |
+ encoding: <%= ENV['DATABASE_ENCODING'].presence || "utf8" %> |
|
19 |
+ reconnect: <%= ENV['DATABASE_RECONNECT'].presence || "true" %> |
|
20 |
+ database: <%= ENV['TEST_DATABASE_NAME'].presence || "huginn_test" %> |
|
21 |
+ pool: <%= ENV['DATABASE_POOL'].presence || "5" %> |
|
22 |
+ username: <%= ENV['DATABASE_USERNAME'].presence || "root" %> |
|
23 |
+ password: <%= ENV['DATABASE_PASSWORD'].presence || "" %> |
|
24 |
+ socket: <%= ENV['DATABASE_SOCKET'] || ["/var/run/mysqld/mysqld.sock", "/opt/local/var/run/mysql5/mysqld.sock", "/tmp/mysql.sock"].find { |path| File.exist? path } %> |
|
24 | 25 |
port: <%= ENV['DATABASE_PORT'] || "" %> |
25 |
- pool: <%= ENV['DATABASE_POOL'] || "5" %> |
|
26 | 26 |
|
27 | 27 |
production: |
28 |
- adapter: <%= ENV['DATABASE_ADAPTER'] || "mysql2" %> |
|
29 |
- encoding: <%= ENV['DATABASE_ENCODING'] || "utf8" %> |
|
30 |
- reconnect: <%= ENV['DATABASE_RECONNECT'] || "true" %> |
|
31 |
- database: <%= ENV['DATABASE_NAME'] || "huginn_production" %> |
|
32 |
- pool: <%= ENV['DATABASE_POOL'] || "5" %> |
|
33 |
- username: <%= ENV['DATABASE_USERNAME'] || "root" %> |
|
34 |
- password: <%= ENV['DATABASE_PASSWORD'] || "password" %> |
|
28 |
+ adapter: <%= ENV['DATABASE_ADAPTER'].presence || "mysql2" %> |
|
29 |
+ encoding: <%= ENV['DATABASE_ENCODING'].presence || "utf8" %> |
|
30 |
+ reconnect: <%= ENV['DATABASE_RECONNECT'].presence || "true" %> |
|
31 |
+ database: <%= ENV['DATABASE_NAME'].presence || "huginn_production" %> |
|
32 |
+ pool: <%= ENV['DATABASE_POOL'].presence || "5" %> |
|
33 |
+ username: <%= ENV['DATABASE_USERNAME'].presence || "root" %> |
|
34 |
+ password: <%= ENV['DATABASE_PASSWORD'].presence || "password" %> |
|
35 | 35 |
host: <%= ENV['DATABASE_HOST'] || "" %> |
36 | 36 |
port: <%= ENV['DATABASE_PORT'] || "" %> |
37 | 37 |
socket: <%= ENV['DATABASE_SOCKET'] || ["/var/run/mysqld/mysqld.sock", "/opt/local/var/run/mysql5/mysqld.sock", "/tmp/mysql.sock"].find{ |path| File.exist? path } %> |
@@ -41,7 +41,7 @@ Huginn::Application.configure do |
||
41 | 41 |
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx |
42 | 42 |
|
43 | 43 |
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. |
44 |
- config.force_ssl = ENV['FORCE_SSL'].present? && ENV['FORCE_SSL'] == 'true' ? true : false |
|
44 |
+ config.force_ssl = ENV['FORCE_SSL'] == 'true' |
|
45 | 45 |
|
46 | 46 |
# See everything in the log (default is :info) |
47 | 47 |
# config.log_level = :debug |
@@ -18,7 +18,7 @@ Thread.new do |
||
18 | 18 |
sleep 45 |
19 | 19 |
|
20 | 20 |
if ENV['DOMAIN'] |
21 |
- force_ssl = ENV['FORCE_SSL'].present? && ENV['FORCE_SSL'] == 'true' |
|
21 |
+ force_ssl = ENV['FORCE_SSL'] == 'true' |
|
22 | 22 |
Net::HTTP.get_response(URI((force_ssl ? "https://" : "http://") + ENV['DOMAIN'])) |
23 | 23 |
end |
24 | 24 |
|
@@ -106,7 +106,7 @@ class HuginnScheduler |
||
106 | 106 |
end |
107 | 107 |
|
108 | 108 |
def run! |
109 |
- tzinfo_friendly_timezone = ActiveSupport::TimeZone::MAPPING[ENV['TIMEZONE'].present? ? ENV['TIMEZONE'] : "Pacific Time (US & Canada)"] |
|
109 |
+ tzinfo_friendly_timezone = ActiveSupport::TimeZone::MAPPING[ENV['TIMEZONE'].presence || "Pacific Time (US & Canada)"] |
|
110 | 110 |
|
111 | 111 |
# Schedule event propagation. |
112 | 112 |
@rufus_scheduler.every '1m' do |
@@ -0,0 +1,85 @@ |
||
1 |
+require 'open3' |
|
2 |
+require 'io/console' |
|
3 |
+require 'securerandom' |
|
4 |
+ |
|
5 |
+module SetupTools |
|
6 |
+ def capture(cmd, opts = {}) |
|
7 |
+ o, s = Open3.capture2e(cmd, opts) |
|
8 |
+ o.strip |
|
9 |
+ end |
|
10 |
+ |
|
11 |
+ def grab_config_with_cmd!(cmd) |
|
12 |
+ config_data = capture(cmd) |
|
13 |
+ $config = {} |
|
14 |
+ if config_data !~ /has no config vars/ |
|
15 |
+ config_data.split("\n").map do |line| |
|
16 |
+ next if line =~ /^\s*(#|$)/ # skip comments and empty lines |
|
17 |
+ first_equal_sign = line.index('=') |
|
18 |
+ raise "Invalid line found in config: #{line}" unless first_equal_sign |
|
19 |
+ $config[line.slice(0, first_equal_sign)] = line.slice(first_equal_sign + 1, line.length) |
|
20 |
+ end |
|
21 |
+ end |
|
22 |
+ end |
|
23 |
+ |
|
24 |
+ def print_config |
|
25 |
+ if $config.length > 0 |
|
26 |
+ puts |
|
27 |
+ puts "Your current config:" |
|
28 |
+ $config.each do |key, value| |
|
29 |
+ puts ' ' + key + ' ' * (25 - [key.length, 25].min) + '= ' + value |
|
30 |
+ end |
|
31 |
+ end |
|
32 |
+ end |
|
33 |
+ |
|
34 |
+ def set_defaults! |
|
35 |
+ unless $config['APP_SECRET_TOKEN'] |
|
36 |
+ puts "Setting up APP_SECRET_TOKEN..." |
|
37 |
+ set_value 'APP_SECRET_TOKEN', SecureRandom.hex(64) |
|
38 |
+ end |
|
39 |
+ set_value 'RAILS_ENV', "production" |
|
40 |
+ set_value 'FORCE_SSL', "true" |
|
41 |
+ set_value 'USE_GRAPHVIZ_DOT', 'dot' |
|
42 |
+ unless $config['INVITATION_CODE'] |
|
43 |
+ puts "You need to set an invitation code for your Huginn instance. If you plan to share this instance, you will" |
|
44 |
+ puts "tell this code to anyone who you'd like to invite. If you won't share it, then just set this to something" |
|
45 |
+ puts "that people will not guess." |
|
46 |
+ |
|
47 |
+ invitation_code = nag("What code would you like to use?") |
|
48 |
+ set_value 'INVITATION_CODE', invitation_code |
|
49 |
+ end |
|
50 |
+ end |
|
51 |
+ |
|
52 |
+ def confirm_app_name(app_name) |
|
53 |
+ unless yes?("Your app name is '#{app_name}'. Is this correct?") |
|
54 |
+ puts "Well, then I'm not sure what to do here, sorry." |
|
55 |
+ exit 1 |
|
56 |
+ end |
|
57 |
+ end |
|
58 |
+ |
|
59 |
+ # expects set_env(key, value) to be defined. |
|
60 |
+ def set_value(key, value, options = {}) |
|
61 |
+ if $config[key].nil? || $config[key] == '' || ($config[key] != value && options[:force] != false) |
|
62 |
+ puts "Setting #{key} to #{value}" unless options[:silent] |
|
63 |
+ puts set_env(key, value) |
|
64 |
+ $config[key] = value |
|
65 |
+ end |
|
66 |
+ end |
|
67 |
+ |
|
68 |
+ def ask(question, opts = {}) |
|
69 |
+ print question + " " |
|
70 |
+ STDOUT.flush |
|
71 |
+ (opts[:noecho] ? STDIN.noecho(&:gets) : gets).strip |
|
72 |
+ end |
|
73 |
+ |
|
74 |
+ def nag(question, opts = {}) |
|
75 |
+ answer = '' |
|
76 |
+ while answer.length == 0 |
|
77 |
+ answer = ask(question, opts) |
|
78 |
+ end |
|
79 |
+ answer |
|
80 |
+ end |
|
81 |
+ |
|
82 |
+ def yes?(question) |
|
83 |
+ ask(question + " (y/n)") =~ /^y/i |
|
84 |
+ end |
|
85 |
+end |