Skip to content

Latest commit

 

History

History
189 lines (138 loc) · 8.23 KB

README.md

File metadata and controls

189 lines (138 loc) · 8.23 KB

Stuyvesant Spectator API

The official API for the Stuyvesant Spectator.

Setting Up

  1. Clone the repo
$ git clone https://github.com/stuyspec/stuy-spec-api.git
  1. Follow the directions below to set up Rails. Ignore the MySQL section; instead, only complete the PostgreSQL section: https://gorails.com/setup/

  2. On linux, go to /etc/postgresql/YOUR_VERSION/main/pg_hba.conf. At the bottom, change the method to trust for all lines that start with local all or host all. Then, run sudo systemctl restart postgresql

  3. In the stuy-spec-api repository, create your dotenv file.

$ echo PG_HOST=localhost > .env
  1. If you intend to use this API while working with client-app or cli-uploader, follow the setup instructions in the AWS S3 section below. Then create, migrate, and seed the database with media.
$ rails db:create db:migrate db:seed media=true
  1. If you did not follow instruction 4, create, migrate, and seed the database.
$ rails db:create db:migrate db:seed
  1. To start the server, run:
rails server

Docker

If the above doesn't work, you can use Docker. Docker encapsulates your runtime environment into a "container", basically making your configuration deterministic and reproducible.

  1. Follow steps 1-3 above

  2. Run docker-compose build

  3. Run docker-compose up. If you get an error saying it can't connect to db, try stopping and rerunning.

  4. In a separate terminal instance, run docker-compose run web rake db:create. If there are a bunch of errors about being unable to connect to TCP/IP at 5432, just check the top of those errors to see if something like Created database stuy-spec-api_development was created. If so, then ignore the errors.

  5. Run docker-compose run web rails db:migrate db:seed

  6. To start the server, run docker-compose run web rails server.

AWS

You will need to be an IAM user for the Spectator Web AWS account. Request an account by messaging one of the editors on Facebook.

While you wait for your beloved editors to get the account set up, watch this IAM introduction.

After you receive your login information, navigate to the stuyspec AWS console and log in. In the AWS console, navigate to the service "IAM". Go to Users, in the sidebar, and click on your username. Click the Security Credentials tab and create an Access Key. It will prompt you to download a file with your new access key and secret key. Download it.

If you don't have one already, navigate to your home directory (cd ~/) and make a directory called .aws. Then create a file called config with this content:

[default]
region=us-east-2
output=json

Next, create a file called credentials with this content:

[default]
aws_access_key_id=YOUR_ACCESS_KEY_ID
aws_secret_access=YOUR_SECRET_ACCESS

rails console

The Rails console lets you interact with the Rails API from the command line with Ruby. For instance:

> a = Article.find_by(title: 'The Original Title')
> a.title = 'New Title'
> a.save

This function is helpful if you know cli-uploader made a mistake or you want to make a small change in a record of the database. Here are the steps to open the Rails console for our production database:

  1. You'll need an SSH key to be able to SSH. This comes in the form of a .pem key file that you put into your home ssh directory (~/.ssh). Download the .pem key (ask the current Web Editors if you need help with that) and place it into the aforementioned directory. NEVER share this file publically.

  2. Use the ssh command to connect to our Lightsail instance. You can find the IP by following ssh instructions on Lightsail

  3. Once you're in, navigate to the directory of the Rails API (cd /deploy/current).

  4. Here, you can run rails console or rails c for short to manipulate the database.

To exit the Rails console, use Ctrl-D. To exit the SSH, use Ctrl-D as well.

Deploying stuy-spec-api

  1. Go to your local stuy-spec-api directory and check out and pull down the branch you want to deploy.

  2. Run bundle exec cap production deploy. The automatic capistrano script spearheaded by Darius Jankauskas should do the trick. Thanks Darius!

Testing GraphQL

Use GraphQL to test your GraphQL queries.