Skip to content

Commit

Permalink
first commit!
Browse files Browse the repository at this point in the history
  • Loading branch information
PigeonsHouse committed Mar 13, 2022
0 parents commit 53b53f6
Show file tree
Hide file tree
Showing 14 changed files with 694 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_HOST=
POSTGRES_DB=giganoto
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode/
.env
*.pyc
25 changes: 25 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
fastapi = "*"
sqlalchemy = "*"
uvicorn = "*"
psycopg2 = "*"
python-multipart = "*"
requests = "*"
flake8 = "*"
bcrypt = "*"
pydantic = {extras = ["email"], version = "*"}
pytest = "*"
sqlalchemy-utils = "*"
python-dotenv = "*"
pyjwt = "*"
cerberus = "*"

[dev-packages]

[requires]
python_version = "3.9"
536 changes: 536 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

Empty file added README.md
Empty file.
20 changes: 20 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from routers.api import router
from db.main import engine
from db.models import Base

Base.metadata.create_all(bind=engine)
app = FastAPI(
title='ReaBar'
)

app.add_middleware(
CORSMiddleware,
allow_credentials=True,
allow_origins=['*'],
allow_methods=['*'],
allow_headers=['*'],
)

app.include_router(router)
Empty file added bot.py
Empty file.
23 changes: 23 additions & 0 deletions db/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session
from typing import Any
import os

DATABASE = 'postgresql'
USER = os.environ.get('POSTGRES_USER')
PASSWORD = os.environ.get('POSTGRES_PASSWORD')
HOST = os.environ.get('POSTGRES_HOST')
DB_NAME = os.environ.get('POSTGRES_DB')

DATABASE_URL = "{}://{}:{}@{}/{}".format(DATABASE, USER, PASSWORD, HOST, DB_NAME)

engine = create_engine(DATABASE_URL)

SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

def get_db() -> Session:
db = SessionLocal()
try:
yield db
finally:
db.close()
16 changes: 16 additions & 0 deletions db/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import datetime
from typing import Any
from sqlalchemy import Boolean, Column, DateTime, func
from sqlalchemy.ext.declarative import as_declarative
from sqlalchemy.sql.schema import ForeignKey
from sqlalchemy.sql.sqltypes import String, Integer
from sqlalchemy.orm import relationship
from uuid import uuid4

@as_declarative()
class Base:
id: Any
__name__: Any

def generate_uuid():
return str(uuid4())
51 changes: 51 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: '3'
services:
db:
container_name: giganoto-db
image: postgres:12
volumes:
- dbdata:/var/lib/postgresql/data/
env_file:
- .env

server:
container_name: giganoto-api
build:
context: .
dockerfile: dockerfile_fastapi
network: host
volumes:
- .:/opt
env_file:
- .env
ports:
- '7000:8000'
depends_on:
- db

bot:
container_name: giganoto-bot
build:
context: .
dockerfile: dockerfile_linebot
network: host
volumes:
- .:/opt
env_file:
- .env
ports:
- '7070:8000'
depends_on:
- db

adminer:
container_name: giganoto-adminer
image: adminer:4.7.5
restart: always
ports:
- 7080:8080
depends_on:
- db

volumes:
dbdata: null
13 changes: 13 additions & 0 deletions dockerfile_fastapi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.9.5-slim

RUN mkdir -p /opt
COPY . /opt/
WORKDIR /opt

RUN apt update
RUN apt install -y libpq-dev build-essential
RUN pip install pipenv
RUN pipenv install

ENTRYPOINT []
CMD pipenv run uvicorn api:app --host 0.0.0.0 --reload
Empty file added dockerfile_linebot
Empty file.
3 changes: 3 additions & 0 deletions routers/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from fastapi import APIRouter

router = APIRouter()
Empty file added routers/bot.py
Empty file.

0 comments on commit 53b53f6

Please sign in to comment.