-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
3,841 additions
and
2,440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
VITE_ENDPOINT=http://100.111.214.8:8000/new_todo | ||
|
||
# this ENV will load with npm run dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
VITE_ENDPOINT=https://jchv4b5lpu5gea3lkowr5g2bei0tpnsl.lambda-url.eu-central-1.on.aws/new_todo | ||
|
||
# this ENV will load with npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Deploy kbsb-demodash | ||
run-name: ${{ github.actor }} is deploying. | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy-frontend: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v3 | ||
- run: echo "make a node environment" | ||
- run: echo "install pnpm" | ||
- run: echo "build frontend" | ||
- run: echo "copy dist folder to Scaleway" | ||
- run: echo "purge Cloudflare cache" | ||
- name: List files in the repository | ||
run: | | ||
ls ${{ github.workspace }} | ||
- run: | | ||
echo "🍏 This job's status is ${{ job.status }}." | ||
node-version: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
- run: node --version | ||
- run: npm --version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ dist/ | |
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
# lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# run development server | ||
# accept traffic from all of the available interfaces (0.0.0.0) | ||
dev: | ||
pnpm run dev | ||
|
||
# export/build for production | ||
build: | ||
pnpm run build | ||
|
||
# preview/test the production export on 0.0.0.0:8000 | ||
preview: | ||
cd dist; python -m http.server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>kbsb-demodash</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
# the shebang is ignored, but nice for editors | ||
|
||
use nix | ||
# source shell.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.9.16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Readme | ||
|
||
Lambda functions for the React front end widgets. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
extend-select = ["C4", "SIM", "TCH"] | ||
ignore = [] | ||
show-fixes = true | ||
target-version = "py39" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
|
||
pkgs.mkShell { | ||
name = "NIX"; | ||
buildInputs = [ | ||
pkgs.python39 | ||
pkgs.python39Packages.pip | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export AWS_PROFILE="YOUR_PROFILE_NAME" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
**/__pycache__/ | ||
.aws/ | ||
.venv/ | ||
events/ | ||
.env | ||
.env.example | ||
.envrc | ||
Makefile | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
AIRTABLE_API_KEY=api_key | ||
AIRTABLE_BASE_ID=base_id | ||
AIRTABLE_TABLE_NAME=table_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# also source the .envrc of parent directory | ||
source_up | ||
|
||
#! The order is important | ||
#! Sourcing the parent env after layout discards the python env | ||
|
||
# set name for virtual environment | ||
export VIRTUAL_ENV=.venv | ||
# use the python env | ||
layout python3 | ||
|
||
# source venv alias | ||
alias svenv="source .venv/bin/activate" | ||
|
||
# https://github.com/direnv/direnv/wiki/Python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM public.ecr.aws/lambda/python:3.9 | ||
|
||
# Copy function code | ||
COPY requirements.txt ${LAMBDA_TASK_ROOT} | ||
# COPY app.py ${LAMBDA_TASK_ROOT} | ||
COPY . ${LAMBDA_TASK_ROOT} | ||
|
||
# install dependencies | ||
RUN pip install -r requirements.txt | ||
# you don't need a venv in a container | ||
|
||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) | ||
# make sure that the Lambda container use the Mangum handler | ||
# and that your local test environment uses the app:app FastAPI function | ||
CMD [ "app.handler" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# include environment variables in every sub-shell | ||
include .aws/.env | ||
# all targets refer to tasks (instead of files) | ||
.PHONY: * | ||
|
||
ecr = 011809624525.dkr.ecr.eu-central-1.amazonaws.com | ||
region = eu-central-1 | ||
image_name = kbsb-demodash-todos | ||
docker_repo = kbsb-demodash | ||
function_name = todos | ||
|
||
######## FASTAPI local development | ||
|
||
url_local = http://100.111.214.8:8000 | ||
url_docker = http://localhost:9000/2015-03-31/functions/function/invocations | ||
url_lambda = https://jchv4b5lpu5gea3lkowr5g2bei0tpnsl.lambda-url.eu-central-1.on.aws | ||
|
||
# app:app refers to app.py app function | ||
api: | ||
uvicorn --host 0.0.0.0 app:app --reload | ||
|
||
pytest-local: | ||
export TEST_URL="$(url_local)" && pytest -s -k test_endpoints | ||
# `pytest -s` includes stdout | ||
|
||
pytest-docker: | ||
export TEST_URL="$(url_docker)"; export TEST_DOCKER=1 && pytest -s -k test_endpoints | ||
|
||
pytest-prod: | ||
export TEST_URL="$(url_lambda)" && pytest -s -k test_endpoints | ||
|
||
######## AWS Authentication | ||
|
||
login: | ||
aws sso login | ||
|
||
auth: | ||
aws ecr get-login-password --region "$(region)" | docker login --username AWS --password-stdin "$(ecr)" | ||
|
||
######## DOCKER tasks | ||
|
||
build: | ||
docker build -t "$(image_name)" . | ||
|
||
run: | ||
docker run --env-file .env -e LOG_LEVEL=DEBUG -p 9000:8080 "$(image_name)" | ||
|
||
shell: | ||
docker run -it --entrypoint /bin/bash -p 9000:8080 "$(image_name)" | ||
|
||
tag: | ||
docker tag "$(image_name)" "$(ecr)"/"$(docker_repo)" | ||
|
||
push: | ||
docker push "$(ecr)"/"$(docker_repo)" | ||
|
||
lambda: | ||
aws lambda update-function-code \ | ||
--region "$(region)" \ | ||
--function-name "$(function_name)" \ | ||
--image-uri "$(ecr)"/"$(docker_repo)":latest | ||
|
||
invoke: | ||
aws lambda invoke --function-name "$(function_name)" output.json | ||
|
||
update: build tag push lambda | ||
|
||
logs: | ||
docker logs "$(image_name)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Readme | ||
|
||
Post todos to Airtable. | ||
|
||
Requirements: | ||
- Python v3.9 | ||
|
||
> 📌 Make sure to set the AWS_PROFILE environment variable if you want to use the Makefile Docker targets! | ||
```sh | ||
pip install pytest | ||
pip freeze > requirements.txt | ||
# install dependencies from requirements | ||
pip freeze -r requirements.txt | ||
|
||
# update requirements | ||
pip freeze | ||
# run pytest tests | ||
pytest | ||
``` | ||
|
||
```sh | ||
# setup Python environment | ||
python -m venv .venv | ||
source .venv/bin/activate | ||
pip install -r requirements.txt | ||
``` | ||
|
||
## FastAPI documentation page | ||
|
||
``` | ||
http://100.111.214.8:8000/docs | ||
https://jchv4b5lpu5gea3lkowr5g2bei0tpnsl.lambda-url.eu-central-1.on.aws/docs | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from fastapi import FastAPI | ||
from mangum import Mangum | ||
from routes import new_todo, list_todos | ||
from fastapi.middleware.cors import CORSMiddleware | ||
|
||
origins = ["*"] | ||
|
||
#! set a variable so that the production origin is only demodash.kbsb.app | ||
|
||
app = FastAPI() | ||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=origins, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
app.include_router(new_todo.router) | ||
app.include_router(list_todos.router) | ||
|
||
|
||
@app.get("/") | ||
def root(): | ||
return { | ||
"body": {"message": "Hello todo!"}, | ||
} | ||
|
||
|
||
handler = Mangum(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# send API Gateway payload to the Lambda function | ||
|
||
curl -XGET "http://localhost:9000/2015-03-31/functions/function/invocations" -d ' | ||
{ | ||
"version": "2.0", | ||
"requestContext": { | ||
"http": { | ||
"method": "GET", | ||
"path": "/", | ||
"protocol": "HTTP/1.1", | ||
"sourceIp": "192.0.2.1" | ||
} | ||
} | ||
} | ||
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# send API Gateway payload to the Lambda function | ||
|
||
# the Lambda emulator expects escaped JSON strings as body | ||
# this is not a problem when running locally with FastAPI | ||
# or when running in production | ||
|
||
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d ' | ||
{ | ||
"version": "2.0", | ||
"requestContext": { | ||
"http": { | ||
"method": "POST", | ||
"path": "/new_todo", | ||
"protocol": "HTTP/1.1", | ||
"sourceIp": "192.0.2.1" | ||
} | ||
}, | ||
"body": "{\"description\": \"Lorem ipsum\",\"label\": \"normal\",\"done\": true}" | ||
} | ||
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# production | ||
# @URL = https://jchv4b5lpu5gea3lkowr5g2bei0tpnsl.lambda-url.eu-central-1.on.aws | ||
|
||
# local dev server | ||
@URL = http://100.111.214.8:8000 | ||
|
||
# https://github.com/Huachao/vscode-restclient/blob/master/README.md#variables | ||
|
||
### endpoint: / | ||
|
||
GET {{URL}}/ HTTP/1.1. | ||
content-type: application/json | ||
|
||
{} | ||
|
||
### endpoint: /new_todo | ||
|
||
POST {{URL}}/new_todo HTTP/1.1. | ||
content-type: application/json | ||
|
||
{ | ||
"description": "Lorem ipsum", | ||
"label": "normal", | ||
"done": true | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
# load environment variables | ||
load_dotenv() | ||
|
||
test = "test222222" | ||
|
||
api_key = os.getenv("AIRTABLE_API_KEY") | ||
base_id = os.getenv("AIRTABLE_BASE_ID") | ||
table_name = os.getenv("AIRTABLE_TABLE_NAME") |
Oops, something went wrong.