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

CD #28

Merged
merged 3 commits into from
Jan 22, 2024
Merged

CD #28

Show file tree
Hide file tree
Changes from 2 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
79 changes: 79 additions & 0 deletions .github/workflows/cd.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: CD Dev

on:
push:
branches:
- main

jobs:
Deploy-Dev:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -

- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm
working-directory: ./workers

- name: Setup Node.js
uses: actions/setup-node@master
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
working-directory: ./workers

- uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install dependencies
run: (yarn install --nonInteractive --frozen-lockfile --prefer-offline || yarn install --nonInteractive --frozen-lockfile --prefer-offline)
working-directory: ./workers

- name: Deploy
run: yarn deploy:dev
working-directory: ./workers
env:
DEPLOYMENT_STAGE: dev
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
DEV_INNGEST_SIGNING_KEY: ${{ secrets.DEV_INNGEST_SIGNING_KEY }}
DEV_INNGEST_EVENT_KEY: ${{ secrets.DEV_INNGEST_EVENT_KEY }}
DEV_NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.DEV_NEXT_PUBLIC_SUPABASE_URL }}
DEV_NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.DEV_NEXT_PUBLIC_SUPABASE_ANON_KEY }}
DEV_SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.DEV_SUPABASE_SERVICE_ROLE_KEY }}

- uses: supabase/setup-cli@v1
with:
version: latest
- run: supabase link --project-ref $SUPABASE_PROJECT_ID
working-directory: ./web
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.DEV_SUPABASE_ACCESS_TOKEN }}
SUPABASE_DB_PASSWORD: ${{ secrets.DEV_SUPABASE_DB_PASSWORD }}
SUPABASE_PROJECT_ID: ${{ secrets.DEV_SUPABASE_PROJECT_ID }}

- run: supabase db push
working-directory: ./web
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.DEV_SUPABASE_ACCESS_TOKEN }}
SUPABASE_DB_PASSWORD: ${{ secrets.DEV_SUPABASE_DB_PASSWORD }}
SUPABASE_PROJECT_ID: ${{ secrets.DEV_SUPABASE_PROJECT_ID }}
- run: curl -X PUT https://api.dev.fundpublicgoods.ai/api/inngest
42 changes: 42 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: ci

on:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Read .nvmrc
run: echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT
id: nvm

- name: Setup Node.js
uses: actions/setup-node@master
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'

- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -

- name: Install dependencies
run: yarn

- name: Build
run: yarn build
env:
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.DEV_NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.DEV_NEXT_PUBLIC_SUPABASE_ANON_KEY }}
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.DEV_SUPABASE_SERVICE_ROLE_KEY }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ next-env.d.ts
__pycache__

dist
.mypy_cache
.mypy_cache

# serverless
.serverless
9 changes: 4 additions & 5 deletions workers/fund_public_goods/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dotenv import load_dotenv
from fastapi import FastAPI
import inngest.fast_api
# from mangum import Mangum
from fund_public_goods.gitcoin.functions import functions
from mangum import Mangum
from fund_public_goods.gitcoin.functions import functions as gitcoin_functions
from .inngest_client import inngest_client
from .functions import functions
from .api import workers
Expand All @@ -15,10 +15,9 @@
inngest.fast_api.serve(
app,
inngest_client,
functions,
functions + gitcoin_functions,
)
app.include_router(workers.router)
app.include_router(get_version_router)

# TODO: Only use mangum when environment is production
# handler = Mangum(app=app)
handler = Mangum(app=app)
16 changes: 16 additions & 0 deletions workers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "fund-public-goods-api",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"deploy:dev": "npx serverless deploy --config ./serverless.dev.yml --stage dev",
"deploy:prod": "npx serverless deploy --config ./serverless.prod.yml --stage prod",
"package": "npx serverless package"
},
"devDependencies": {
"serverless": "3.38.0",
"serverless-domain-manager": "7.3.3",
"serverless-python-requirements": "6.0.1"
}
}
49 changes: 49 additions & 0 deletions workers/serverless.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
service: fund-public-goods

plugins:
- serverless-python-requirements
- serverless-domain-manager

package:
individually: true

provider:
name: aws
runtime: python3.10
region: us-east-1
memorySize: 256
timeout: 30
environment:
DEPLOYMENT_STAGE: dev
INNGEST_PROD: true
INNGEST_ENV: fundpublicgoods-dev
INNGEST_SIGNING_KEY: ${env:DEV_INNGEST_SIGNING_KEY}
INNGEST_EVENT_KEY: ${env:DEV_INNGEST_EVENT_KEY}
RESEND_API_KEY: ${env:DEV_RESEND_API_KEY}
NEXT_PUBLIC_SUPABASE_URL: ${env:DEV_NEXT_PUBLIC_SUPABASE_URL}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${env:DEV_NEXT_PUBLIC_SUPABASE_ANON_KEY}
SUPABASE_SERVICE_ROLE_KEY: ${env:DEV_SUPABASE_SERVICE_ROLE_KEY}

custom:
pythonRequirements:
dockerizePip: true
layer:
name: fund-public-goods-deps
description: Dependencies of fund-public-goods
compatibleRuntimes:
- python3.10
customDomain:
domainName: api.dev.fundpublicgoods.ai
certificateName: api.dev.fundpublicgoods.ai
createRoute53Record: true

functions:
fund-public-goods:
handler: fund_public_goods.main.handler
layers:
- { Ref: PythonRequirementsLambdaLayer }
events:
- http:
path: /{path+}
method: any
cors: true
Loading