Skip to content

Installation

Julia Nguyen edited this page Nov 9, 2024 · 75 revisions

The app uses Ruby 3.1.4 and Rails 7.0.8.1. Please stick to these versions.

Dev Environment

Docker [Works best for macOS (Apple Chip) and Windows users] (click to expand)

Docker

Assuming Docker is set up, you can start the server using. See the Get Started guide for your operating system. Additionally, you will need to run a few one-time setup commands.

First, run the following one-time command that builds the necessary images:

docker compose build

After the images for running the app are created you will need to create the databases, run migrations, and seed test data:

docker compose run app bundle exec rake db:create
docker compose run app bundle exec rake db:migrate 
docker compose run app bundle exec rake db:seed

You should be able to successfully run up to have the application run locally (Note: 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)

docker compose up

Or open a shell within the running docker image using:

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

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

If you're seeing any errors related to gems that need updating running docker compose build to rebuild your image should fix things!

Vagrant [Works best 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 [Works best for macOS (Intel) 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.

Installation guidelines for WSL can be found here.

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/main/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

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 [Intel] (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-3.1.4

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

rbenv [Intel] (click to expand)

rbenv [Intel]

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 3.1.4:

rbenv install 3.1.4
rbenv [M1] (click to expand)

rbenv [M1]

Install using rbenv. You can find the installation guide here.

If you get an implicit function declaration error, run the command:

RUBY_CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 3.1.4

Note: if you previously installed Ruby 3.1.4 with RVM, you must add this at the beginning of your $PATH in .zshrc:

/Users/username/.rbenv/shims:

Run bundle update ffi sassc

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-3.1.4@rails6.0.3.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 and meetings for Groups).

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 a location in the account profile and for saving Medication refill reminders to your calendar.

To get the location working, in the Maps API, enable the following:

  • Directions API
  • Distance Matrix API
  • Geocoding API
  • Maps Elevation API
  • Maps JavaScript API
  • Places API

To get the calendar working, enable the Google Calendar API.

If you would like to use these features 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, CLOUDINARY_API_SECRET, and CLOUDINARY_SECURE_URL 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)

If you have installed the app locally or through Vagrant, start the local server:

bin/start_app

If you have installed the app through Docker, start the local server:

docker compose up

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