The official API for the Stuyvesant Spectator.
- Clone the repo
$ git clone https://github.com/stuyspec/stuy-spec-api.git
-
Follow the directions below to set up Rails. Ignore the MySQL section; instead, only complete the PostgreSQL section: https://gorails.com/setup/
-
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
-
In the
stuy-spec-api
repository, create your dotenv file.
$ echo PG_HOST=localhost > .env
- 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
- If you did not follow instruction 4, create, migrate, and seed the database.
$ rails db:create db:migrate db:seed
- To start the server, run:
rails server
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.
-
Follow steps 1-3 above
-
Run
docker-compose build
-
Run
docker-compose up
. If you get an error saying it can't connect to db, try stopping and rerunning. -
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 likeCreated database stuy-spec-api_development
was created. If so, then ignore the errors. -
Run
docker-compose run web rails db:migrate db:seed
-
To start the server, run
docker-compose run web rails server
.
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
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:
-
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. -
Use the
ssh
command to connect to our Lightsail instance. You can find the IP by following ssh instructions on Lightsail -
Once you're in, navigate to the directory of the Rails API (
cd /deploy/current
). -
Here, you can run
rails console
orrails c
for short to manipulate the database.
To exit the Rails console, use Ctrl-D
. To exit the SSH, use Ctrl-D
as well.
-
Go to your local
stuy-spec-api
directory and check out and pull down the branch you want to deploy. -
Run
bundle exec cap production deploy
. The automatic capistrano script spearheaded by Darius Jankauskas should do the trick. Thanks Darius!
Use GraphQL to test your GraphQL queries.