Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stuyspec/stuyspec-api
🗄🛰📲 Rails API for The Spectator; GraphQL server, written with PostgreSQL.
https://github.com/stuyspec/stuyspec-api
database docker graphql-server postgresql rails-api
Last synced: 4 days ago
JSON representation
🗄🛰📲 Rails API for The Spectator; GraphQL server, written with PostgreSQL.
- Host: GitHub
- URL: https://github.com/stuyspec/stuyspec-api
- Owner: stuyspec
- License: mit
- Created: 2017-07-30T21:00:08.000Z (over 7 years ago)
- Default Branch: develop
- Last Pushed: 2023-03-08T17:24:57.000Z (almost 2 years ago)
- Last Synced: 2024-03-27T13:17:25.354Z (10 months ago)
- Topics: database, docker, graphql-server, postgresql, rails-api
- Language: Ruby
- Homepage: https://api.stuyspec.com
- Size: 2.93 MB
- Stars: 11
- Watchers: 8
- Forks: 5
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```2. Follow the directions below to set up Rails. Ignore the MySQL section; instead, only complete the PostgreSQL section: https://gorails.com/setup/
3. 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`
4. In the `stuy-spec-api` repository, create your [dotenv](https://github.com/bkeepers/dotenv) file.
```
$ echo PG_HOST=localhost > .env
```5. If you intend to use this API while working with client-app or cli-uploader, follow the setup instructions in the [AWS S3](#setting-up-s3) section below. Then create, migrate, and seed the database with media.
```
$ rails db:create db:migrate db:seed media=true
```6. If you did not follow instruction 4, create, migrate, and seed the database.
```
$ rails db:create db:migrate db:seed
```7. 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](https://www.youtube.com/watch?v=Ul6FW4UANGc).
After you receive your login information, navigate to the [stuyspec AWS console](https://stuyspec.signin.aws.amazon.com/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](http://guides.rubyonrails.org/command_line.html#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](https://lightsail.aws.amazon.com/ls/webapp/home/instances)
3. Once you're in, navigate to the directory of the Rails API (`cd /deploy/current`).
6. 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](https://github.com/DJankauskas) should do the trick. Thanks Darius!
## Testing GraphQL
Use [GraphQL](https://github.com/graphql/graphiql) to test your GraphQL queries.