Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ COPY . .
CMD [ "npm", "start" ]

# Build
# docker build -t tryn-api .
# docker build -t opentransit-state-api .

# Run
# docker run -p 4000:4000 tryn-api:latest
# docker run -p 4000:4000 opentransit-state-api:latest
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
# tryn-api
# OpenTransit State API

API for historical transit vehicle location data.

tryn-api provides a GraphQL API for the data previously stored in S3 by Orion (https://github.com/trynmaps/orion).
OpenTransit State API provides a GraphQL API for the data previously stored in S3 by OpenTransit Collector (https://github.com/codeforpdx/opentransit-collector).

## Getting Started

See our welcome doc for contribution and deployment guidelines.
https://bit.ly/opentransit-onboarding

1. Clone this repo.

2. Create a docker-compose.override.yml file that sets the environment variable TRYNAPI_S3_BUCKET to the name of the S3 bucket where data was stored by Orion,
and provides AWS credentials with read access to that bucket. tryn-api reads data from S3 using the AWS credentials from the default locations,
2. Create a docker-compose.override.yml file that sets the environment variable OPENTRANSIT_S3_BUCKET to the name of the S3 bucket where data was stored by OpenTransit Collector, and provides AWS credentials with read access to that bucket. The OpenTransit State API reads data from S3 using the AWS credentials from the default locations,
e.g. a credentials file located within the Docker container at /root/.aws/credentials (using the default profile or a profile named by AWS_PROFILE),
or using the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. For example:

```
version: "3.7"
services:
tryn-api-dev:
state-api-dev:
volumes:
- ../.aws:/root/.aws
environment:
AWS_PROFILE: "default"
TRYNAPI_S3_BUCKET: "my-opentransit-bucket"
OPENTRANSIT_S3_BUCKET: "my-opentransit-bucket"
```

2. Run `docker-compose up`
Expand All @@ -45,7 +41,7 @@ The root query object for the API.

| Parameter Name | Type | Description |
| --- | --- | --- |
| `agency` | `String!` | ID of the agency. The agency ID should be the same ID used in the configuration for Orion. |
| `agency` | `String!` | ID of the agency. The agency ID should be the same ID used in the configuration for OpenTransit Collector. |
| `startTime` | `BigInt!` | Start timestamp in seconds since the Unix epoch. |
| `endTime` | `BigInt!` | End timestamp in seconds since the Unix epoch , exclusive. |
| `routes` | `[String!]` | List of route IDs to return vehicle data. |
Expand All @@ -54,7 +50,7 @@ The root query object for the API.

| Field Name | Type | Description |
| --- | --- | --- |
| `agencyId` | `String` | ID of the agency. The agency ID should be the same ID used in the configuration for Orion. |
| `agencyId` | `String` | ID of the agency. The agency ID should be the same ID used in the configuration for OpenTransit Collector. |
| `startTime` | `BigInt` | Start timestamp in seconds since the Unix epoch. |
| `endTime` | `BigInt` | End timestamp in seconds since the Unix epoch, exclusive. |
| `routes` | [`[RouteHistory]`](#routehistory) | Array of historical state for each route. |
Expand Down Expand Up @@ -117,4 +113,4 @@ query {
}
```

Substitute startTime and endTime with epoch timestamps (in seconds) corresponding to when Orion was actually running.
Substitute startTime and endTime with epoch timestamps (in seconds) corresponding to when OpenTransit Collector was actually running.
12 changes: 6 additions & 6 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/tryn-api:$REVISION_ID', '.' ]
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/opentransit-state-api:$REVISION_ID', '.' ]
- name: 'gcr.io/cloud-builders/docker'
args: [ 'push', 'gcr.io/$PROJECT_ID/tryn-api:$REVISION_ID' ]
args: [ 'push', 'gcr.io/$PROJECT_ID/opentransit-state-api:$REVISION_ID' ]
- name: 'gcr.io/cloud-builders/docker'
args: [ 'tag', 'gcr.io/$PROJECT_ID/tryn-api:$REVISION_ID', 'gcr.io/$PROJECT_ID/tryn-api:latest' ]
args: [ 'tag', 'gcr.io/$PROJECT_ID/opentransit-state-api:$REVISION_ID', 'gcr.io/$PROJECT_ID/opentransit-state-api:latest' ]
- name: 'gcr.io/cloud-builders/docker'
args: [ 'push', 'gcr.io/$PROJECT_ID/tryn-api:latest' ]
args: [ 'push', 'gcr.io/$PROJECT_ID/opentransit-state-api:latest' ]
- name: 'gcr.io/cloud-builders/kubectl'
args: [ 'set', 'image', 'deployment/tryn-api', 'tryn-api=gcr.io/$PROJECT_ID/tryn-api:$REVISION_ID' ]
args: [ 'set', 'image', 'deployment/opentransit-state-api', 'opentransit-state-api=gcr.io/$PROJECT_ID/opentransit-state-api:$REVISION_ID' ]
env:
- 'CLOUDSDK_COMPUTE_ZONE=${_COMPUTE_ZONE}'
- 'CLOUDSDK_CONTAINER_CLUSTER=${_CONTAINER_CLUSTER}'
images:
- 'gcr.io/$PROJECT_ID/tryn-api:$REVISION_ID'
- 'gcr.io/$PROJECT_ID/opentransit-state-api:$REVISION_ID'
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.7"
services:
tryn-api-dev:
container_name: tryn-api-dev
state-api-dev:
container_name: state-api-dev
build:
dockerfile: Dockerfile
context: .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
run: tryn-api
name: tryn-api
run: opentransit-state-api
name: opentransit-state-api
spec:
selector:
matchLabels:
run: tryn-api
run: opentransit-state-api
strategy:
rollingUpdate:
maxSurge: 1
Expand All @@ -16,16 +16,18 @@ spec:
template:
metadata:
labels:
run: tryn-api
run: opentransit-state-api
spec:
containers:
- image: gcr.io/poetic-genius-233804/tryn-api:latest
- image: gcr.io/YOUR_GCP_PROJECT_ID/opentransit-state-api:latest
imagePullPolicy: IfNotPresent
name: tryn-api
name: opentransit-state-api
resources:
requests:
cpu: 0.03
env:
- name: OPENTRANSIT_S3_BUCKET
value: YOUR_OPENTRANSIT_S3_BUCKET
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ apiVersion: v1
kind: Service
metadata:
labels:
run: tryn-api
name: tryn-api
run: opentransit-state-api
name: opentransit-state-api
spec:
ports:
- protocol: "TCP"
port: 80
targetPort: 4000
selector:
run: tryn-api
run: opentransit-state-api
type: LoadBalancer
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "tryn-api",
"name": "opentransit-state-api",
"version": "1.0.0",
"description": "API for historical transit vehicle location data",
"private": true,
Expand All @@ -9,13 +9,13 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/trynmaps/tryn-api.git"
"url": "git+https://github.com/codeforpdx/opentransit-state-api.git"
},
"author": "Eddy",
"bugs": {
"url": "https://github.com/trynmaps/tryn-api/issues"
"url": "https://github.com/codeforpdx/opentransit-state-api/issues"
},
"homepage": "https://github.com/trynmaps/tryn-api#readme",
"homepage": "https://github.com/codeforpdx/opentransit-state-api",
"dependencies": {
"@creditkarma/graphql-loader": "^0.6.6",
"@turf/turf": "^5.1.6",
Expand Down
6 changes: 4 additions & 2 deletions src/helpers/s3Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ var zlib = require('zlib');

const s3 = new AWS.S3();

const s3Bucket = process.env.TRYNAPI_S3_BUCKET || "orion-vehicles";
const s3Bucket = process.env.OPENTRANSIT_S3_BUCKET;
if (!s3Bucket) {
throw new Error("Missing OPENTRANSIT_S3_BUCKET environment variable");
}
console.log(`Reading state from s3://${s3Bucket}`);

/*
Expand Down Expand Up @@ -123,4 +126,3 @@ function insertTimestamp(timestamp, vehicles) {
module.exports = {
getVehicles,
};