Skip to content

Commit

Permalink
Merge pull request #15 from cs169/heroku-deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Reimirno authored Mar 14, 2023
2 parents 214240b + 0aa7460 commit 2168073
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: bundle exec puma -C config/puma.rb -p $PORT
release: bin/rails db:prepare
release: bin/rails db:prepare
43 changes: 26 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,23 @@ We have worked on the adding following core features and functionality:
- For Cucumber tests run `bundle exec cucumber`
- For Rubocop check run `bundle exec rubocop` (Autocorrect all with `bundle exec rubocop -a`)
- To make someone an admin use db console access
- First run `heroku pg:psql` or `psql bjc_teachers_dev`
- Then
```
UPDATE teachers
SET admin = true
WHERE Email LIKE '%@berkeley.edu%'
;
```
- Using psql
- First run `heroku pg:psql` (for Heroku) or `psql bjc_teachers_dev` (for local) to get into psql
- Alternatively, you can use `rails db` to get into psql
- Then
```
UPDATE teachers
SET admin = true
WHERE Email LIKE '%@berkeley.edu%'
;
```
Of course, you can swap in the email of your choice.
- Using rails console
- First run `heroku run rails console` (for Heroku) or `rails console` (for local) to get into rails console
- Then
```
Teacher.where("email LIKE '%@berkeley.edu%'").update_all(admin: true)
```
## JavaScript and CSS with Webpack
Expand All @@ -97,25 +106,25 @@ We have worked on the adding following core features and functionality:
## Steps to Deploying on Heroku
- ... create a heroku app
- `heroku stack:set heroku-20` (Ruby 2.7.7 is not supported on latest stack heroku-22. Double check your Ruby version though)
- `heroku buildpacks:set heroku/nodejs` # this must be the first buildpack.
- `heroku buildpacks:add --index 2 heroku/ruby`
- `git remote set-url heroku https://git.heroku.com/bjc-teachers.git`
- `git remote set-url heroku https://git.heroku.com/bjc-teachers.git` (or whatever your heroku deployment repository is)
- Make your local changes and start the commit process
- `git add .`
- `git commit -m "<Message>"`
- `git push heroku master`
- `git push heroku master` (If this fails, try commenting the release command in `Procfile` for this first deployment only and go on to the next step. After you are done with the deployment, uncomment back the release command again. For more information, see [this PR](https://github.com/cs169/BJC-Teacher-Tracker/pull/15).)
If bundler install runs successfully, continue with the following commands to correctly setup the PostgreSQL database on Heroku:
- `heroku addons:create heroku-postgresql`
- `heroku run rake db:drop`
- `heroku run rake db:schema:load`
- `heroku run rake db:migrate`
- `figaro heroku:set -e production`
- `heroku addons:create heroku-postgresql` (or, create and attach a new postgresql database on Heroku dashboard manually)
- `heroku run bin/rails db:drop` (if this fails, you can skip this step)
- `heroku run bin/rails db:schema:load`
- `heroku run bin/rails db:seed`
- `figaro heroku:set -e production` (or `staging`, depending on the your needs)
- `heroku open`
### CodeClimate Local Test
## CodeClimate Local Test
```
https://codeclimate.com/downloads/test-reporter/test-reporter-latest-darwin-amd64
Expand Down
5 changes: 5 additions & 0 deletions config/cable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: bjc_teacher_tracker_production

staging:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: bjc_teacher_tracker_staging
6 changes: 6 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ test:
<<: *default
database: bjc_teachers_test

staging:
adapter: postgresql
pool: 5
timeout: 5000
database: bjc_teachers_stage

production:
adapter: postgresql
pool: 5
Expand Down
97 changes: 97 additions & 0 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# frozen_string_literal: true

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
config.cache_classes = true

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# config.require_master_key = true

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?

# Compress JavaScripts and CSS.
# config.assets.js_compressor = Uglifier.new(harmony: true)
# config.assets.css_compressor = :sass

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'

# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

# Store uploaded files on the local file system (see config/storage.yml for options)
# config.active_storage.service = :local

# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true

# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :warn

# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]

# Don't log view information:
config.action_view.logger = nil

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

# Use a real queuing backend for Active Job (and separate queues per environment)
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "bjc_teacher_tracker_#{Rails.env}"

config.action_mailer.perform_caching = false

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true

# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new

# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')

if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

# Email settings
# Do not send emails in staging environment, and do not raise errors
config.action_mailer.raise_delivery_errors = false

# Store files on Amazon S3. (Uncomment this when S3 is setup)
# config.active_storage.service = :amazon
end
5 changes: 4 additions & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ test:

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
production: &production
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
bjc_password: <%= ENV["BJC_PASSWORD"] %>
piazza_password: <%= ENV["PIAZZA_PASSWORD"] %>

staging:
<<: *production
12 changes: 12 additions & 0 deletions config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,15 @@ production:

# Cache manifest.json for performance
cache_manifest: true

staging:
<<: *default

# Production depends on precompilation of packs prior to booting for performance.
compile: false

# Extract and emit a css file
extract_css: true

# Cache manifest.json for performance
cache_manifest: true

0 comments on commit 2168073

Please sign in to comment.