From e3d31df621e339330602cb3c2554aa75d2ca56ca Mon Sep 17 00:00:00 2001 From: Shep Date: Thu, 23 Aug 2018 02:45:08 +0800 Subject: [PATCH 1/2] Set mailer params to grab from env ------ Set the ActionMailer parameters for both `production.rb` and `development.rb` to pull the email address and password from environment variables. --- MYR_rails/config/environments/development.rb | 8 ++++++++ MYR_rails/config/environments/production.rb | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/MYR_rails/config/environments/development.rb b/MYR_rails/config/environments/development.rb index d347c10..c444a08 100644 --- a/MYR_rails/config/environments/development.rb +++ b/MYR_rails/config/environments/development.rb @@ -43,4 +43,12 @@ config.action_mailer.default_url_options = { :host => "localhost:3000" } config.action_mailer.delivery_method = :letter_opener config.action_mailer.perform_deliveries = true + config.action_mailer.smtp_settings = { + :address => "smtp.gmail.com", + :port => 587, + :authentication=> "plain", + :enable_starttls_auto=> true, + :user_name => ENV["GMAIL_USERNAME_DEV"], + :password => ENV["GMAIL_PASSWORD_DEV"], + } end diff --git a/MYR_rails/config/environments/production.rb b/MYR_rails/config/environments/production.rb index 6b8f742..51f8f20 100644 --- a/MYR_rails/config/environments/production.rb +++ b/MYR_rails/config/environments/production.rb @@ -78,13 +78,13 @@ config.active_record.dump_schema_after_migration = false # SMTP settings for gmail - config.action_mailer.default_url_options = { :host => "www.roboticsailing.org/2018/tracking" } - config.action_mailer.delivery_method = :smtp - config.action_mailer.smtp_settings = { + config.action_mailer.default_url_options = { :host => "www.roboticsailing.org/2018/tracking" } + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { address: "smtp.gmail.com", port: 587, - user_name: "wrsc.noreply@gmail.com", - password: "sailrobot", + user_name: ENV["GMAIL_USERNAME"], + password: ENV["GMAIL_PASSWORD"], authentication: "plain", enable_starttls_auto: true } From 434ace413a90c7ffbeab9acd308914930beca1e1 Mon Sep 17 00:00:00 2001 From: Shep Date: Thu, 23 Aug 2018 02:48:00 +0800 Subject: [PATCH 2/2] Semantic edits to documentation ------ First off, server_deploy.md was separated with a comma, not a period. Secondly, I've changed the language a little in both, in hopes of streamlining what we are talking about. --- Doc/server_deploy,md | 64 ------------------------------------------- Doc/server_deploy.md | 65 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 10 ++++--- 3 files changed, 71 insertions(+), 68 deletions(-) delete mode 100644 Doc/server_deploy,md create mode 100644 Doc/server_deploy.md diff --git a/Doc/server_deploy,md b/Doc/server_deploy,md deleted file mode 100644 index d9e2ee5..0000000 --- a/Doc/server_deploy,md +++ /dev/null @@ -1,64 +0,0 @@ -# Server development guide - - -## Get a linux server - -You can use your own server or get a cheap VPS started from Digital Ocean started $5 per month. (referral code to be inserted here) - -## Prepare rails app - -Clone the repository - - git clone https://github.com/WRSC/tracking.git - -Install ruby - -Check this [instruction](https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-16-04) - - -Install ruby packages - - gem install bundle - cd MYR_rails - bundle install - - -## Initialise the database and serve the website in development mode - - export RAIL_ENV=development - bundle exec rake db:migrate - bundle exec rails s - - -## Update the database for a competition - -To update the website for a new competition, both visual front-end and database back-end need to be changed. - -- Most front-end related files are under `/MYR_rails/app/views` folder. -- Database file is under `/MYR_rails/db` folder. - - - Depends on the mode, you'll see one (development, production, test) of SQLite database there. You do need to configure them manually - - Edit the seed file under `seeds` folder, the `seeds2018` is self-explanatory. After that run `bundle exec rake db:seed:seeds2018` to add admin users and missions to the competition. - - -## Run the server in production environment - -### Repeat the initialise the database and update the database step in production mode - - cd MYR_rails # Assume you are under /tracking/MYR_rails folder - export RAIL_ENV=production - bundle exec rake db:migrate - bundle exec rake db:seed:seeds2018 # Replace when necessary - - - - -### Run in CLI or create a bash script - - #!/bin/bash - export RAIL_ENV=production - export SECRET_KEY=... # Fill in a SECRET_KEY key, 'rake secret' can generate one - - cd tracking/MYR_rails - bundle exec s -e production -b 0.0.0.0 -p 80 - diff --git a/Doc/server_deploy.md b/Doc/server_deploy.md new file mode 100644 index 0000000..9318d89 --- /dev/null +++ b/Doc/server_deploy.md @@ -0,0 +1,65 @@ +# Server development guide + + +## Get a Linux server + +You can use your own server or get a cheap VPS started from Digital Ocean started $5 per month. (referral code to be inserted here) + +## Prepare the rails app + +Clone the repository + + git clone https://github.com/WRSC/tracking.git + +Install ruby + +Check this [instruction](https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-16-04) to install Ruby and rbenv, a Ruby version manager, into your machine. + + +Install ruby packages + + gem install bundle + cd MYR_rails + bundle install + + +## Initialise the database and serve the website in development mode + + export RAILS_ENV=development + bundle exec rake db:migrate + bundle exec rails s + + +## Update the database for competition + +To update the website for a new competition, both the visual front-end and database back-end need to be changed. + +- Most front-end related files are under `MYR_rails/app/views`. +- Database file is under `MYR_rails/db`: + + - Depending on the mode (development, test, production), you'll see a corresponding SQLite file. You will need to configure it manually. + - Edit the seed file under `seeds/` (e.g. `seeds/seeds2018.rb`) and run `bundle exec rake db:seed:seeds2018` to add your own admin users and missions to the competition. + + +## Run the server in production + +### Reinitialise the database for production + + cd tracking/MYR_rails + export RAILS_ENV=production + bundle exec rake db:migrate + bundle exec rake db:seed:seeds2018 # Replace where necessary + +### Run the server in CLI or via Bash script + + #!/bin/bash + cd tracking/MYR_rails + + export RAILS_ENV=production + # Generate a SECRET_TOKEN; `rake secret` can generate one + export SECRET_TOKEN= + # If you haven't already, make sure to generate a SECRET_KEY_BASE too + export SECRET_KEY_BASE= + + bundle exec rails s -e production -b 0.0.0.0 -p 80 # Options are, well, optional + diff --git a/README.md b/README.md index f5f7a3c..d97d482 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,15 @@ To run the server locally for development: # gem is Ruby's package manager. You'll need to get that somehow. gem install bundle bundle install - + # It looks like this should only be needed in production, but I always # seem to need it. It should be a proper random token in production. + # To learn how to deploy to production, please read `Docs/server_deploy.md`. export SECRET_KEY_BASE=blah - - # Go! - bundle exec rails server -e development + + # Run the database migrations, and launch the server! + bundle exec rake db:migrate RAILS_ENV=development + bundle exec rails server -e development # or bundle exec rails s -e development Open http://localhost:3000/ in a browser to see it.