GithubHelp home page GithubHelp logo

broadcast's Introduction

tests

See test GitHub Action run for code coverage percentage

Broadcast

Send SMS to distinct groups of recipients. Allow numbers to subscribe to topics.

under development, not fully functional

Twilio Configuration

To send messages the following environment variables will need to be set

TWILIO_SID
TWILIO_TOKEN
TWILIO_PHONE

Developers

Prerequisities

  • Have a PostgreSQL instance available or modify the application to use another database
    • replace pg references in the Gemfile
    • update config/database.yml
  • Have a Twilio account (if you will be sending messages to Twiliio)
    • Twilio accounts allow test accounts, which will allow you to interact with Twilio services but not actually send messages or charge you per send

Setup

bundle install
bin/rails db:create

Create an admin user via the Rails console

Admin.create!(email: '[email protected]', password: 'S3Kr1t!')

Create users via http://localhost:3000/users/sign_in or via the Rails console, then seed

bin/rails db:seed:replant

Run in watch mode with assets

bin/dev

or compile manually and use rails server

bin/rake assets:precompile
bin/rails s

Tests

Both system and unit tests are present

bundle exec rspec

Twilio

To reduce effort and prevent the sending of real SMS while testing, rails_helper.rb will set Twilio send values (SID, TOKEN, and PHONE) to test versions if you have them declared in your environment variables unless you have the variables on the left already populated:

TWILIO_SID ||= ENV['TWILIO_TEST_SID']
TWILIO_TOKEN ||= ENV['TWILIO_TEST_TOKEN']
TWILIO_PHONE ||= '+15005550006'

See https://www.twilio.com/docs/iam/test-credentials for details. The TWILIO_PHONE when using test credentials needs to be one of a few specific numbers, which is why the value is hard-coded above.

System Tests

Viewing rendered pages during system tests

When at a breakpoint, enter the following on the console

save_and_open_page

Headed Browser mode

Tests tha execute JavaScript will need to mark themselves as js: true (see spec/system/navbar_spec.rb for an example). Per RSpec configuration in spec_helper these run in headless mode by default. Tests not marked as js: true will use driven_by :rack_test. Note that tests rack_test is significantly faster than selenium_chrome so only tests that need to interact with JavaScript should be run with the latter.

Should you desire to run in headed mode specify driven_by :selenium_chrome at the test level, block level, or by changing the config value in spec_helper.rb.

Linters

bundle exec rubocop
bundle exec brakeman
bundle exec bundler-audit --update
bundle exec reek

Production Deployment

Render

  • Create web application
  • Create database instance
  • Add secrets to web app
    • SECRET_KEY_BASE
    • BROADCAST_DATABASE_NAME
    • BROADCAST_DATABASE_HOST
    • BROADCAST_DATABASE_PASSWORD
    • BROADCAST_DATABASE_USERNAME
    • TWILIO_SID
    • TWILIO_TOKEN
    • TWILIO_PHONE
    • NEW_RELIC_LICENSE (if monitoring with New Relic)
    • ROLLBAR_ACCESS_TOKEN (if monitoring with Rollbar)
  • Connect to the database and run migrations
    • If on the free tier you'll have to do this from your local box

A11y

This application uses the axe for accessibility checking

Monitoring

New Relic

You need to populate environment variable NEW_RELIC_LICENSE

Rollbar

ROLLBAR_ACCESS_TOKEN

OSX

New Relic agent can run on OSX, but log integration doesn't seem to be available directly on OSX

brew services run newrelic-infra-agent # use 'start' instead of 'run' to always start the agent
brew services stop newrelic-infra-agent

https://docs.newrelic.com/docs/logs/forward-logs/forward-your-logs-using-infrastructure-agent/

sudo NEW_RELIC_API_KEY=<API_KEY> NEW_RELIC_ACCOUNT_ID=<<ACCOUNT_ID> /usr/local/bin/newrelic install -n logs-integration

Docker

By default the app runs in production mode on Docker, but this implementation is not intended for production use due to security (e.g., exposed PostgreSQL password).

This requires a SECRET_KEY_BASE value and certs for SSL.

https://github.com/docker/awesome-compose/blob/master/official-documentation-samples/rails/README.md

Certificates

Docker-compose will use localhost-key.pem and localhost.pem. Update filesnames in puma.rb if so inclined.

mkdir -p config/credentials
cd config/credentials
mkcert localhost
mkcert -install

Build then run app and database using Docker compose

DOCKER_SSL controls whether puma will expose an SSL endpoint. Set this true when running the Dockerized version locally -- hosters like Render may do this automatically.

docker compose build

DOCKER_SSL=1 SECRET_KEY_BASE=$(cat config/master.key) docker compose up

Or just uild the image directly

docker build -t broadcast .

Connect to the rails console via the web container

docker exec -it broadcast-web-1 /bin/bash

broadcast's People

Contributors

eebbesen avatar

Watchers

 avatar  avatar

broadcast's Issues

Log bug for RSpec?

Not an issue with this codebase (presumably) but saving here for logging later:

This passes intermittently*

  describe 'validations' do
    it { is_expected.to belong_to :user }
    it { is_expected.to have_many :message_recipients }
    it { is_expected.to have_many(:recipient_lists).through(:messages_recipient_list) }
    it { is_expected.to have_many(:recipients).through(:message_recipients) }
    it { is_expected.to validate_presence_of :content }
    it { is_expected.to validate_presence_of :status }
  end
end```

but when the check for `recipient_lists` is _after_ the check for `recipients` the test fails with `Expected Message to have a has_many association called recipient_lists through messages_recipient_list (Could not find the association :messages_recipient_list in model Message)`

```RSpec.describe Message do
  describe 'validations' do
    it { is_expected.to belong_to :user }
    it { is_expected.to have_many :message_recipients }
    it { is_expected.to have_many(:recipients).through(:message_recipients) }
    it { is_expected.to have_many(:recipient_lists).through(:messages_recipient_list) }
    it { is_expected.to validate_presence_of :content }
    it { is_expected.to validate_presence_of :status }
  end
end```

* when running in the context of the whole suite, this sometimes fails, sometimes does not 🤷 

Dockerize

  • Confirm the application and the DB are dockerized
  • Document how to use Dockerized version

More monitoring

  • Consider hooking up to front-end monitoring like logrocket/rollbar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.