Skip to content

Commit

Permalink
Merge branch 'main' into clientside-rtree-exploration
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed Nov 25, 2024
2 parents 6f5776f + bf57b0d commit b821dfc
Show file tree
Hide file tree
Showing 113 changed files with 8,177 additions and 3,558 deletions.
159 changes: 159 additions & 0 deletions .github/workflows/fly-deploy-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: Fly Deploy Disctictr V2 Pull Request app
on:
pull_request:
types: [opened, reopened, synchronize, closed]
env:
FLY_API_TOKEN: ${{ secrets.FLY_ORG_TOTKEN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
FLY_REGION: "ewr"
FLY_ORG: "mggg"
jobs:
pr_review_app:
runs-on: ubuntu-latest

concurrency:
group: pr-${{ github.event.number }}

environment:
name: pr-${{ github.event.number }}

steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master

- name: Set shared environment variables
run: |
echo "db_name=${{ github.event.repository.name }}-${{ github.event.number }}-db" >> $GITHUB_ENV
echo "api_app_name=${{ github.event.repository.name }}-${{ github.event.number }}-api" >> $GITHUB_ENV
echo "frontend_app_name=${{ github.event.repository.name }}-${{ github.event.number }}-app" >> $GITHUB_ENV
- name: Destroy Resources
if: github.event.action == 'closed'
run: |
app_name="${{ github.event.repository.name }}-${{ github.event.number }}-api"
frontend_app_name="${{ github.event.repository.name }}-${{ github.event.number }}-app"
db_name="${{ github.event.repository.name }}-${{ github.event.number }}-db"
echo "Destroying app $app_name"
flyctl apps destroy "$app_name" -y
echo "Destroying frontend app $frontend_app_name"
flyctl apps destroy "$frontend_app_name" -y
echo "Destroying database $db_name"
flyctl apps destroy "$db_name" -y
echo "Resources for PR #${{ github.event.number }} have been destroyed."
env:
FLY_API_TOKEN: ${{ secrets.FLY_ORG_TOTKEN }}

# fork new db from existing production db if it doesn't already exist
# eventually we may want to maintain a stage and only fork that
- name: Fork From DB
id: fork-db
if: github.event.action != 'closed'
run: |
if flyctl postgres list | grep -q ${{ github.event.repository.name }}-${{ github.event.number }}-db; then
echo "DB already exists"
else
flyctl postgres create \
--name ${{ github.event.repository.name }}-${{ github.event.number }}-db \
--region ewr \
--initial-cluster-size 1 \
--vm-size shared-cpu-2x \
-p ${{ secrets.FLY_PR_PG_PASSWORD }} \
--org mggg \
--fork-from districtr-v2-db
if [ $? -eq 0 ]; then
echo "Database created successfully."
else
echo "Failed to create database."
exit 1
fi
fi
echo "::set-output name=name::${{ github.event.repository.name }}-${{ github.event.number }}-db"
# manually launch and deploy the api app
- name: Launch API
if: github.event.action != 'closed'
run: |
app="${{ github.event.repository.name }}-${{ github.event.number }}-api"
db_name="${{ github.event.repository.name }}-${{ github.event.number }}-db"
config="fly.toml"
# Check if the app exists
if flyctl apps list | grep -q "$app"; then
echo "App $app already exists. Skipping launch."
else
flyctl launch \
--no-deploy --copy-config --name "$app"
echo "App $app launched successfully."
fi
# Output app name for use in the deploy step
echo "api_app_name=$app" >> $GITHUB_ENV
working-directory: backend

- name: Deploy API
if: github.event.action != 'closed'
run: |
flyctl secrets set \
-a ${{ github.event.repository.name }}-${{ github.event.number }}-api \
POSTGRES_SCHEME="postgresql+psycopg" \
POSTGRES_SERVER="${{ github.event.repository.name }}-${{ github.event.number }}-db.flycast" \
POSTGRES_USER="postgres" \
POSTGRES_PASSWORD=${{ secrets.FLY_PR_PG_PASSWORD }} \
POSTGRES_DB="districtr_v2_api" \
BACKEND_CORS_ORIGINS="https://${{ github.event.repository.name }}-${{ github.event.number }}-app.fly.dev,https://districtr-v2-frontend.fly.dev" \
DATABASE_URL="postgresql://postgres:${{ secrets.FLY_PR_PG_PASSWORD }}@${{ steps.fork-db.outputs.name }}.flycast:5432/districtr_v2_api?sslmode=disable&options=-csearch_path%3Dpublic"
flyctl deploy \
--config fly.toml --app "${{ github.event.repository.name }}-${{ github.event.number }}-api" \
--strategy immediate '--ha=false' --vm-cpu-kind shared --vm-cpus 1 --vm-memory 256 \
working-directory: backend

- name: Check and Launch Frontend App
id: launch
if: github.event.action != 'closed'
run: |
app="${{ github.event.repository.name }}-${{ github.event.number }}-app"
api_app="${{ github.event.repository.name }}-${{ github.event.number }}-api"
config="fly.toml"
# Check if the app exists
if flyctl apps list | grep -q "$app"; then
echo "App $app already exists. Skipping launch."
else
echo "Launching app $app."
# Run the flyctl launch command
flyctl launch \
--no-deploy --copy-config --name "${{ github.event.repository.name }}-${{ github.event.number }}-app" \
--build-arg NEXT_PUBLIC_API_URL="https://${{ github.event.repository.name }}-${{ github.event.number }}-api.fly.dev" \
--build-arg NEXT_PUBLIC_S3_BUCKET_URL=https://districtr-v2-dev.s3.amazonaws.com

echo "App $app launched successfully."
fi

# Output app name for use in the deploy step
echo "frontend_app_name=$app" >> $GITHUB_ENV
working-directory: app

- name: Deploy frontend
if: github.event.action != 'closed'
run: |
app_name="${{ github.event.repository.name }}-${{ github.event.number }}-app"
config="fly.toml"
flyctl secrets set \
-a "${{ github.event.repository.name }}-${{ github.event.number }}-app" \
NEXT_PUBLIC_API_URL="https://${{ github.event.repository.name }}-${{ github.event.number }}-api.fly.dev" \
NEXT_PUBLIC_S3_BUCKET_URL=https://districtr-v2-dev.s3.amazonaws.com
# Deploy the app
flyctl deploy --config "$config" --app "${{ github.event.repository.name }}-${{ github.event.number }}-app" \
--build-arg NEXT_PUBLIC_API_URL="https://${{ github.event.repository.name }}-${{ github.event.number }}-api.fly.dev" \
--build-arg NEXT_PUBLIC_S3_BUCKET_URL=https://districtr-v2-dev.s3.amazonaws.com \
--strategy immediate '--ha=false' \
--vm-cpu-kind shared --vm-cpus 1 --vm-memory 256
working-directory: app
7 changes: 1 addition & 6 deletions .github/workflows/test-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
container-job:
runs-on: ubuntu-latest

container: python:3.12
container: python:3.12.6

services:
postgres:
Expand All @@ -34,11 +34,6 @@ jobs:
- name: Checkout repo code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install GDAL
run: |
apt-get update
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ When reviewing a PR, use the "HIPPO" method to provide feedback:
| **PP** - Personal preference | Possible changes requested. Something the reviewer would do but is non-blocking. |
| **O** - Opinion | Comment for discussion. Non-blocking. Could be a bigger idea that's relevant to the PR. |

Open PRs will spin up a set of test apps for review, following the convention `pr-<pr number>-districtr-districtr-v2-<sub app>`, and would be available for testing at e.g. `https://pr-116-districtr-districtr-v2-app.fly.dev/map`. This behavior can be tweaks via `.github/workflows/fly-deploy-pr.yml`

Updates to PRs will trigger updates to staging apps, including re-running of migrations on the testing db.

### CI/CD

Deployments are managed with GitHub Actions.
2 changes: 1 addition & 1 deletion app/.env.dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_S3_BUCKET_URL=https://pub-fa71193941a74e14a38eee99f30f53d9.r2.dev
NEXT_PUBLIC_S3_BUCKET_URL=https://districtr-v2-dev.s3.amazonaws.com
2 changes: 1 addition & 1 deletion app/.env.docker
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_S3_BUCKET_URL=https://pub-fa71193941a74e14a38eee99f30f53d9.r2.dev
NEXT_PUBLIC_S3_BUCKET_URL=https://districtr-v2-dev.s3.amazonaws.com
2 changes: 1 addition & 1 deletion app/.env.production
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NEXT_PUBLIC_API_URL=https://districtr-v2-api.fly.dev
NEXT_PUBLIC_S3_BUCKET_URL=https://pub-fa71193941a74e14a38eee99f30f53d9.r2.dev
NEXT_PUBLIC_S3_BUCKET_URL=https://districtr-v2-dev.s3.amazonaws.com
16 changes: 16 additions & 0 deletions app/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
// https://github.com/Parker-Ledoux/prettier-airbnb-config
"$schema": "http://json.schemastore.org/prettierrc",
"arrowParens": "avoid",
"bracketSpacing": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 100,
"proseWrap": "always",
"quoteProps": "as-needed",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
};
6 changes: 6 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ ENV NODE_ENV="production"

# Throw-away build stage to reduce size of final image
FROM base as build
ARG NEXT_PUBLIC_API_URL
ARG NEXT_PUBLIC_S3_BUCKET_URL

# Install packages needed to build node modules
RUN apt-get update -qq && \
Expand All @@ -23,6 +25,10 @@ RUN apt-get update -qq && \
COPY --link package-lock.json package.json ./
RUN npm ci --include=dev

RUN echo NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL && \
echo "NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL" > .env.production && \
echo "NEXT_PUBLIC_S3_BUCKET_URL=$NEXT_PUBLIC_S3_BUCKET_URL" >> .env.production

# Copy application code
COPY --link . .

Expand Down
19 changes: 13 additions & 6 deletions app/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
This is a [Next.js](https://nextjs.org/) project bootstrapped with
[`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

Expand All @@ -22,9 +23,11 @@ bun dev

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the
file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to
automatically optimize and load Inter, a custom Google Font.

## Learn More

Expand All @@ -33,10 +36,14 @@ To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your
feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
The easiest way to deploy your Next.js app is to use the
[Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme)
from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more
details.
4 changes: 2 additions & 2 deletions app/fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ primary_region = 'ewr'
[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = 'stop'
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 1
min_machines_running = 0
processes = ['app']

[[vm]]
Expand Down
24 changes: 12 additions & 12 deletions app/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { withSentryConfig } from "@sentry/nextjs";
import {withSentryConfig} from '@sentry/nextjs';
/** @type {import('next').NextConfig} */
const nextConfig = {
async redirects() {
return [
// Basic redirect
{
source: "/",
destination: "/map",
source: '/',
destination: '/map',
permanent: true,
},
];
Expand All @@ -16,12 +16,12 @@ const nextConfig = {
},
resolve: {
alias: {
"@src": "app/src",
"@components": "app/src/components",
"@utils": "app/src/utils",
"@api": "app/src/api",
"@store": "app/src/store",
"@constants": "app/src/constants",
'@src': 'app/src',
'@components': 'app/src/components',
'@utils': 'app/src/utils',
'@api': 'app/src/api',
'@store': 'app/src/store',
'@constants': 'app/src/constants',
},
},
};
Expand All @@ -30,8 +30,8 @@ export default withSentryConfig(nextConfig, {
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options

org: "mggg-districtr",
project: "districtr-v2-app",
org: 'mggg-districtr',
project: 'districtr-v2-app',

// Only print logs for uploading source maps in CI
silent: !process.env.CI,
Expand All @@ -51,7 +51,7 @@ export default withSentryConfig(nextConfig, {
// This can increase your server load as well as your hosting bill.
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
tunnelRoute: "/monitoring",
tunnelRoute: '/monitoring',

// Hides source maps from generated client bundles
hideSourceMaps: true,
Expand Down
Loading

0 comments on commit b821dfc

Please sign in to comment.