Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Heroku Deployment #15

Merged
merged 8 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,22 @@ 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` or `psql bjc_teachers_dev`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also just do rails db, locally or on heroku.

- 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` or `rails console` 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 +105,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)
cycomachead marked this conversation as resolved.
Show resolved Hide resolved
- `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_production
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name should probably be updated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea probably.

8 changes: 7 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ production:
adapter: postgresql
pool: 5
timeout: 5000
database: bjc_teachers_prod
database: bjc_teachers_prod

production:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t this key be staging?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I think I got prod and stage database name mixed up.

adapter: postgresql
pool: 5
timeout: 5000
database: bjc_teachers_stage
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: 5 additions & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
bjc_password: <%= ENV["BJC_PASSWORD"] %>
piazza_password: <%= ENV["PIAZZA_PASSWORD"] %>

staging:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
bjc_password: <%= ENV["BJC_PASSWORD"] %>
piazza_password: <%= ENV["PIAZZA_PASSWORD"] %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
bjc_password: <%= ENV["BJC_PASSWORD"] %>
piazza_password: <%= ENV["PIAZZA_PASSWORD"] %>
<<: *production

This would reduce some duplication

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