Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying #3

Merged
merged 3 commits into from
Jun 4, 2024
Merged
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
33 changes: 29 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,42 @@ module.exports = {
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"prettier",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
plugins: [
"react",
"react-hooks",
"@typescript-eslint",
"import",
"react-refresh",
"prettier",
],
rules: {
"import/named": "warn",
"import/no-self-import": "error",
"import/order": "error",
"import/newline-after-import": "error",
"import/no-unused-modules": ["warn", { unusedExports: true }],
"@typescript-eslint/no-explicit-any": "warn",
"import/no-useless-path-segments": [
"error",
{
noUselessIndex: true,
},
],
"import/max-dependencies": [
"warn",
{
max: 20,
ignoreTypeImports: false,
},
],
"prettier/prettier": "error",
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
},
globals: {
process: true,
},
};
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
ignore = E501,E731,W503
exclude =
.chalice
.venv
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* @skaplan-dev
deploy.sh @devinmatte @nathan-weinberg
.github @devinmatte @nathan-weinberg
.flake8 @devinmatte @nathan-weinberg
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Motivation

<!-- Why are you making this change, what problem does it solve? Include links to relevant issues -->

## Changes

<!-- What does this change exactly? Include relevant screenshots, videos, links -->

## Testing Instructions

<!-- How can the reviewer confirm these changes do what you say they do? -->
11 changes: 11 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ci/cd:
- .github/**/*
- deploy.sh

dependencies:
- package.json
- package-lock.json

documentation:
- README.md
- LICENSE
62 changes: 62 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: deploy

on:
workflow_dispatch:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ["20"]
env:
AWS_PROFILE: transitmatters
AWS_DEFAULT_REGION: us-east-1
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
TM_LABS_WILDCARD_CERT_ARN: ${{ secrets.TM_LABS_WILDCARD_CERT_ARN }}
MBTA_V3_API_KEY: ${{ secrets.MBTA_V3_API_KEY }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}

steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.12
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Set up Node ${{ matrix.node-version }}.x
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Set up CI Cache
uses: actions/cache@v4
with:
path: |
~/.npm
${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
restore-keys: |
${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}-
- name: Check if package-lock.json is up to date
run: |
npx --yes [email protected]
- name: Generate AWS profile
run: |
mkdir ~/.aws
cat >> ~/.aws/credentials << EOF
[$AWS_PROFILE]
aws_access_key_id = $AWS_ACCESS_KEY_ID
aws_secret_access_key = $AWS_SECRET_ACCESS_KEY
EOF
- name: Run deploy shell script
run: |
npm ci
npm run build
bash deploy.sh
60 changes: 60 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: lint

on:
pull_request:
push:
branches:
- main

jobs:
frontend:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['20']
python-version: ['3.12']
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up Node ${{ matrix.node-version }}.x
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Check if package-lock.json is up to date
run: |
npx --yes [email protected]
- name: Lint frontend code with ESLint
run: |
curl -sSL https://install.python-poetry.org | python3 -
npm ci
npm run lint-frontend

backend:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['20']
python-version: ['3.12']
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up Node ${{ matrix.node-version }}.x
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Check if package-lock.json is up to date
run: |
npx --yes [email protected]
- name: Lint backend code with Flake8
run: |
curl -sSL https://install.python-poetry.org | python3 -
npm ci
npm run lint-backend
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ node_modules
dist
dist-ssr
*.local
*.pyc
server/**/__pycache__
requirements.txt
server/cfn/*
server/.chalice/deployments/*

# Editor directories and files
.vscode/*
Expand All @@ -23,3 +28,4 @@ dist-ssr
*.sln
*.sw?
.env
.envrc
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"bradlc.vscode-tailwindcss"
]
}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Pride Bus Tracker

- Tracks the MBTA Pride bus #1833

## Requirements to develop locally

- node 20.x and npm 10+ required
- With `nvm` installed, use `nvm install && nvm use`
- verify with `node -v`
- Python 3.12 with recent poetry (1.7.0 or later)
- Verify with `python --version && poetry --version`
- `poetry self update` to update poetry
- If using `pyenv`, `pyenv install 3.12.0`

## Support TransitMatters

If you've found this app helpful or interesting, please consider [donating](https://transitmatters.org/donate) to TransitMatters to help support our mission to provide data-driven advocacy for a more reliable, sustainable, and equitable transit system in Metropolitan Boston.
60 changes: 60 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash -x

set -e

export AWS_PROFILE=transitmatters
export AWS_REGION=us-east-1
export AWS_DEFAULT_REGION=us-east-1
export AWS_PAGER=""

if [[ -z "$DD_API_KEY" || -z "$TM_LABS_WILDCARD_CERT_ARN" || -z "$MBTA_V3_API_KEY" ]]; then
echo "Must provide DD_API_KEY, TM_LABS_WILDCARD_CERT_ARN and MBTA_V3_API_KEY in environment" 1>&2
exit 1
fi

STACK_NAME=pride-bus
CHALICE_STAGE=production

FRONTEND_HOSTNAME="pride-bus.labs.transitmatters.org"
FRONTEND_ZONE="labs.transitmatters.org"
FRONTEND_BUCKET="$FRONTEND_HOSTNAME"
FRONTEND_CERT_ARN="$TM_LABS_WILDCARD_CERT_ARN"

BACKEND_HOSTNAME="pride-bus-api.labs.transitmatters.org"
BACKEND_ZONE="labs.transitmatters.org"
BACKEND_BUCKET=pride-bus-backend
BACKEND_CERT_ARN="$TM_LABS_WILDCARD_CERT_ARN"

# Identify the version and commit of the current deploy
GIT_VERSION=`git describe --tags --always`
GIT_SHA=`git rev-parse HEAD`
echo "Deploying version $GIT_VERSION | $GIT_SHA"

# Adding some datadog tags to get better data
DD_TAGS="git.commit.sha:$GIT_SHA,git.repository_url:github.com/transitmatters/pride-bus"

npm run build

# Deploy to cloudformation
pushd server/ > /dev/null
poetry export --without-hashes --output requirements.txt
poetry run chalice package --stage $CHALICE_STAGE --merge-template cloudformation.json cfn/
aws cloudformation package --template-file cfn/sam.json --s3-bucket $BACKEND_BUCKET --output-template-file cfn/packaged.yaml
aws cloudformation deploy --template-file cfn/packaged.yaml --stack-name $STACK_NAME --capabilities CAPABILITY_IAM --no-fail-on-empty-changeset --parameter-overrides \
TMFrontendHostname=$FRONTEND_HOSTNAME \
TMFrontendZone=$FRONTEND_ZONE \
TMFrontendCertArn=$FRONTEND_CERT_ARN \
TMBackendCertArn=$BACKEND_CERT_ARN \
TMBackendHostname=$BACKEND_HOSTNAME \
TMBackendZone=$BACKEND_ZONE \
MbtaV3ApiKey=$MBTA_V3_API_KEY \
DDApiKey=$DD_API_KEY \
GitVersion=$GIT_VERSION \
DDTags=$DD_TAGS

popd > /dev/null
aws s3 sync dist/ s3://$FRONTEND_BUCKET

# Grab the cloudfront ID and invalidate its cache
CLOUDFRONT_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Aliases.Items!=null] | [?contains(Aliases.Items, '$FRONTEND_HOSTNAME')].Id | [0]" --output text)
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths "/*"
Loading