Skip to content

πŸ—„πŸ›°πŸ“² Rails API for The Spectator; GraphQL server, written with PostgreSQL.

License

Notifications You must be signed in to change notification settings

cor10/stuyspec-api

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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. 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

Setting up S3

Once the ~/.aws directory is set up above, S3 should work automagically.

Using Elastic Beanstalk

Elastic Beanstalk is an orchestration service offered from Amazon Web Services for deploying infrastructure which orchestrates various AWS services, including EC2 (a cloud computing service) and S3. It is where we host our production database.

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. Install the Elastic Beanstalk CLI: (Mac, Linux, Windows).

  2. Run eb init. Select the default region as choice 1 (us-east-1). Select the default application as choice 1 (stuyspec-api-prod). DO NOT create a new application and DO NOT create a new environment.

  3. 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 (either from Jason Kao or Nicholas Yang) and place it into the aforementioned directory. NEVER share this file publically.

  4. eb ssh and connect to our EB instance.

  5. Navigate to the directory of the Rails API (cd /var/app/current).

  6. Here, you can run rails console and 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 eb init. Select the default region as choice 1 (us-east-1). Select the default application as choice 1 (stuyspec-api-prod). DO NOT create a new application and DO NOT create a new environment.

  3. Run eb deploy.

Testing GraphQL

Use GraphiQL to test your GraphQL queries.

About

πŸ—„πŸ›°πŸ“² Rails API for The Spectator; GraphQL server, written with PostgreSQL.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 97.9%
  • HTML 1.4%
  • Other 0.7%