Skip to content

Installation

Julia Nguyen edited this page Aug 16, 2020 · 74 revisions

The app uses Ruby 2.6.6 and Rails 6.0.3. Please stick to these versions.

Dev Environment

Docker [Fastest, especially recommended for Windows users] (click to expand)

Docker

Assuming Docker is setup, you can start the server using

docker-compose up

or open a shell using

docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm app

Running docker-compose for the first time will take more than a few minutes. Get yourself some coffee or tea and wait for the application to start.

Once the application and database are running, there are a few housekeeping commands that must be run before the application can be accessed from the browser on the host machine. While the server is running, run the following in a new shell.

This command creates the database and the tables:

docker-compose exec app bundle exec rake db:create db:migrate

This command creates the webpack_bundle.css file. Even though the command is run in the Dockerfile, it has to be run after the app has started in order to generate the assets. There is probably a different way to do this, but for now, this will get you up and running on Docker!

docker-compose exec app bundle exec rails assets:precompile
Vagrant [If you don't want to install locally, especially recommended for Windows users] (click to expand)

Vagrant

Assuming Vagrant is setup (make sure you install VirtualBox as well), run vagrant init hashicorp/precise32 in the ifme directory.

Then add the following in the auto-generated Vagrantfile:

config.vm.network :forwarded_port, guest: 3000, host: 3000

After that, run vagrant up. Then you're ready to run vagrant ssh!

Within the Vagrant box, you must do cd /vagrant to access our codebase. Next, run sudo apt-get update. Now, you will want to follow-up the steps under the next "Locally" section inside of your box! Refer to installation steps for Linux, specifically Ubuntu.

Locally [Recomended if you want to run the environment on your machine, works best for macOS and Linux users] (click to expand)

For Windows Subsystem for Linux (WSL) users

Setting the project up on the Linux installation within WSL is certainly possible. Please proceed by following all Linux instructions within your Linux environment on Windows. Because Windows and the Linux subsystem share ports, it's important that you don't have things like Postgres running on both environments concurrently, as that may prevent Linux from running the application properly.

For macOS users

Thank you @discombobulateme for putting together this summary of what the macOS installation looks like!

Summary of macOS installation (click to expand) Visual map of the macOS installation guide

Before following the next steps please install:

Install Xcode

Get it on your App Store, this should also install git for you.

Install Homebrew

Install through the Homebrew site or through the terminal: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)".

Install Yarn

brew install yarn

Install Code Editor

This is up to your personal preference, though we highly recommend Visual Code Studio.

PostgreSQL

If you are asked to create a new user, please follow these instructions.

macOS (click to expand)

macOS

Install via Homebrew

brew install postgresql

then start the postgres server:

postgres -D /usr/local/var/postgres

For more information, follow this guide for a more detailed setup

Linux (click to expand)

Linux

Install using your package management software (e.g. apt, yum, etc.).

It may also be necessary to install a separate development files package or the Ruby gem may not compile. On Ubuntu/Debian, this package is called postgresql-server-dev-X.Y (e.g. postgresql-server-dev-9.4). If you are unsure of what the package is for your distribution, continue following the instructions; usually, bundler will let you know what you need to install.

Most likely, PostgreSQL will be running under a new user called "postgresql" and your user will not have permission to connect to the database. You can add yourself as a user by running:

sudo -u postgres createuser -s $(whoami)
createdb $(whoami)

Ubuntu

  1. Install the latest package for PostgreSQL via sudo apt-get install postgresql postgresql-contrib.
  2. Run ps -Af | grep postgres to check whether the server was started during installation.
  3. If not, refer to the PostgreSQL documentation for [Starting the Database Server][https://www.postgresql.org/docs/9.6/static/server-start.html] (you may need to select your version at the top of the page).

Debian

  1. Install the following packages: postgresql, postgresql-server-dev, and libpg-dev.
  2. Run ps -Af | grep postgres to check whether the server was started during installation.
  3. If not, refer to the PostgreSQL documentation for [Starting the Database Server][https://www.postgresql.org/docs/9.6/static/server-start.html] (you may need to select your version at the top of the page).
Windows (click to expand)

Windows

Install via graphical installer.

Ruby on Rails

Check out these recommended installation guides:

If you're updating an existing installation through RVM OR rbenv. We recommend using RVM!

RVM (click to expand)

RVM

Assuming you have RVM installed, update to the latest version

rvm get stable --autolibs=enable

Close and re-open the terminal window

rvm install ruby-2.6.6

Check that Ruby has been updated by running ruby -v.

rbenv (click to expand)

rbenv

Follow instructions for updating rbenv at the project's GitHub. Make sure you also upgrade ruby-build if you used Homebrew to install rbenv.

Run the following to install Ruby 2.6.6:

rbenv install 2.6.6

Gems

Update the gem manager by running gem update --system.

Update your gems by running gem update.

If you are missing bundler, please install it

gem install bundler

Make a gemset for the specific Ruby on Rails version through RVM OR rbenv.

RVM (click to expand)

RVM

rvm use ruby-2.6.6@rails6.0.3 --create
rbenv (click to expand)

rbenv

rbenv-gemset

Yarn

Follow steps here for all of the major operating systems.

Configuration Files

Mandatory (click to expand)

Mandatory

There are two config files: config/env/test.env and config/env/development.env. To run the app locally, you should modify test.env and development.env. They are ignored in git to prevent accidentally committing sensitive information.

Automatic setup

For your development and test environments, you can automatically generate the env files by running bin/rake setup_workspace.

Manual setup

Copy the sample files to create your own configuration files:

cp config/env/test.example.env config/env/test.env cp config/env/development.example.env config/env/development.env

Run rake secret twice to generate values for SECRET_KEY_BASE and DEVISE_SECRET_KEY. The values in test.env and development.env can be the same.

BE CAREFUL: The secret should be in the test.env and development.env NOT the config/env/test.example.env or config/env/development.example.env files. The example files are not ignored by git.

Optional (click to expand)

Optional

The following are not mandatory but are required if you would like to test/use these features.

Pusher

Pusher is used in-app notifications. If you would like to use this feature in your local environment, please create your own account (create a Channels project), generate keys, and update PUSHER_APP_ID, PUSHER_KEY, PUSHER_SECRET, and PUSHER_CLUSTER in config/env/test.env and config/env/development.env.

Google OAuth 2.0 IDs

Google OAuth 2.0 IDs is used for OAuth (Sign in with Google) and Calendars (refill dates for Medications).

If you would like to use this feature in your local environment, please create your own account, generate keys and update GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET in config/env/test.env and config/env/development.env.

You'll need to activate both the Google+ API and the Contacts API for OAuth, and the Calendar API for Calendars. Under the credentials tab, make sure to add the Authorized redirect URI as http://localhost:3000/users/auth/google_oauth2/callback. Note, you may have to hit the Save button twice for this to take effect.

We have a wiki with step by step instructions if you get lost in the process.

Facebook OAuth 2.0 IDs

Facebook OAuth 2.0 IDs is used for OAuth (Sign in with Facebook).

If you would like to use this feature in your local environment, please create your own account, generate keys and update FACEBOOK_APP_ID and FACEBOOK_APP_SECRET in config/env/test.env and config/env/development.env.

You'll need to activate the Facebook Login product. Under the settings button for Facebook Login, make sure to add the Authorized redirect URI as http://localhost:3000/users/auth/facebook/callback.

Google API

Google API is used for location autocomplete, specifically the Maps JavaScript API (which needs to be activated). If you would like to use this feature in your local environment, please create] your own account, generate keys and update GOOGLE_API_KEY in config/env/test.env and config/env/development.env.

We have a wiki with step by step instructions if you get lost in the process.

Cloudinary

Cloudinary is used to store profile pictures. If you would like to use this feature in your local environment, please create your own ]account, generate keys, and update CLOUDINARY_CLOUD_NAME, CLOUDINARY_API_KEY, and CLOUDINARY_API_SECRET in config/env/test.env and config/env/development.env.

If you want to generate static images through the Cloudinary CDN, run heroku run rake cloudinary:sync_static.

Email Notifications

To get email notifications working, you must configure SMTP settings in config/env/test.env and config/env/development.env.

The following guide from Launch School is helpful.

Please do not test these with the Testing Accounts. Create new accounts with valid email addresses!

If you want to test out scheduled emails, run the following commands:

bundle exec rake scheduler:send_take_medication_reminders

bundle exec rake scheduler:send_refill_reminders

bundle exec rake scheduler:send_perform_strategy_reminders

bundle exec rake scheduler:send_meeting_reminders

Letter Opener

The gem letter_opener enables test e-mails to be sent without actually sending an e-mail accidentally to someone through SMTP.

You can disable this gem when you deploy the app by commenting it out.

# gem "letter_opener", :group => :development

You can read more about this gem here.

Running the App

Create the development and test databases:

bin/rake db:setup db:test:prepare

Run rake slugs:slugify to update existing entries in the database with slugs (e.g. moments/fun-slug)

Start the local server:

bin/start_app

To view the app, go to http://localhost:3000.

To debug on an Android device, please follow these steps.

When trying to use pry debugger, you might notice that the server stops at the line where you added binding.pry, but you cannot see the rails console to actually interact with the debugger, as per this issue. To go around this, you could:

  1. Build assets:
bin/client.sh
  1. In a separate terminal window, run the rails server:
bundle exec rails s -p 3000 -b '0.0.0.0'

Testing Accounts

They have been created in db/seeds.rb. Feel free to modify seeds.rb to help to your development needs! You can also test with Google accounts.

Email: test1@example.com
Password: passworD@99
Email: test2@example.com
Password: passworD@99
Email: test3@example.com
Password: passworD@99

Admin accounts have access to the admin dashboard where reported users can be seen and users can be banned.

Email: admin@example.com
Password: passworD@99

Accessing the Database

rails db

Note that ifme_test is used when running unit tests.

Best Practices

Yay, things are up and running! Please review our Best Practices next.

Clone this wiki locally