Mental Health Prototype

Prototype goal => Help to overcome the stigma of mental health. Stigma can lead to discrimination. Discrimination may be obvious and direct, such as someone making a negative remark about your mental illness or your treatment. We will provide a list of therapist to our community in order that the people who need help could find some resources. We will help to address this systemic issue as a society.

Screen Shot 2022-10-23 at 11 27 12 PMScreen Shot 2022-10-23 at 11 27 36 PM

Getting Started with Mental Health Prototype Project

This README describes the steps needed to get up and running as a developer of the project. This project uses Rails 6, SQL, Bootstrap and to send emails we use the gem letter_opener. The instructions below describe how you set up an ubuntu linux environment, including linux running under vagrant on Windows. The steps for Mac are similar except that you do brew install.

Configuring Vagrant if you are using it Rails 6 uses Webpacker and Yarn. As a result, it requires support in the environment for symbolic links. To enable this, add the following to your Vagrantfile:

config.vm.provider "virtualbox" do |v| v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"] end

You may already have the config.vm.provider block, in which case you add the line described. Then, bring down your vagrant environment with "vagrant halt" if it is running, and close the Git Bash session. Then, start a new Git Bash session running it as the windows administrator. Then do a "vagrant up". From now on, whenever you do "vagrant up", you will need to do it from a Git Bash session that was run as the windows administrator.

Installing Prerequisites on Linux (and Vagrant) Do:

sudo apt-get update sudo apt-get install postgresql sudo apt-get install postgresql-contrib sudo apt-get install libpq-dev sudo apt-get install yarn curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash nvm install --lts sudo apt remove nodejs which node

The which command will return a filename like

/home/vagrant/.nvm/versions/node/v14.15.1/bin/node

You create a symbolic link to it via

ln -s /usr/bin/nodejs /home/vagrant/.nvm/versions/node/v14.15.1/bin/node

Be sure that the ln command is passed the actual location returned by which. The node/nodejs stuff is not needed on mac.

Installing Prerequisites on Mac OS

Check if you are running Mac OS Catalina. That is done by clicking on the apple icon in the upper left corner of your screen, and then clicking on About This Mac. If you are running Catalina, which is the most current release, you will have to do the following steps:

curl -sL https://github.com/nodejs/node-gyp/raw/master/macOS_Catalina_acid_test.sh | bash

The above command may return an error. If so, do the following:

sudo rm -rf /Library/Developer/CommandLineTools (You will have to enter your admin password) sudo xcode-select --reset xcode-select --install

Then repeat the curl command above. The error should go away. If it does not, you can contact me.

Now we can actually install the prerequisites. You should have installed brew when you originally set up your Mac to run rails. Check that it is there with this command:

brew -v

If you do not have brew, instructions for installing it are here: https://brew.sh/ . Now, do the following commands:

brew update brew doctor brew services start postgresql brew install yarn

Each of these commands should complete without error. If not, you can contact me adi_111@icloud.com.

Getting started with the git repository In your browser, go to https://github.com/adrianagithub/mhproject Then fork that repository into your own github workspace. Then clone your mhproject workspace to your laptop, in an appropriate directory.

git remote add upstream https://github.com/adrianagithub/mhproject

Setting up the Mental Health Prototype

We will assume that everyone is running either mac or linux ubuntu. Windows users will run linux ubuntu under vagrant as for the class. We will use Rails 6.x. For this version of Rails, you must install a current version of node.js, and you must also install yarn. We will also have to install the database sqlite3, which will be our production database. Ubuntu setup (including for Ubuntu under vagrant) sudo apt-get update sudo apt-get install npm sudo npm install npm@latest -g sudo npm cache-clean -f sudo npm install -g n sudo n stable

At this point, you will have installed the latest stable version of node.js. You should exit your command window and start a new one to get the right path statement. Then, to install yarn, you do the following:

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt install yarn

This project was developed with

Rails 6.1.7 Ruby 2.6.5 Gems:

  • gem 'sqlite3'
  • gem 'sass-rails', '>= 6'
  • gem 'webpacker', '~> 5.0'
  • gem 'turbolinks', '~> 5'
  • gem 'jbuilder', '~> 2.7'
  • gem 'devise'
  • gem "font-awesome-rails"
  • gem 'bootstrap', '~>5.0'
  • gem 'letter-opener'
  • gem 'rspec-rails'
  • gem 'factory_bot_rails'
  • gem 'faker'
  • gem 'rails-controller-testing'

Installing and setting up the app

Screen Shot 2022-10-23 at 10 14 42 PM

Screen Shot 2022-10-23 at 9 53 52 PM

Here you are some commands to be able to install bootstraps.

Screen Shot 2022-10-23 at 9 55 54 PM

And these are the prerequisites to install bootstraps

Screen Shot 2022-10-23 at 9 56 58 PM

Each of these commands should complete without failures, including Rspec. You will see tests passing when you run the rspec command.

Screen Shot 2022-10-23 at 10 03 45 PM

Then run bin/rails s

adding -b 0.0.0.0 if you are running in vagrant. Then see if you can get to the server at localhost:3000.

If any of this fails, post the problem adi_111@icloud.com

Go to the browser and type http://localhost:3000/. Make a new account (sign up) and a confirmation message will appeared on the screen. Click in the Navigation bar options and continue.

Dockerize App

This section is to know how to use this repository with Docker for a more straightforward installation process. Pre-requisites are only to have Docker working and have the docker-compose command installed.

On the root folder, you need to copy the .env-template file to .env and modify the values of the environment variables with what you need, but with the default values work fine.

cp .env-template .env

Finally, you need to run the docker-compose command and wait until the build process finish.

docker-compose up --build

Architecture

The main idea is to have two containers running, one for the database (PostgreSQL) and the second for the project (Ruby/Rails/Nodejs); the database container uses the main PostgreSQL image from Docker Hub, and the second container is based on Alpine Linux distribution from Docker Hub, too. The essential files are:

  • ./init.sql # It contains the initial sql script to create and grant three databases: dev, test, and prod.
  • ./entrypoint.sh # It contains the command to start the web server rails exec rails s -b 0.0.0.0
  • ./.env # It contains the environment variables and their values
  • ./Dockerfle # It contains the definition of project, package installation and build commands
  • ./docker-compose.yml # It contains the Docker definitions, environment variables, volumes and ports usage

On the last file you can modify the main environment variable for Rails RAILS_ENV, by default the value is "development" but you cand change it for test or production based on your requirements.

Automatic Build&Push the Docker image

We can use the Dockerhub or any other container registry to publish this Docker image and anyone can deploy it on their own local computer, VPS (virtual private server) or any other cloud resource which can execute containers (GKE, ECS, AKS or something similar).

The firts step of GitHub Actions use the Docker official images to login, to build and push the image into the Dockerhub (container registry); so we need to setup two initial secrets values into the Github repository configuration add these variables:

  • DOCKERHUB_USERNAME the value required here is the username of the Dockerhub account (for example adrianaprojects)
  • DOCKERHUB_TOKEN the value required here is the Access token from your account